import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react-swc'; // In dev, the UI is served by Vite at :5173 and proxies `/api/*` to the // moments-api binary at :8080 (default). In prod, nginx serves the static // build and reverse-proxies the same `/api/*` to the API backend, so the // frontend's URL shape is identical in both environments. export default defineConfig({ plugins: [react()], // For the prerender (`vite build --ssr`), bundle dependencies into the server // output rather than externalising them. Several deps (react-bootstrap, // react-markdown, …) use subpath/ESM-directory imports or pull in CSS that a // raw Node `import` of the externalised package can't resolve; bundling lets // vite resolve the subpaths and strip the CSS. Has no effect on client builds. ssr: { noExternal: true, }, server: { proxy: { '/api': { target: process.env.API_PROXY_TARGET ?? 'http://localhost:8080', changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), }, }, }, });