Skip to content

Latest commit

 

History

History
34 lines (28 loc) · 803 Bytes

install-svgo-with-reasonable-defaults.md

File metadata and controls

34 lines (28 loc) · 803 Bytes

Install SVGO With Reasonable Defaults

A project I'm working on uses SVGO to clean and minify SVG files. There's one problem: SVGO by default removes the viewBox attribute, which comes embedded in the SVG's I receive and have stylistic meaning in my codebase.

You can override this default by using an SVGO config file:

// svgo.config.js
module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          removeViewBox: false,
        },
      },
    },
  ],
};

Applied like so:

svgo --config svgo.config.js input.svg --output output.svg

This reduces my SVG's file size by about ~25%, without changing its presentation. There's an issue on the SVGO repo where this default is discussed at length.