8b1df674ec
问题原因: - element-plus 2.14.x 的 package.json exports 包含 ./*: ./ 通配符 - Vite 5.x 的 import-analysis 在某些场景下无法解析该 exports 配置 - 新机器 git pull + npm install 后 Vite 缓存为空,首次预构建可能失败 - 报错: Failed to resolve entry for package 'element-plus' 解决方案: 1. vite.config.js resolve.alias 添加 element-plus 显式 fallback 路径 即使 exports 解析失败也能直接定位到 es/index.mjs 2. start.sh 启动前自动清理 .vite 缓存,避免过期缓存问题 3. start.sh 失败自动重试+清缓存机制,提高首次启动成功率
32 lines
803 B
JavaScript
32 lines
803 B
JavaScript
import { fileURLToPath, URL } from 'node:url'
|
|
import path from 'node:path'
|
|
|
|
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 exports 解析失败则走 fallback
|
|
'element-plus': path.resolve(
|
|
fileURLToPath(new URL('node_modules/element-plus/es/index.mjs', import.meta.url))
|
|
)
|
|
}
|
|
},
|
|
server: {
|
|
host: '0.0.0.0',
|
|
port: 3000,
|
|
// 允许任意 Host 头访问(HMR WebSocket 在远程访问时需要)
|
|
allowedHosts: true,
|
|
proxy: {
|
|
'/api': {
|
|
target: 'http://localhost:8008',
|
|
changeOrigin: true
|
|
}
|
|
}
|
|
}
|
|
})
|