// vite.test.config.ts — Plan 01-11 two-bundle separation. // // Extends the production `./vite.config.ts` with two delta knobs: // 1. `mode: 'test'` — Vite statically replaces `import.meta.env.MODE` // everywhere in the input source with the string literal `'test'`. // The gated dynamic imports in src/background/index.ts + // src/offscreen/recorder.ts (Plan 01-11 Task 2) take the form // `if (import.meta.env.MODE === 'test') { await import('../test-hooks/...'); }`. // With mode='test' the comparison resolves to a live branch and // Rollup KEEPS the dynamic import; with the default mode='production' // the comparison is a static dead branch and Rollup tree-shakes the // `await import` away entirely (verified by the Tier-1 grep gate // `tests/background/no-test-hooks-in-prod-bundle.test.ts`). // 2. `build.outDir: 'dist-test'` + `emptyOutDir: true` — emit to a // SEPARATE directory so a `npm run build` immediately after this // build does not clobber. Puppeteer harness consumes this path via // `puppeteer.launch({ enableExtensions: [] })`. // // References: // - Vite mergeConfig: https://vite.dev/guide/api-javascript.html#mergeconfig // - Vite environment variables: https://vite.dev/guide/env-and-mode.html // - Rollup tree-shaking literal-comparison dead branches: // https://rollupjs.org/plugin-development/#how-rollup-handles-dynamic-imports import { defineConfig, mergeConfig, type UserConfigExport } from 'vite'; import baseConfig from './vite.config'; const baseAsExport: UserConfigExport = baseConfig; export default defineConfig(({ command, mode }) => mergeConfig( typeof baseAsExport === 'function' ? baseAsExport({ command, mode, isPreview: false, isSsrBuild: false }) : baseAsExport, { mode: 'test', build: { outDir: 'dist-test', emptyOutDir: true, }, }, ), );