MMF-FE / svgicon

SVG icon components and tool set
https://mmf-fe.github.io/svgicon
MIT License
922 stars 95 forks source link

Issue with svgoConfig for overriding svgo default config #167

Closed adrienWeiss closed 2 years ago

adrienWeiss commented 3 years ago

Hello,

I'm trying to add & modify plugins using the svgoConfig in .vue-svgicon.config.js (in vue-cli-plugin-svgicon), and after a while I think I've figure out why it does not work as expected :

{
  svgoConfig: {
    plugins: [ { myPlugin1: true }, { myPlugin2: true}]
  }
}

But svgoConfig is merged with svgo defaultConfig using lodash _.merge, which recursively merges arrays see example here https://lodash.com/docs/4.17.15#merge

https://github.com/MMF-FE/svgicon/blob/8781ec0a68cf60f89b8d8efeb4e40757f2b1de17/packages/svgicon-gen/src/index.ts#L43

So we endup with a real config that has an incorrect shape

plugins: [
  { removeAttrs: {},  myPlugin1: true },
  { removeTitle: true, myPlugin2: true },
  { inlineStyles: { onlyMatchedOnce: false } },
  { minifyStyles: true },
  ...
]

I'm not sure what would the best approach be here, but it looks like svgo v2 has the util extendDefaultPlugins for this use case.

Allenice commented 2 years ago

svgo updated, from ^1.3.2 to ^2.8.0, please update @yzfe/svgicon-loader@1.2.0, see change log. Override svgo config: https://github.com/svg/svgo#default-preset