ben-eb / gulp-svgmin

Minify SVG files with gulp.
MIT License
341 stars 35 forks source link

Add user callback support #20

Closed TrySound closed 9 years ago

TrySound commented 9 years ago

Need to get svgjs data

ben-eb commented 9 years ago

Could you please elaborate? What's the use case?

TrySound commented 9 years ago

I use gulp-svgstore and want to add style="display: none" without cheerio.

ben-eb commented 9 years ago

SVG2JS seems like an internal API for SVGO; the AST is not returned with the optimised SVG. It might be worth extracting that conversion into a separate module which SVGO could consume, but in this case I think it might be better to have a gulp plugin that was about SVG AST manipulation (which would consume that hypothetical SVG2JS/JS2SVG extraction).

In most cases, people will not need the extra transformation that you would like here, and if they do, I think it is worth using a separate module to achieve it; it keeps this module small and focused. Plus, gulp-svgstore's README already has a one-line callback which I think should do the job:

var gulp = require('gulp');
var svgstore = require('gulp-svgstore');
var cheerio = require('gulp-cheerio');

gulp.task('svgstore', function () {
    return gulp
        .src('test/src/*.svg')
        .pipe(svgstore({ inlineSvg: true }))
        .pipe(cheerio(function ($) {
            $('svg').attr('style', 'display:none');
        }))
        .pipe(gulp.dest('test/dest'));
});

I'm not sold on adding this, it doesn't seem like you'll get any benefit over using cheerio (which is an excellent module), and it bloats the API for introducing a feature that will only be used in edge cases.