Skip to content

Instantly share code, notes, and snippets.

@Macxim
Created March 27, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Macxim/4ba163df0f220db16b32 to your computer and use it in GitHub Desktop.
Save Macxim/4ba163df0f220db16b32 to your computer and use it in GitHub Desktop.
gulp task SVG symbols
// See https://github.com/Hiswe/gulp-svg-symbols/
var gulp = require('gulp');
var filter = require('gulp-filter');
var cssFilter = filter('**/*.css');
var svgFilter = filter('**/*.svg');
gulp.task('svgsymbol', function () {
return gulp.src('img/icons/**/*.svg')
.pipe( require('gulp-plumber')() )
.pipe( require('through2').obj(function ( file, enc, cb ) {
var fileString = file.contents.toString()
var titleRegex = /<title>.*<\/title>/gi
var descRegex = /<desc>.*<\/desc>/gi
var commentRegex = /<!--.*-->/gi
var defsRegex = /<defs>.*<\/defs>/gi
var mSShapeGroupRegex = / +sketch:type=\"MSShapeGroup\"/gi
var mSPageRegex = / +sketch:type=\"MSPage\"/gi
var mSLayerGroupRegex = / +sketch:type=\"MSLayerGroup\"/gi
var fillRegex = / +fill=\".*\"/gi
fileString = fileString.replace(titleRegex, '')
fileString = fileString.replace(descRegex, '')
fileString = fileString.replace(commentRegex, '')
fileString = fileString.replace(defsRegex, '')
fileString = fileString.replace(mSShapeGroupRegex, '')
fileString = fileString.replace(mSPageRegex, '')
fileString = fileString.replace(mSLayerGroupRegex, '')
fileString = fileString.replace(fillRegex, '')
file.contents = new Buffer( fileString )
this.push( file )
cb()
}) )
.pipe(
require('gulp-svg-symbols')({
id: 'icon-Svg--%f',
className: '.icon-Svg--%f',
fontSize: 32,
css: true
})
)
.pipe( cssFilter )
.pipe( require('gulp-rename')('svg-symbols.less') )
.pipe( gulp.dest('style/src/base/') )
.pipe( cssFilter.restore() )
.pipe( svgFilter )
.pipe( require('gulp-rename')('svg-symbols.xml') )
.pipe( gulp.dest('img/') )
});
gulp.task('default', ['svgsymbol']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment