最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - what does the "modules:auto" means in @babelpreset-env field? - Stack Overflow

programmeradmin4浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 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 "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`,
发布评论

评论列表(0)

  1. 暂无评论