the babel docs say the modules default option is auto, what does the auto means? does it transform the "import" to "require" or not? what's the difference between "modules: false" and "modules: auto"? it seems they are the same result; I'm learning tree shaking, when I didn't set any options to my @babel/preset-env, tree shaking success, when I set "modules: false", the tree shaking also succeed;
"presets": [
[
"@babel/preset-react"
],
[
"@babel/preset-env",{"modules": "false"}
]
],
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.
A Babel preset that compiles ES2015+ down to ES5 by automatically determining the Babel plugins and polyfills you need based on your targeted browser or runtime environments. It uses browserslist to parse this information, so we can use any valid query format supported by browserslist .
babel-loader does what ts-loader does for TypeScript; passes off files to the Babel compiler, and returns the result to be used in the bundle in-place of the original source program.
It seems that the documentation for auto is described in this pull request. According to that PR:
The default
auto
will automatically selectfalse
if ES6 module syntax is already supported by the caller, or"commonjs"
otherwise.
So, if ES6 is supported (which seems to be your case) setting modules to auto its the same as setting false.
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