【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