imagemin-webp-webpack-plugin icon indicating copy to clipboard operation
imagemin-webp-webpack-plugin copied to clipboard

Weird options schema

Open Tofandel opened this issue 4 years ago • 0 comments

The way to setup options is very weird and prone to errors

new ImageminWebpWebpackPlugin({ config: [{ test: /\.(jpe?g|png)/, options: {quality: 80} }], overrideExtension: false })

Messing up the config array, forgetting a test or anything small would result in a cryptic error message

imagemin-webp-webpack-plugin/plugin.js:40
                  if (this.config[i].test.test(name)) {
                                          ^

TypeError: Cannot read property 'test' of undefined

I'd recommend switching to import { validate } from 'schema-utils' and to redesign the option schema

Something where both

new ImageminWebpWebpackPlugin({ quality: 80, overrideExtension: false})

and

new ImageminWebpWebpackPlugin( { silent: true, overrideExtension: false }, [ { test: /\.(png)/, quality: 80  }, { test: /\.(jpe?g)/, quality: 60, overrideExtension: true }] )

Would work

As well as adding an outputName modifier to let the user handle a case where both file file.jpg and file.png exist that would result in the .webp file generated over an existing one

Tofandel avatar Mar 30 '21 00:03 Tofandel