Skip to content

Instantly share code, notes, and snippets.

@fogrew
Created November 20, 2016 13:00
Show Gist options
  • Save fogrew/d3eb2d326600b65d5b2db279e9daa74f to your computer and use it in GitHub Desktop.
Save fogrew/d3eb2d326600b65d5b2db279e9daa74f to your computer and use it in GitHub Desktop.
Gulp task for svg symbols sprite
'use strict';
const paths = require('../config/paths');
const fs = require('fs');
const path = require('path');
const svgSprite = require('gulp-svg-sprite');
module.exports = function(gulp, bs) {
return gulp.task('svg-symbols', function() {
fs.readdir(paths.dev.svg, function(err, files){
if(err) {
return console.error(err);
}
for (var i in files) {
var dirName = files[i],
dirPath = path.join(paths.dev.svg, dirName),
stats = fs.lstatSync(dirPath);
var svgSpriteConfig = {
shape: {
spacing: {
padding: 1
},
},
mode: {
symbol: {
dest: '.',
sprite: path.join(paths.dist.svg, dirName + '.symbol.svg'),
dimensions: false,
bust: false
}
}
};
if (stats.isDirectory()) {
gulp.src(dirPath + '/*.svg')
.pipe(svgSprite(svgSpriteConfig)
.on('error', function(error){
console.error(JSON.stringify(error));
})
)
.pipe(gulp.dest('.'))
.pipe(bs.stream());
}
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment