es6转码和package.json中的配置
在线实时转换
需要babel-register
.babelrc中:
{ "presets": [ "es2015" ] }
项目中main.js配置:
前提是安装对应的包
require('babel-register') require('./src/app')
自己写的要运行的为app.js,这样配置后会在运行main.js是自动转为es5并执行
通过配置手动转换
需要babel-cli
安装babel后
运行babel src -d dist
src为自己写的es6目录文件,dist为转码后的es5文件,没有则创建
运行node dist/app.js
这样就可以以es5来运行自己的项目了
关于package.json中的配置
package.json:
{ "name": "edu", "version": "1.0.0", "description": "", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "dev": "node main.js", "build": "babel src -d dist", "prestart": "npm run build", "start": "node dist/app.js" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { "bootstrap": "^3.3.7", "echarts": "^3.4.0", "ejs": "^2.5.5", "express": "^4.14.1", "font-awesome": "^4.7.0", "jquery": "^3.1.1", "nprogress": "^0.2.0" }, "devDependencies": { "babel-cli": "^6.22.2", "babel-preset-es2015": "^6.22.0", "babel-register": "^6.22.0" } }
dependencies
为项目依赖文件,上线必须要安装的
devDependencies
为开发阶段使用的工具,只在开发阶段使用
对配置的解释
"dev": "node main.js",
运行node run dev
=node main.js
"build": "babel src -d dist",
运行npm run build
=babel src -d dist
"prestart": "npm run build", "start": "node dist/app.js"
运行npm start
或npm run start
=npm run build
+node dist/app.js
相关推荐
PANH 2019-10-28
zhongweinan 2019-09-08
Fairfeng 2019-09-08
lbn0 2019-09-08
86530296 2020-11-10
hilary0 2020-02-21
83096129 2020-01-08
fangjack 2020-01-01
Justypc 2013-03-29
shyoushine 2019-11-10
cherayliu 2019-11-04
Wmeng0 2018-08-17
CWeeYii 2008-09-17
王之白石 2014-10-26
欧阳凯少 2015-08-26
gaedmihx 2019-04-17
ningningmingming 2016-08-16
创业轨迹 2017-09-18