import { defineConfig, type PluginOption } from 'vite'; import react from '@vitejs/plugin-react'; // Coverage instrumentation is opt-in and must stay that way. The plugin rewrites // every source file to record execution, which is what makes end-to-end coverage // possible and what must never reach a customer: an instrumented bundle is // substantially larger and slower, and it publishes the source structure through // window.__coverage__. // // Nothing in the production path sets COVERAGE — the Dockerfile runs a plain // `npm run build` — so the shipped bundle is uninstrumented. Only the Playwright // coverage run turns this on, via playwright.config.ts passing it to the dev // server it starts. // // Loaded with a dynamic import rather than at the top of the file because // vite-plugin-istanbul is ESM-only and this config is evaluated as CommonJS, the // package having no "type": "module". A static import fails the build outright. // The upside is that a production build never even resolves the package. async function coveragePlugins(): Promise { if (process.env.COVERAGE !== 'true') return []; const { default: istanbul } = await import('vite-plugin-istanbul'); return [istanbul({ include: 'src/**/*', extension: ['.ts', '.tsx'], requireEnv: false })]; } export default defineConfig(async () => ({ plugins: [react(), ...(await coveragePlugins())], build: { outDir: 'dist' }, server: { proxy: { '/api': 'http://localhost:3000', '/uploads': 'http://localhost:3000', '/webhooks': 'http://localhost:3000' } } }));