vite打包后访问index.html错误
工具版本
(1)软件工具:IntelliJ IDEA 2021.1 x64、
(2)框架:"vite": "^4.0.0","vue": "^3.2.45",
(3)依赖:"@vitejs/plugin-legacy": "^4.0.4"
问题解决
描述
vite打包后访问index.html控制台错误,页面白板
解决
--> 依赖下载 plugin-legacy
在下载依赖之前建议先看看vite与legacy的版本依赖,避免依赖冲突导致时间的浪费
依赖版本关系:https://registry.npmjs.org/@vitejs%2Fplugin-legacy
npm install @vitejs/plugin-legacy@4.0.4 -D # vite版本为4.0.0
--> vite.config.js配置
import { fileURLToPath, URL } from 'node:url'
import legacy from '@vitejs/plugin-legacy';
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [
vue(),
legacy({
targets: ['ie>=11'], // 支持旧版浏览器
additionalLegacyPolyfills: ['regenerator-runtime/runtime']
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
})
--> 打包后查看index.html即可
您的发现及意见
有存在错误或发现,可及时回复我。

浙公网安备 33010602011771号