Created
March 27, 2015 14:09
-
-
Save Macxim/4ba163df0f220db16b32 to your computer and use it in GitHub Desktop.
gulp task SVG symbols
This file contains hidden or 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
// 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