First, the installation package
npm install --save-dev babel-loader @babel/core
npm install @babel/preset-env --save-dev
npm install --save @babel/polyfill
npm install --save-dev @babel/plugin-transform-runtime
npm install --save @babel/runtime
npm install @babel/runtime-corejs2 -D
Then two of the module configuration webpack.config.js
module: { rules: [ { test: /\.js$/, exclude: /node_modules/, loader: "babel-loader" } ] }
Then three configuration files in the root directory .babelrc
{ "plugins": [ [ "@babel/plugin-transform-runtime", { "absoluteRuntime": false, "corejs": 2, "helpers": true, "regenerator": true, "useESModules": false } ] ] }
Not .babelrc configuration file can also:
https://babeljs.io/setup#installation some of the installation configuration of about webpack
{ test: /\.js$/, exclude: /node_modules/, loader: "babel-loader", options: { // "presets": [["@babel/preset-env",{ // "targets": { // "chrome": "67" // }, // useBuiltIns: "usage", // }]] "plugins": [ [ "@babel/plugin-transform-runtime", { "absoluteRuntime": false, "corejs": 2, "helpers": true, "regenerator": true, "useESModules": false } ] ] } }
The syntax allows ES6 becomes the ES5, backward compatible, may also be incorporated in accordance with the automatic function references used in the absence of