Answer the question
In order to leave comments, you need to log in
Why is mustache.js throwing an error?
I'm trying to create an svg sprite using gulp.
Here is the content of gulpfile.js
let svgSprite = require('gulp-svg-sprite'),
svgmin = require('gulp-svgmin'),
gulp = require('gulp'),
cheerio = require('gulp-cheerio'),
replace = require('gulp-replace');
gulp.task('svgSpriteBuild', function(){
return gulp.src('assets/i/icons/*.svg')
// minify svg
.pipe(svgmin({
js2svg: {
pretty: true
}
}))
// remove all fill, style and stroke declarations in out shapes
.pipe(cheerio({
run: function($){
$('[fill]').removeAttr('fill');
$('[stroke]').removeAttr('stroke');
$('[style]').removeAttr('style');
},
parserOptions: {xmlMode: true}
}))
// cheerio plugin create unnecessary string '>', so replace it.
.pipe(replace('>', '>'))
// build svg sprite
.pipe(svgSprite({
mode: {
symbol: {
sprite: "../sprite.svg",
render: {
scss: {
dest: '../../../sass/_sprite.scss',
template: "assets/sass/templates/_sprite_template.scss"
}
}
}
}
}))
.pipe(gulp.dest('assets/i/sprite/'));
});
.icon {
display: inline-block;
width: 1em;
height: 1em;
fill: currentColor;
}
{{#shapes}}
.icon-{{base}} {
font-size:({{height.inner}}/10)*1rem;
width:({{width.inner}}/{{height.inner}})*1em;
}
Starting 'svgSpriteBuild'...
/var/www/test.loc/node_modules/mustache/mustache.js:226
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos);
^
Error: Unclosed section "shapes" at 207
at parseTemplate (/var/www/test.loc/node_modules/mustache/mustache.js:226:13)
at Writer.parse (/var/www/test.loc/node_modules/mustache/mustache.js:450:34)
at Writer.render (/var/www/test.loc/node_modules/mustache/mustache.js:465:23)
at Object.render (/var/www/test.loc/node_modules/mustache/mustache.js:603:26)
at /var/www/test.loc/node_modules/svg-sprite/lib/svg-sprite/mode/base.js:165:27
at /var/www/test.loc/node_modules/async/dist/async.js:3866:24
at replenish (/var/www/test.loc/node_modules/async/dist/async.js:998:17)
at /var/www/test.loc/node_modules/async/dist/async.js:1002:9
at _parallel (/var/www/test.loc/node_modules/async/dist/async.js:3865:5)
at Object.parallelLimit$1 [as parallelLimit] (/var/www/test.loc/node_modules/async/dist/async.js:3971:5)
Process finished with exit code 1
Answer the question
In order to leave comments, you need to log in
I think that the error occurs due to some invalid svg or scss template in which the tag does not close, check your svg files from which you are collecting the sprite.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question