gulp-svgmin

Minify SVG files with gulp.

gulp-svgmin

Minify SVG with SVGO.

If you have any difficulties with the output of this plugin, please use the SVGO tracker.

Install via npm:

npm install gulp-svgmin --save-dev
var gulp = require('gulp');
var svgmin = require('gulp-svgmin');
 
gulp.task('default', function() {
    return gulp.src('logo.svg')
        .pipe(svgmin())
        .pipe(gulp.dest('./out'));
});

Optionally, you can disable any SVGO plugins to customise the output. You will need to provide the config in comma separated objects, like the example below.

gulp.task('default', function() {
    return gulp.src('logo.svg')
        .pipe(svgmin({
            plugins: [{
                removeDoctype: false
            }, {
                removeComments: false
            }]
        }))
        .pipe(gulp.dest('./out'));
});

You can also use gulp-svgmin to optimise your SVG but render a pretty output, instead of the default where all extraneous whitespace is removed:

gulp.task('pretty', function() {
    return gulp.src('logo.svg')
        .pipe(svgmin({
            js2svg: {
                pretty: true
            }
        }))
        .pipe(gulp.dest('./out'))
});

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

MIT © Ben Briggs