Klathmon / imagemin-webpack-plugin

Plugin to compress images with imagemin
MIT License
685 stars 53 forks source link

passing options to `imagemin-svgo` being ignored #93

Open nr1q opened 5 years ago

nr1q commented 5 years ago

I'm having a weird issue passing options to imagemin-svgo, if done via the svgo object, seems like they are ignored, and produces a zero size SVG file; but it works if I disable the plugin by setting the object to null and including it again through plugins attribute as follows:

new ImageminPlugin({
  test: /\.(jpe?g|png|gif|svg)$/i,
  disable: isdev,
  optipng: { optimizationLevel: 7 },
  gifsicle: { optimizationLevel: 3 },
  pngquant: { quality: '65-90', speed: 4 },
  svgo: null, // options not working from here
  plugins: [
    require('imagemin-svgo')({
      plugins: [
        {cleanupIDs: false},
        {removeHiddenElems: false},
        {removeUnknownsAndDefaults: false},
      ]
    })
  ]
})
Klathmon commented 5 years ago

Which version of the plugin are you using?

Another user just made an issue with something similar in #95.

nr1q commented 5 years ago

I've tested from 2.1.5 to 2.4.2 and even beta release, but is the same: other image formats are being emitted (minified/optimized) but SVG is a zero size image file.

As additional info, here is the SVG I'm testing with:

<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="position:absolute" visibility="hidden" width="100%" height="100%">
  <defs>
    <!-- Symbols goes here -->
  </defs>
</svg>

Looks like some of the passed options are ignored or something weird is happening because:

BUT, by removing the visibility attribute:

...I need the svg to be visibility=hidden though.

Thanks! and I hope everything goes ok about the hurricane, be safe.