使用babel将es6转为es5

js yekong 39℃

安装依赖

babel-preset-es2015和babel-cli

cnpm i --save-dev babel-preset-es2015 babel-cli

项目根目录创建.babelrc

{
  "presets": [
    "es2015"
  ],
  "plugins": []
}

执行命令

babel src/index.js -o dist/index.js

编译前代码

let a = 1;
console.log(a)

编译后代码

var a = 1;
console.log(a)

喜欢 (0)