我的项目用IE运行报错,是ie不支持es6的原因。然后我安装了babel,但是没有生效无法运行,尝试了很多方法都不行,救救孩子吧。
vue版本:2.6.1
vue cli版本:4.5.6
IE控制台
babel.config.js文件:
module.exports = {
presets: [
[
'@vue/app',
{
useBuiltIns: 'entry'
}
],
],
plugins: [
[
'import',
{
libraryName: 'vant',
libraryDirectory: 'es',
style: true
},
'vant'
]
]
};
.browserslistrc文件:
> 1%
last 2 versions
IE 11
package.json文件:
{
"name": "goodsmanagerapp",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build"
},
"dependencies": {
"@babel/polyfill": "^7.12.1",
"axios": "^0.20.0",
"core-js": "^3.8.1",
"vant": "^2.10.8",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuex": "^3.4.0"
},
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"@babel/plugin-transform-arrow-functions": "^7.12.1",
"@babel/preset-env": "^7.12.10",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"babel-plugin-import": "^1.13.0",
"css-loader": "^4.3.0",
"es6-promise": "^4.2.8",
"vue-template-compiler": "^2.6.11"
}
}
vue.config.js文件:
module.exports = {
runtimeCompiler: true,
publicPath: '/Content/app',
devServer: {
disableHostCheck: true
}, css: {
extract: false,
sourceMap: true
},
transpileDependencies: ['*'],
chainWebpack: config => {
config.entry('main').add('@babel/polyfill');
}
}
main.js :引入了babel
import '@babel/polyfill';
import Es6Promise from 'es6-promise'
Es6Promise.polyfill()
import 'core-js/stable'; import 'regenerator-runtime/runtime';
.....
更新:现在没有报错但是仍然白屏,更诡异的是ie9可以运行,10和11不可以
上面
es6-promise
是比较旧的,可以试下babel-polyfill
: