-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulp-sprite.js
More file actions
42 lines (38 loc) · 1.24 KB
/
gulp-sprite.js
File metadata and controls
42 lines (38 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ------------------------
// Build SVG symbol sprites
// ------------------------
// Each directory matching assets/icons/sprite-* may contain individual SVG files,
// and will be turned into a SVG symbol spritesheet.
let gulp = require('gulp');
let path = require('path');
let glob = require('glob');
let svgSprite = require('gulp-svg-sprite');
gulp.task('build-svg', function() {
let svgDest = './public/images/sprites';
return glob('./resources/assets/icons/sprite-*', function(err, dirs) {
dirs.forEach(function(dir) {
console.log(dir);
gulp.src( path.join(dir, '*.svg') )
.pipe( svgSprite(makeSvgSpriteOptions(dir)) )
//.pipe( size({ showFiles: true, title: svgDest }) )
.pipe( gulp.dest(svgDest) )
})
});
/**
* Make a svg-sprite configuration object for a symbol sprite with a custom file name
*/
function makeSvgSpriteOptions(dirPath) {
return {
mode: {
symbol: {
dest: '.',
sprite: path.basename(dirPath).replace('sprite-', '') + '.svg'
}
},
shape: {
id: {separator: '-'},
transform: ['svgo']
}
};
}
});