SVGO v3 Override Defaults

417 Views Asked by At

I have Node running on my machine v NVM and installed SVGO. The script runs and processes my files using the defaults.

However, I am trying to active the removeXMLNS plugin and cannot get the latest CLI script to pick up my customisation file.

I have created the js file below using the example from the github readme, however, it has no effect.

I also tried running the --config parameter and linked to my file, which is located at

~/Scrips/svg/svgo-optimise.js

I've found a lot of older articles but nothing on the latest version. I am hoping someone may have run into a similar issue.

module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // customize default plugin options
          inlineStyles: {
            onlyMatchedOnce: false,
          },
          removeXLMNS: true,

          // or disable plugins
          removeDoctype: false,
        },
      },
    },
  ],
}; 

Thanks in advance

1

There are 1 best solutions below

0
On

You were correct.

However, after I made that change the script gave me a helpful error message and I solved the problem.

The additional plugins should have been added after the "extension" as I was adding them.

module.exports = {
  plugins: [
    {
      name: 'preset-default',
      params: {
        overrides: {
          // customize default plugin options
          inlineStyles: {
            onlyMatchedOnce: false,
          },

          // or disable plugins
          removeDoctype: false,
        },
      },
    },
// additional plugins here
    'removeXMLNS',
    {
      name: "addClassesToSVGElement",
      params: {
        className: "mySvg"
      }
    }
  ],
};