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

Accept undefined and null in plugins array #3836

Closed
silverwind opened this issue Jun 5, 2023 · 3 comments · Fixed by webpack/webpack#17339
Closed

Accept undefined and null in plugins array #3836

silverwind opened this issue Jun 5, 2023 · 3 comments · Fixed by webpack/webpack#17339

Comments

@silverwind
Copy link

silverwind commented Jun 5, 2023

Is your feature request related to a problem? Please describe.

To conditionally add plugins, && syntax is useful and this works in vite as well:

export default {plugins: [condition && SomePlugin()]}

It errors because the schema is too strict:

[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
 - configuration.plugins[4] should be one of these:
   object { apply, … } | function
   -> Plugin of type object or instanceof Function.
   Details:
    * configuration.plugins[4] should be an object:
      object { apply, … }
      -> Plugin instance.
    * configuration.plugins[4] should be an instance of function.
      -> Function acting as plugin.

Describe the solution you'd like

Accept undefined and null values in plugins array, and just ignore them.

Describe alternatives you've considered

This works, but is clumsy:

export default {plugins: [condition && SomePlugin()].filter(Boolean)}
@alexander-akait
Copy link
Member

I think we need improve this on the webpack side, because you can pass options without webpack-cli, feel free to send a PR

@silverwind
Copy link
Author

I tried but then I gave up.

@hardfist
Copy link

hardfist commented Jun 8, 2023

webpack side seems more ideal,otherwise all webpack cli have to reimplement the same logic here

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

Successfully merging a pull request may close this issue.

3 participants