Last active
August 29, 2015 14:27
-
-
Save frank-who/3e3e367e6fe7d6c4e910 to your computer and use it in GitHub Desktop.
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
// npm install gulp gulp-cheerio gulp-rename gulp-svgmin gulp-svgstore gulp-watch --save-dev | |
// gulp watch | |
var paths = { | |
icons: './app/assets/images/sprites/*.svg', | |
dest: './app/assets/images/' | |
}; | |
var gulp = require('gulp'), | |
path = require('path'), | |
cheerio = require('gulp-cheerio'), | |
rename = require('gulp-rename'), | |
svgmin = require('gulp-svgmin'), | |
svgstore = require('gulp-svgstore'), | |
watch = require('gulp-watch'); | |
gulp.task('sprites', function () { | |
return gulp.src(paths.icons) | |
.pipe(svgmin({ | |
js2svg: { pretty: true }, | |
plugins: [{ cleanupIDs: false }] | |
})) | |
.pipe(rename({ prefix: 'sprite--' })) | |
.pipe(svgstore({ inlineSvg: true })) | |
.pipe(cheerio({ | |
run: function ($, file) { | |
$('svg').attr('style', 'display:none'); | |
// $('[fill]').removeAttr('fill'); | |
}, | |
parserOptions: { xmlMode: true } | |
})) | |
.pipe(rename('sprites.svg')) | |
.pipe(gulp.dest(paths.dest)); | |
}); | |
gulp.task('watch', function() { | |
gulp.watch(paths.icons, ['sprites']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment