node.js - babel编译es6 modules的插件是哪个?
伊谢尔伦
伊谢尔伦 2017-04-17 15:14:48
0
2
440

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

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
洪涛

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
阿神

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template