nodejsサポートes 6&自動再起動

1624 ワード

インストールes 6依存パッケージ
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はあなたのエス6コードです.
実行
npm start
完全パッケージ.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"
  }
}