1. 程式人生 > >轉碼器babel

轉碼器babel

blog 6.0 post port rip babel package dev set

一、配置文件.babelrc,存放在項目的根目錄下

1)配置文件.babelrc
{ “presets
": [ //presets字段設置轉碼規則     "es2015" ], "plugins": [] }

ES2015轉碼規則
npm install --save-dev babel-preset-es2015

2)命令行轉碼babel-cli安裝在項目中
  npm install --save-dev babel-cli
  改寫package.json
    {
      "devDependencies":{
        "babel-cli": "^6.0.0"
      },
      "scrippts": {
        "build": "babel src -d lib"
      }
    }
    轉碼的時候執行 npm run build 命令

3)babel-poolyfill插件
npm install --save-dev babel-polyfill
import "babel-polyfill"

webpack.config.js中:
  modeule.exports = {
    entry: [‘babel-polyfill‘,‘./app/js‘]
  }

轉碼器babel