Created
October 13, 2017 21:03
-
-
Save rzzo/fff42ec765dfd22167d758502243e421 to your computer and use it in GitHub Desktop.
Gulp-svg-sprite config template to generate svg sprites
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'; | |
var gulp = require('gulp'), | |
svgSprite = require('gulp-svg-sprite'), | |
path = require('path'), | |
// SVG Config | |
config = { | |
shape : { | |
id : { | |
separator : '-', | |
whitespace : '-', | |
// svg name prefix + default (i.e. prefix-foldername-name.svg | |
// generator : "prefix-%s" | |
// or just use name.svg | |
generator: function (name) { | |
return path.basename(name, '.svg') | |
} | |
}, | |
dimension : { // Set maximum dimensions | |
maxWidth : 42, | |
maxHeight : 42 | |
}, | |
spacing : { // Add padding | |
padding : 0, | |
box : 'content' | |
}, | |
transform : [ | |
{svgo : { | |
plugins : [ | |
{cleanupIDs: false} | |
] | |
}} | |
], | |
dest : 'prefix' , // Keep the intermediate files | |
sort : 1 // Sort alphabetically | |
}, | |
mode : { | |
view : { // Activate the «view» mode | |
bust : false, | |
example : true, | |
sprite : 'svg/prefix-view.svg', | |
render : { | |
scss : { | |
example : false | |
} | |
} | |
}, | |
symbol : { | |
prefix : 'prefix-', | |
inline : false, | |
filename : 'prefix', | |
dest : 'sprite', | |
sprite : 'prefix.svg', | |
bust : false, | |
example : true, | |
svg : { | |
xmlDeclaration: false, // strip out the XML attribute | |
doctypeDeclaration: false // don't include the !DOCTYPE declaration | |
} | |
}, | |
} | |
}; | |
gulp.task('watch', function () { | |
gulp.watch('**/*.svg', {cwd: 'icons'}, ['svgSprite']) | |
}); | |
gulp.task("svgSprite", function () { | |
gulp.src('**/*.svg', {cwd: 'icons'}) | |
.pipe(svgSprite(config)) | |
.pipe(gulp.dest('dist')); | |
}); | |
gulp.task('default', ['svgSprite']); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment