57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
import { defineConfig, loadEnv } from 'vite'
|
|
|
|
function resolveBuildId() {
|
|
const configured = process.env.BUILD_ID?.trim().replace(/[^a-zA-Z0-9_-]/g, '')
|
|
return configured || Date.now().toString(36)
|
|
}
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
// 以 vite.config 所在目录为基准读取 .env,避免「在仓库根目录跑 dev:clinical」
|
|
// 时 cwd 不是 clinical-web 而读不到 .env.local。
|
|
const configDir = fileURLToPath(new URL('.', import.meta.url))
|
|
const env = loadEnv(mode, configDir, '')
|
|
const buildId = resolveBuildId()
|
|
const apiProxyTarget =
|
|
process.env.VITE_API_PROXY_TARGET?.trim() ||
|
|
env.VITE_API_PROXY_TARGET?.trim() ||
|
|
'http://127.0.0.1:18080'
|
|
|
|
// 启动日志:直接告诉你 /api 到底被代理到了哪里,排查「没走真实接口」时用。
|
|
// 显示 18080 说明 .env.local 没被读到;显示 ipad.shenynet.com 才是真实接口生效。
|
|
console.log(`[vite] API 代理目标: ${apiProxyTarget}`)
|
|
|
|
return {
|
|
plugins: [vue()],
|
|
build: {
|
|
rollupOptions: {
|
|
output: {
|
|
entryFileNames: `assets/[name]-${buildId}-[hash].js`,
|
|
chunkFileNames: `assets/[name]-${buildId}-[hash].js`,
|
|
assetFileNames: `assets/[name]-${buildId}-[hash][extname]`,
|
|
},
|
|
},
|
|
},
|
|
server: {
|
|
// The public HTTPS virtual host terminates TLS in Nginx and proxies to this dev server.
|
|
// Permit only that configured hostname; keep Vite's DNS-rebinding protection enabled.
|
|
allowedHosts: ['fn.xianyi.de'],
|
|
proxy: {
|
|
'/api': {
|
|
target: apiProxyTarget,
|
|
changeOrigin: true,
|
|
secure: true,
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
|
},
|
|
},
|
|
}
|
|
})
|