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
It's a feature request.
Context
Sometimes you need to specify options for some plugins inside
preset-enve.g. when you want to enableloosemode only for some of them.The only way to do it right now is to include those plugins separately under the
pluginssection 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-envin loose mode but I can't enable loose mode fortransform-spreadbecause 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-envthat 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-envby itself e.g. in the case aboveloose: falsewill overrideloose: truefortransform-spreadplugin.Your Environment
babel: 7.0.0-beta.32
preset-env: 7.0.0-beta.32