nodejs 支持 es6 & 自动重启

安装es6 依赖包

npm i --save-dev babel-cli 
npm i --save-dev babel-plugin-transform-async-generator-functions 
npm i --save-dev babel-plugin-transform-object-rest-spread 
npm i --save-dev babel-plugin-transform-runtime babel-preset-latest

编写 .babelrc

{
  "presets": ["latest"]
}

自动重启 依赖包

npm i --save-dev nodemon

编写 npm scripts

  "scripts": {
    "start": "nodemon ./src/server.js --exec babel-node -e js"
  },

./src/server.js 是你的 es6 代码

执行

npm start

完整 package.json 参考

{
  "name": "nodejs es6 run",
  "version": "0.1.0",
  "description": "",
  "main": "./src/server.js",
  "scripts": {
    "start": "nodemon ./src/server.js --exec babel-node -e js",
    "h" : "nodemon -h"
  },
  "author": "",
  "devDependencies": {
    "babel-cli": "^6.24.0",
    "babel-plugin-transform-async-generator-functions": "^6.24.1",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-latest": "^6.23.0",
    "nodemon": "^1.11.0"
  },
  "dependencies": {
    "body-parser": "^1.17.1",
    "express": "^4.15.2",
    "lodash": "^4.17.4"
  }
}

你可能感兴趣的:(nodejs 支持 es6 & 自动重启)