Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird options schema #43

Open
Tofandel opened this issue Mar 30, 2021 · 0 comments
Open

Weird options schema #43

Tofandel opened this issue Mar 30, 2021 · 0 comments

Comments

@Tofandel
Copy link

Tofandel commented Mar 30, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant