node支持import语法
- 安装插件
npm i babel-cli babel-preset-env -D
- 添加配置文件 .babelrc
{
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
]
}
- package.json文件添加配置
"scripts": {
"dev":"nodemon -w src --exec \"babel-node src --presets env\"", // 监测src文件夹下的
"test": "echo \"Error: no test specified\" && exit"
},
node@8.x 新增的工具模块
import {promisify} from 'util' // promisify 序列化一个promise
生产环境支持ES6/7
- 安装依赖
npm i -S babel-plugin-transform-runtime babel-runtime -D
- 修改配置
{
"presets": [
[
"env",
{
"targets": {
"node": "current"
}
}
]
],
"plugins": [
[
"transform-runtime",
{
"polyfill": false,
"regeneratoe": true
}
]
]
}
- package.json文件添加配置
"scripts": {
"dev": "nodemon -w src --exec \"babel-node src --presets env\"",
"build": "rimraf dist && babel src -s -D -d dist --presets env",
"production": "nodemon dist",
"test": "echo \"Error: no test specified\" && exit"
},
koa 核心概念
网友评论