简体   繁体   English

如何使用 babel 插件将 commonjs 转换为 es2015 模块?

[英]How can I transform commonjs to es2015 module with babel plugin?

I use the webpack2 to build my web and I want to benefit from tree-shaking, which only works with es2015 modules.我使用 webpack2 来构建我的网络,我想从 tree-shaking 中受益,它仅适用于 es2015 模块。

So I want to ask for commonjs to es2015 transformer of babel plugin like this rollup plugin https://github.com/rollup/rollup-plugin-commonjs .所以我想要求commonjs到es2015的babel插件转换器,比如这个汇总插件https://github.com/rollup/rollup-plugin-commonjs

One such plug-in is babel-plugin-transform-commonjs-es2015-modules.一个这样的插件是 babel-plugin-transform-commonjs-es2015-modules。 It can be installed by running:它可以通过运行安装:

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

Then add 'plugins':['transform-commonjs-es2015-modules'] to your babel configuration.然后将'plugins':['transform-commonjs-es2015-modules']到您的 babel 配置中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM