Skip to content

Accept undefined and null in plugins array #3836

@silverwind

Description

@silverwind

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)}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions