使用babel7 进行转码
需要提前安装的东西:
- npx 方便执行命令
{
"name": "TestBabel7",
"version": "1.0.0",
"dependencies": {
"@babel/polyfill": "^7.6.0"
},
"devDependencies": {
"@babel/cli": "^7.6.4",
"@babel/core": "^7.6.4",
"@babel/plugin-proposal-decorators": "^7.6.0",
"@babel/preset-env": "^7.6.3"
}
}
babel.config.js 配置
const presets = [
[
"@babel/env",
],
];
const plugins = [
["@babel/plugin-proposal-decorators", { "legacy": true }], // 装饰器
];
module.exports = { presets,plugins};
转换的命令
如: 将 js 目录下的文件 转换后 存放到 src目录下
npx babel js -d src