javascriptwebpackbabeljsbabel-preset-env

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


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"}
    ]
  ],

Solution

  • 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`,