安装babel相关库
babel-loader
@babel/core
@babel/plugin-proposal-class-properties
@babel/plugin-transform-runtime
@babel/preset-env
@babel/runtime
npm install babel-loader @babel/core @babel/plugin-proposal-class-properties @babel/plugin-transform-runtime @babel/preset-env @babel/runtime -D
项目根目录添加文件 .babelrc
{
"presets": ["@babel/preset-env"],
"plugins": [
"@babel/plugin-transform-runtime",
"@babel/plugin-proposal-class-properties"
]
}
webpack.config.js中添加
module: {
rules: [
{
test: /\.js$/,
exclude:/node_modules/,
use:["babel-loader"],
}
]
}