【问题标题】:How can I transform commonjs to es2015 module with babel plugin?如何使用 babel 插件将 commonjs 转换为 es2015 模块?
【发布时间】:2017-01-13 08:48:57
【问题描述】:

我使用 webpack2 来构建我的网络,我想从 tree-shaking 中受益,它只适用于 es2015 模块。

所以我想问一下commonjs到es2015的babel插件的transformer,比如这个rollup插件https://github.com/rollup/rollup-plugin-commonjs

【问题讨论】:

  • 仅供参考,OP 在这里要求插件或转换 - 实际上并不是要求整个库,所以我不认为这是题外话。就像问“我如何转换......”并得到一个 babel 插件作为答案。
  • @CodingIntrigue 感谢您的建议

标签: javascript ecmascript-6 babeljs commonjs rollupjs


【解决方案1】:

babel-plugin-transform-commonjs-es2015-modules 就是一个这样的插件。 可以通过运行安装:

npm install babel-plugin-transform-commonjs-es2015-modules

然后将'plugins':['transform-commonjs-es2015-modules'] 添加到您的 babel 配置中。

【讨论】:

    猜你喜欢
    • 2017-06-21
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2022-07-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 2019-05-31
    相关资源
    最近更新 更多