【NodeJS】NodeJS、ES6、Babel初步

1、安装node-v8.10.0-x64.msi

2、npm init -y

3、npm install --save express

4、npm install --save-dev babel-cli babel-preset-es2015 rimraf

5、package.json

{
  "name": "vtk-js-new",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "rimraf dist/ && babel ./ --out-dir dist/ --ignore ./node_modules,./.babelrc,./package.json,./npm-debug.log --copy-files",
    "start": "npm run build && node dist/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.2"
  },
  "devDependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-es2015": "^6.24.1",
    "rimraf": "^2.6.2"
  }
}

6、.babelrc

{
"presets": ["es2015"]
}

7、index.js

import express from 'express';

const app = express()

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, function () {
  console.log('Example app listening on port 3000!')
})

8、文件夹结构

8、npm start

9、运行效果

 参考资料:http://www.cnblogs.com/weschen/p/7159307.html

posted @ 2018-03-09 13:15  咸鱼翻身  阅读(2038)  评论(0编辑  收藏  举报