Install the following plug-ins in the development dependency package:
yarn add @babel/core babel-loader @babel/preset-env @babel/plugin-transform-runtime @babel/plugin-transform-modules-commonjs -D
Dependency package installation online
yarn add @babel/runtime -D
/ / the Babel configuration
{
test: /\.(jsx|js)$/,
use: {
loader: 'babel-loader'.// options:{
// Presets :["@babel/preset-env"] // Method one
// }
},
exclude: /node_modules/
}
Copy the code
.babelrc (Method 2)
{
"presets": [["@babel/preset-env", {
"useBuiltIns": "usage".// Inject as needed
"corejs": "2".// Declare the corejs version
"targets": {
"browsers": [ "1%" >."last 5 versions"."ie >= 8"]}}]],"plugins": [// This plugin transforms ES2015 modules to CommonJS.
["@babel/plugin-transform-runtime"}, {}]]Copy the code
@babel/plugin-transform-runtime prevents global contamination
Yarn add @babel/plugin-transform-runtime –dev yarn add @babel/runtime- save yarn add @babel/ run-time corejs2 // Install yarn only if an error occurs yarn add @babel/polyfill –dev
{
"presets": [["@babel/preset-env", {
"useBuiltIns": "usage".// Inject as needed
"corejs": "2".// Declare the corejs version
"targets": {
"browsers": [ "1%" >."last 5 versions"."ie >= 8"]}}]],"plugins": [// This plugin transforms ES2015 modules to CommonJS.
["@babel/plugin-transform-runtime", { "absoluteRuntime":false."corejs":2."helpers":true."regenerator":true."useESModules":false}}]]Copy the code