import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import tailwindcss from '@tailwindcss/vite'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; const here = fileURLToPath(new URL('.', import.meta.url)); // Dev ports default to the spec values; overridable via env so the e2e run can // dodge a port that another project is already using (the client uses relative // URLs, so it follows whatever port Vite binds). const vitePort = Number(process.env.VITE_PORT ?? 5173); const apiPort = Number(process.env.HISTORY_API_PORT ?? 4321); export default defineConfig({ plugins: [react(), tailwindcss()], resolve: { alias: { '@shared': path.resolve(here, 'shared'), '@': path.resolve(here, 'src'), }, }, server: { port: vitePort, // The Express backend (tsx) listens on :4321. In dev, proxy the API and the // SSE stream to it so the client never needs to know the backend origin. proxy: { '/api': { target: `http://localhost:${apiPort}`, changeOrigin: true }, '/sse': { target: `http://localhost:${apiPort}`, changeOrigin: true }, }, }, build: { outDir: 'dist', emptyOutDir: true, }, });