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"}
]
],
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"}
]
],
Share
Improve this question
asked Apr 22, 2019 at 9:54
lastStrangerlastStranger
2051 gold badge3 silver badges10 bronze badges
2 Answers
Reset to default 8It 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"monjs"
otherwise.
So, if ES6 is supported (which seems to be your case) setting modules to auto its the same as setting false.
auto
means default value
and default value of modules
is false
. See - https://github./babel/babel/pull/8485/files#r236086742.
`Invalid Option: The 'modules' option must be one of \n` +
` - 'false' to indicate no module processing\n` +
` - a specific module type: 'monjs', 'amd', 'umd', 'systemjs'` +
` - 'auto' (default) which will automatically select 'false' if the current\n` +
` process is known to support ES module syntax, or "monjs" otherwise\n`,