Skip to content

Allow to specify options for separate plugins in preset-env #6978

@th0r

Description

@th0r

It's a feature request.

Context

Sometimes you need to specify options for some plugins inside preset-env e.g. when you want to enable loose mode only for some of them.
The only way to do it right now is to include those plugins separately under the plugins section of babel config, but in this case they will be used even for the targets that don't actually need them.

Here is the concrete example:

I want to use preset-env in loose mode but I can't enable loose mode for transform-spread because in this case it doesn't transform code like this [...someMap.value()] properly.

So the only solution right now is to use config like that:

{
  "presets": [
    ["@babel/preset-env", {"loose": true}]
  ],

  "plugins": [
    ["@babel/plugin-transform-spread", {"loose": false}]
  ]
}

But in this case spread operator will be transformed even if target browser supports this syntax natively.

Possible Solution

Introduce an option for preset-env that will contain options for separate plugins:

{
  "presets": [
    ["@babel/preset-env", {
      "loose": true,
      "pluginOptions": {
        "@babel/plugin-transform-spread": {"loose": false}
      }
    }]
  ]
}

They will override any options provided by preset-env by itself e.g. in the case above loose: false will override loose: true for transform-spread plugin.

Your Environment

babel: 7.0.0-beta.32
preset-env: 7.0.0-beta.32

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: discussionoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issuepkg: preset-env

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions