ben-eb/gulp-svgmin

How do you use plugins?

Jakobud opened this issue · 5 comments

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?

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'));
});

Thanks. You should put that in the readme.

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

I did. It's under 'plugins'. 😃

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.

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.

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