【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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM