Вот рабочий таск
svgSprite = require('gulp-svg-sprite');
svgmin = require('gulp-svgmin'),
cheerio = require('gulp-cheerio'),
gulp.task('svg', function () {
return gulp.src('app/img/svg/*.svg') // svg files for sprite
// minify svg
.pipe(svgmin({
js2svg: {
pretty: true
}
}))
// remove all fill and style declarations in out shapes
.pipe(cheerio({
run: function ($) {
$('[fill]').removeAttr('fill');
$('[style]').removeAttr('style');
},
parserOptions: { xmlMode: true }
}))
// cheerio plugin create unnecessary string '>', so replace it.
.pipe(replace('>', '>'))
// build svg sprite
.pipe(svgSprite({
mode: {
stack: {
sprite: "../sprite.svg" //sprite file name
}
},
}
))
.pipe(gulp.dest('app/img/sprite/'));
});