es6转码和package.json中的配置
2021-04-25 05:26
标签:desc 安装 author enc build boot progress some app 需要 项目中main.js配置: 前提是安装对应的包 自己写的要运行的为app.js,这样配置后会在运行main.js是自动转为es5并执行 需要 安装babel后 运行 package.json: 对配置的解释 运行 es6转码和package.json中的配置 标签:desc 安装 author enc build boot progress some app 原文地址:https://www.cnblogs.com/ygjzs/p/12230841.html在线实时转换
babel-register
.babelrc中:{
"presets": [
"es2015"
]
}
require('babel-register')
require('./src/app')
通过配置手动转换
babel-cli
babel src -d dist
src为自己写的es6目录文件,dist为转码后的es5文件,没有则创建
运行node dist/app.js
这样就可以以es5来运行自己的项目了关于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
上一篇:【网页浏览】怀旧xp画图网页版
下一篇:PHP Array
文章标题:es6转码和package.json中的配置
文章链接:http://soscw.com/index.php/essay/79261.html