vue3+vite配置兼容ie11
时间: 2023-12-22 19:05:27 浏览: 241
为了让Vue3和Vite在IE11上正常工作,需要进行以下配置:
1.安装依赖
```shell
npm install @vitejs/plugin-vue@^1.0.0 vite-plugin-compression -D
npm install core-js@3.6.5 -S
```
2.在vite.config.js中添加以下配置:
```javascript
import vue from '@vitejs/plugin-vue'
import compression from 'vite-plugin-compression'
export default {
plugins: [
vue(),
compression({
algorithm: 'gzip',
ext: '.gz'
})
],
build: {
target: 'es2015',
polyfillDynamicImport: false,
outDir: 'dist',
assetsDir: 'assets',
assetsInlineLimit: 4096,
cssCodeSplit: true,
sourcemap: false,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id.toString().split('node_modules/')[1].split('/')[0].toString()
}
}
}
}
},
optimizeDeps: {
include: [
'core-js/stable',
'regenerator-runtime/runtime'
]
}
}
```
3.在main.js中添加以下代码:
```javascript
import 'core-js/stable'
import 'regenerator-runtime/runtime'
```
4.在index.html中添加以下代码:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue3 + Vite</title>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es2015%2CIntersectionObserver"></script>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
```
5.在package.json中添加以下代码:
```json
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 11"
]
```
阅读全文