import { defineConfig, loadEnv } from 'vite' import react from '@vitejs/plugin-react' import tailwindcss from '@tailwindcss/vite' import { fileURLToPath, URL } from 'node:url' // In dev, Vite serves the SPA with HMR and proxies /api to the Go backend. The // backend listens on PANSY_PORT (default 8080); read it so the proxy target // tracks an overridden port. The production build is embedded into the Go binary // (see internal/webdist), so no proxy is involved there. export default defineConfig(({ mode }) => { const env = loadEnv(mode, process.cwd(), '') const backendPort = env.PANSY_PORT || process.env.PANSY_PORT || '8080' return { plugins: [react(), tailwindcss()], resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)), }, }, server: { port: 5173, proxy: { '/api': { target: `http://127.0.0.1:${backendPort}`, changeOrigin: true, }, }, }, build: { outDir: 'dist', sourcemap: true, }, } })