what does the "modules:auto" means in @babel/preset-env field?
Asked Answered
C

2

10

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"}
    ]
  ],
Christmastide answered 22/4, 2019 at 9:54 Comment(0)
H
3

auto means default value and default value of modules is false. See - https://github.com/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: 'commonjs', 'amd', 'umd', 'systemjs'` +
  ` - 'auto' (default) which will automatically select 'false' if the current\n` +
  `   process is known to support ES module syntax, or "commonjs" otherwise\n`,
Hyperactive answered 22/4, 2019 at 10:7 Comment(0)
M
8

It seems that the documentation for auto is described in this pull request. According to that PR:

The default auto will automatically select false 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.

Midshipman answered 22/4, 2019 at 10:3 Comment(0)
H
3

auto means default value and default value of modules is false. See - https://github.com/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: 'commonjs', 'amd', 'umd', 'systemjs'` +
  ` - 'auto' (default) which will automatically select 'false' if the current\n` +
  `   process is known to support ES module syntax, or "commonjs" otherwise\n`,
Hyperactive answered 22/4, 2019 at 10:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.