import { fileURLToPath, URL } from 'node:url' import vue from '@vitejs/plugin-vue' import { defineConfig, loadEnv } from 'vite' function normalizeBasePath(value: string | undefined) { const trimmed = value?.trim() if (!trimmed || trimmed === '/') { return '/' } return `/${trimmed.replace(/^\/+|\/+$/g, '')}/` } export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const appBase = normalizeBasePath(env.VITE_APP_BASE) const devApiOrigin = env.VITE_DEV_API_ORIGIN?.trim() || 'http://127.0.0.1:8080' return { base: appBase, plugins: [vue()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, server: { port: 5173, host: '0.0.0.0', proxy: { '/api': { target: devApiOrigin, changeOrigin: true, configure: (proxy) => { proxy.on('proxyRes', (proxyRes) => { proxyRes.headers['x-accel-buffering'] = 'no' proxyRes.headers['cache-control'] = 'no-cache' }) }, }, }, }, } })