I tried to use following babelrcs:
{
"presets": [
["es2015", { "transform-es2015-modules-commonjs": { "loose": true } }]
]
}
fails with "Invalid options type for foreign"
{
"presets": ["es2015"],
"plugins": [
["transform-es2015-modules-commonjs", { "loose": true }]
]
}
ignores the "loose" option
{
"plugins": [
["transform-es2015-modules-commonjs", { "loose": true }]
]
}
does not use the preset
Ordering matters for each visitor in the plugin. This means if two transforms both visit the "Program" node, the transforms will run in either plugin or preset order. Plugins run before Presets. Plugin ordering is first to last.
In Babel, a preset is a set of plugins used to support particular language features. The two presets Babel uses by default: es2015 : Adds support for ES2015 (or ES6) JavaScript. react : Adds support for JSX.
@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!
Using a Preset Within a Babel config, if the preset is on npm, you can pass in the name of the preset and Babel will check that it's installed in node_modules already. This is added to the presets config option, which takes an array. Otherwise, you can also specify a relative or absolute path to your presets.
By enabling es2015
, you are asking for non-loose-mode modules. If you want loose module modes in Babel v6 (at least at the moment), you would need to explicitly list the plugins you wish to use by listing everything that is part of es2015
.
I ended up creating a preset es2015-mod for this same purpose - an exact copy of Babel's es2015
with loose modules enabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With