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

时光毁灭记忆、已成空白 提交于 2019-12-02 04:30:28

问题


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 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.




回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!