Skip to content

Instantly share code, notes, and snippets.

@massimo-cassandro
Last active July 12, 2020 14:02
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Gulpfile for SVG symbols building #gulp #svg
var gulp = require('gulp')
//,replace = require('gulp-replace')
,rename = require('gulp-rename')
,svgstore = require('gulp-svgstore')
,svgmin = require('gulp-svgmin')
;
gulp.task('default', function() {
gulp.src(['svg_files/*.svg'])
.pipe(rename(function (path) {
path.basename = path.basename.replace(/icon_prefix_/, '');
return path;
}))
.pipe(svgmin(function (file) {
return {
// https://github.com/svg/svgo/tree/master/plugins
plugins: [
{ cleanupIDs: { remove: true, minify: true } }
, { removeDoctype: true }
, { removeComments: true }
, { removeStyleElement: true }
, { removeDimensions: true }
, { cleanupNumericValues: { floatPrecision: 2 } }
, { convertColors: { names2hex: true, rgb2hex: true } }
, { removeAttrs: { attrs: ['(fill|stroke|class|style)', 'svg:(width|height)'] } }
]
//,js2svg: { pretty: true }
};
}))
.pipe(svgstore())
//.pipe( replace(/<style>(.*?)<\/style>/g, '') )
.pipe( rename('my-icons.svg') )
.pipe(gulp.dest('./'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment