8a94f535de
问题原因: - Vite dev server 长时间运行(跨天)后 deps 缓存过期 - import-analysis 阶段无法解析 element-plus 包入口 - 报错: Failed to resolve entry for package "element-plus" 解决方案: - vite.config.js 添加 optimizeDeps.include 显式预构建 element-plus 等核心依赖 - package.json 添加 predev 脚本, npm run dev 前自动清 .vite 缓存 - 防止其他服务器 git pull 后同样踩坑
39 lines
863 B
JavaScript
39 lines
863 B
JavaScript
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import { defineConfig } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig({
|
|
plugins: [vue()],
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
}
|
|
},
|
|
// 显式预构建 element-plus,避免 Vite 缓存过期后
|
|
// 出现 "Failed to resolve entry for package element-plus" 错误
|
|
optimizeDeps: {
|
|
include: [
|
|
'element-plus',
|
|
'@element-plus/icons-vue',
|
|
'vue',
|
|
'vue-router',
|
|
'pinia',
|
|
'axios'
|
|
]
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 3000,
|
|
// 允许任意 Host 头访问(HMR WebSocket 在远程访问时需要)
|
|
allowedHosts: true,
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8008',
|
|
changeOrigin: true
|
|
}
|
|
}
|
|
}
|
|
})
|