vue3+vite+ts配置兼容ie11
时间: 2023-12-21 13:06:13 浏览: 295
为了让Vue3 + Vite + TypeScript应用程序兼容IE11,需要进行以下配置:
1.安装必要的依赖项
```shell
npm install -D vite-plugin-compat @vitejs/plugin-legacy
```
2.在vite.config.ts中添加以下内容:
```typescript
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import legacy from '@vitejs/plugin-legacy'
import { viteSingleFile } from 'vite-plugin-singlefile'
export default defineConfig({
plugins: [
vue(),
legacy({
targets: ['defaults', 'not IE 11']
}),
viteSingleFile()
],
build: {
target: 'es2015',
polyfillDynamicImport: false,
outDir: 'dist'
}
})
```
3.在main.ts中添加以下内容:
```typescript
import 'core-js/stable'
import 'regenerator-runtime/runtime'
```
4.在tsconfig.json中添加以下内容:
```json
{
"compilerOptions": {
"target": "es5",
"lib": ["es6", "dom"],
"module": "esnext",
"moduleResolution": "node",
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"strict": true,
"noImplicitAny": false,
"noImplicitThis": true,
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
```
5.在package.json中添加以下内容:
```json
{
"browserslist": [
"> 1%",
"last 2 versions",
"not ie <= 11"
]
}
```
以上是Vue3 + Vite + TypeScript应用程序兼容IE11的配置方法。
阅读全文