import { dirname, resolve } from 'node:path'; import { fileURLToPath } from 'node:url'; import react from '@vitejs/plugin-react'; import { defineConfig, loadEnv } from 'vite'; const adminWebRoot = dirname(fileURLToPath(import.meta.url)); const repoRoot = resolve(adminWebRoot, '../..'); export default defineConfig(({ command, mode }) => { const repoEnv = loadEnv(mode, repoRoot, ''); const appEnv = loadEnv(mode, adminWebRoot, ''); const env = { ...repoEnv, ...appEnv }; const apiTarget = env.ADMIN_API_TARGET || env.GENARRATIVE_API_TARGET || `http://127.0.0.1:${env.GENARRATIVE_API_PORT || '3100'}`; const base = env.ADMIN_WEB_BASE || '/admin/'; const ignoredWatchGlobs = [ '**/.git/**', '**/.worktrees/**', '**/dist/**', '**/node_modules/**', '**/server-rs/**', '**/server-rs/target/**', ]; return { root: adminWebRoot, publicDir: command === 'serve' ? resolve(repoRoot, 'public') : false, envDir: repoRoot, base, plugins: [react()], server: { watch: { ignored: ignoredWatchGlobs, }, proxy: { '/admin/api': { target: apiTarget, changeOrigin: true, secure: false, }, '/api/assets': { target: apiTarget, changeOrigin: true, secure: false, }, '/healthz': { target: apiTarget, changeOrigin: true, secure: false, }, }, }, build: { outDir: 'dist', emptyOutDir: true, chunkSizeWarningLimit: 600, }, }; });