How to activate/deactivate plugins for svgo

2.9k views Asked by At

I have installed svgo like so:

[sudo] npm install -g svgo

Downloaded the default config from repo:

https://github.com/svg/svgo/blob/master/.svgo.yml

Edited the config like so: ... - minifyStyles - convertStyleToAttrs - cleanupIDs: false - removeRasterImages - removeUselessDefs ...

Replaced the default like so:

svgo --config=custom.yml

As described here:

https://github.com/svg/svgo#cli

I run SVGO like so:

svgo test.svg test.min.svg

...but the plugin I've deactivated (cleanupIDs) is still active.

I've tried to deactivate other plugins too (i.e. removeTitle) but there is no effect on my output file.

Appreciate some guidance!

3

There are 3 answers

0
VeRo On

You can specify the plugin you want enabled or disabled by name, directly in your command line interface:

svgo --enable={cleanupIDs} test.svg -o test.min.svg

This will ensure that the named plugin(s) will be enabled if they are disabled by default, see help screen:

svgo -h

will produce this help screen: https://github.com/svg/svgo#cli where you can find this piece of information:

--disable=PLUGIN : Disable plugin by name,
--enable=PLUGIN : Enable plugin by name, 
svgo --show-plugins

will actually show which plugins are available and which are disabled by default.

0
Сергей Кобец On

Maybe you need to specify a parameter at the beginning of the custom.yml full: true

0
Seth Falco On

You can read the Configuration section of the SVGO README for how to configure plugins today.

Since v2.0.0, there are two supported ways to configure this:

  • Create a file called svgo.config.js in current working directory.
  • Create a file somewhere, and pass the path to the --config command-line argument.

A minimal configuration looks like:

svgo.config.js

module.exports = {
  plugins: [
    'preset-default',
    'reusePaths'
  ]
};

To use it from the same directory as the config:

svgo {{path/to/vector.svg}}

To use it from a different directory from the config:

svgo --config {{path/to/svgo.config.js}} {{path/to/vector.svg}}

To enable a plugin that is not in the default preset, include it in the plugin array like the example above.

To disable a plugin from the default preset, pass the override parameter, and set the plugin to false like the following:

svgo.config.js

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

Reference: SVGO documentation for how to disable a default plugin

SVGO v1.x.x

In versions before v2.0.0, plugins were toggled through command-line arguments or a YAML file rather than the SVGO config file.

See VeRo's answer for how to configure SVGO pre-v2.