如何配置 Babel 只输出 es2017/modern 代码?

How to configure Babel to only output es2017/modern code?

我正在尝试使用 optimize-plugin and babel to create module/nomodule bundles. In fact, I son't mind too much the nomodule thing, but I'd like to be sure to correctly configure babel to output es2017 code. In several tuts, for example this one 配置网络,我发现了一个像 'es2017' 这样的预设,但是从 babel 文档看来它不再受支持。相反,我应该使用 '@babel/preset-env' 和浏览器列表配置。我不太清楚应该如何编写浏览器列表。现在,我会这样说:

module.exports = { 
  presets : [ '@babel/preset-env' ],
  
  targets : {
    browsers: "last 2 versions, not dead, not IE 11",
    esmodules: true
  }
};

但不太确定.. 谁能告诉我最完美的? :)

我刚刚通过阅读 this code that comes from here 找到了答案。很简单:

'last 2 Chrome versions',
'last 2 Safari versions',
'last 2 iOS versions',
'last 2 Edge versions',
'Firefox ESR',

并且由于这个问题而没有使用 esmodules 目标,正如上面链接代码的评论中所报告的:

https://github.com/babel/babel/issues/8809

即使可能使用 babel 8 我们也可以使用它:

https://github.com/babel/babel/pull/12189