1 需安装es6-promise, main.js文件中添加
import promise from "es6-promise";
import "babel-polyfill";
promise.polyfill();
2 webpack.base.js文件写入,include里的内容是手动加入需要编译成es5的文件
module:{
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
include: [
resolve('src'),
resolve('test'),
resolve('mock'),
],
},
]
}
3 .babelrc文件 安装npm i babel-preset-env -D (转码神器)
{
"presets": [
["env", {
"modules": false,
"targets": {
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
}
}],
"stage-2"
]
// "plugins": ["transform-vue-jsx", "transform-runtime"]
}
4 package.json文件
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 8"
]