Created
November 20, 2016 13:00
-
-
Save fogrew/d3eb2d326600b65d5b2db279e9daa74f to your computer and use it in GitHub Desktop.
Gulp task for svg symbols sprite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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