cascornelissen / svg-spritemap-webpack-plugin

SVG spritemap plugin for webpack
MIT License
207 stars 49 forks source link

Cannot disable individual SVGO plugins. #184

Closed jgerigmeyer closed 2 years ago

jgerigmeyer commented 2 years ago

Description

It seems impossible to use SVGO, but disable individual default plugins. The following config comes close:

      output: {
        svgo: {
          plugins: [
            { name: 'removeHiddenElems', active: false },
          ],
        },
      },

That results in removeHiddenElems: false being correctly added to the preset-default params.overrides object, but it also appends { name: 'removeHiddenElems', active: false } to the list of SVGO plugins, and it appears the plugin is not actually disabled.

Expected behavior

If the output.svgo option is an object, I would expect it to completely override the default SVGO settings, removing preset-default entirely.

Actual behavior

generate-svgo-config.js both merges passed in options into the default preset-default plugin settings, and appends them to the list of SVGO plugins. This seems unexpected, and doesn't really allow customization of SVGO plugins (only true or false).

Additional context

Am I missing something obvious? I could create a quick reproducible case (or failing test) to demonstrate, if that'd be useful.

cascornelissen commented 2 years ago

For context: the fact that it's added to both the overrides for preset-default and the entire list of SVGO plugins is that the plugin doesn't (can't) know what plugins are enabled internally in preset-default as that information is not exposed by SVGO.

I'm also not sure the expected behavior you're suggesting makes sense to most people but that's an opinion that differs from person to person. The most important thing is that we can't really change it without introducing a breaking change which I'd like to avoid.

What I'm confused about is why the plugin would not be disabled... If you set active to false for the removeHiddenElems plugin it should end up twice in the output of generate-svgo-config.js but with active set to false for both instances so there's no way the plugin should be enabled...

Could you either do a bit of debugging yourself (you can change the code in node_modules/svg-spritemap-webpack-plugin/lib/helpers/generate-svgo-config.js for some simple tests) ) or supply a reproduction repository that I can use to do this debugging myself?

jgerigmeyer commented 2 years ago

@cascornelissen You're totally right -- I must have been testing incorrectly. I added a test in #185 to ensure that this is working properly.

cascornelissen commented 2 years ago

Thanks for adding a test, that's probably the first time I'm getting a PR with just test scenario's added 😅 Also nice to hear that things are working properly already.