search

Home  >  Q&A  >  body text

node.js - babel编译es6 modules的插件是哪个?

node到v7后支持了async/await,
不想再让项目代码被babel编译的面目全非,
只想编译node还不支持的es6 modules(import export),
请问babel支持的是哪个插件,
或者可以如何设置让babel只编译这部分?


装了

    "babel-cli": "^6.18.0",
    "babel-plugin-transform-es2015-modules-commonjs": "^6.18.0"

.babelrc

{
    "plugins": [
        "transform-es2015-modules-commonjs"
    ]
}

但是--out-file后还是不能支持es6 modules

还有另一个问题就是node v7目前还是不支持 async/await

伊谢尔伦伊谢尔伦2866 days ago443

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 15:16:48

    Haha, just happened to see this article: https://segmentfault.com/a/11...

    1. Global installationbabel-cli, *inux, etc. remember to sudo

      npm i babel-cli -g
    2. Install the babel-plugin-transform-es2015-modules-commonjsplug-in in the project root directory

      npm i babel-plugin-transform-es2015-modules-commonjs --save-dev
    3. Write the .babelrc configuration file in the project root directory, with the content as follows.

      {
        "plugins": [
          "transform-es2015-modules-commonjs"
        ]
      }

      Test it.

    babel es2016.js -o es2016.transform.js

    reply
    0
  • 阿神

    阿神2017-04-17 15:16:48

    You can check out this https://github.com/babel/babe...

    reply
    0
  • Cancelreply