Node.js with babel
Node.js with babel
让 Node.js
使用 ES6
的所有特性, 使用 babel 作为编译器, 以下是配置方式
- 安装
babel
相关的包
yarn add @babel/cli @babel/core @babel/preset-env -D
- 在项目根目录创建
.babelrc
文件并填入如下内容
{
"presets": ["@babel/preset-env"]
}
- 在
package.json
加入如下内容
"scripts": {
"build": "babel src/index.js -d dist",
"start": "npm run build && nodemon dist/index.js"
}