ben-eb / gulp-svgmin

Minify SVG files with gulp.
MIT License
340 stars 34 forks source link

How do you use plugins? #25

Closed Jakobud closed 9 years ago

Jakobud commented 9 years ago

For example I want to change the floatPrecision using the cleanupNumericValues plugin. I tried this:

.pipe(svgmin({
    cleanupNumericValues: {
        floatPrecision: 1
        }
}))

Didn't seem to work... What am I missing here? Do I need to load the plugin itself somehow?

ben-eb commented 9 years ago

Ensure that you are using the latest version, then:

gulp.task('default', function () {
    return gulp.src('logo.svg')
        .pipe(svgmin({
            plugins: [{
                cleanupNumericValues: {
                    floatPrecision: 1
                }
            }]
        }))
        .pipe(gulp.dest('./out'));
});
Jakobud commented 9 years ago

Thanks. You should put that in the readme.

On a side note, are all plugins loaded by default? Is that how SVGO works?

ben-eb commented 9 years ago

I did. It's under 'plugins'. :smiley:

Not all plugins are loaded by default, e.g transformsWithOnePath. https://github.com/svg/svgo/blob/master/plugins/transformsWithOnePath.js

You can tell which plugins are enabled by default by observing the exports.active flag for each plugin. I can't remember if there is a page that tells you which are on by default, but I know that the more experimental transforms are off.

Jakobud commented 9 years ago

Ah okay I see now. That looked like only instructions on how to disable plugins. I didn't realize I could use the same syntax to pass options to plugins.

ben-eb commented 9 years ago

I'll look at revisiting the language for that section. :smile: