Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use loose modules when using es2015 preset in babel 6?

Tags:

babeljs

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

like image 233
zowers Avatar asked Oct 30 '15 23:10

zowers


People also ask

Does Babel preset order matter?

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.

What is the purpose of using '@ Babel preset react preset?

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.

What does Babel preset ENV include?

@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!

How do you use Babel preset?

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.


2 Answers

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.

like image 106
loganfsmyth Avatar answered Sep 26 '22 16:09

loganfsmyth


I ended up creating a preset es2015-mod for this same purpose - an exact copy of Babel's es2015 with loose modules enabled.

like image 34
Orlin M Bozhinov Avatar answered Sep 24 '22 16:09

Orlin M Bozhinov