babel7搭建node es6环境

1. 安装依赖

1
npm i --save-dev @babel/core @babel/register @babel/plugin-proposal-class-properties @babel/plugin-transform-async-to-generator @babel/plugin-transform-modules-commonjs

2. 配置.babelrc文件

1
2
3
4
5
6
7
{
"plugins": [
"@babel/plugin-transform-async-to-generator",
"@babel/plugin-transform-modules-commonjs",
"@babel/plugin-proposal-class-properties"
]
}

3. 写入口文件index.js

1
2
require('@babel/register');
require('./app') // 要运行的文件

4. 启动

1
node index.js
附git demo地址

https://github.com/seawind8888/node-babel7-es6