问题
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"}
]
],
回答1:
auto
means default value
and default value of modules
is false
. See - https://github.com/babel/babel/pull/8485/files#r236086742.
回答2:
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.
回答3:
it enable transformation of ES6 module syntax to another module type.
Reference : https://babeljs.io/docs/en/babel-preset-env#modules
来源:https://stackoverflow.com/questions/55792519/what-does-the-modulesauto-means-in-babel-preset-env-field