The use of babel-cli in the project

  1. Project initialization
npm init
  1. Install babel in the project
npm install babel-cli --save-dev
  1. Install related babel plugins
# babel-preset-xxxxxx
npm install babel-preset-es2015 --save-dev
  1. Rewrite package.json
# src:源目录;lib:目标目录
{
  "devDependencies": {
    "babel-cli": "^6.0.0"
  },
  "scripts": {
    "build": "babel src -d lib"
  },
}
  1. The configuration file in the root directory. babelrc
# presets:转码规则,plugins:插件
{
    "presets": [],
    "plugins": []
}
  1. transcoding

The src transcoded file is under lib

npm run build

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324548114&siteId=291194637