/// import path from 'node:path'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import tailwindcss from '@tailwindcss/vite'; import { version } from './package.json'; // https://vite.dev/config/ export default defineConfig(({ command }) => ({ // Production builds are deployed under /admin (see Program.cs); the dev server keeps serving from '/'. base: command === 'build' ? '/admin/' : '/', plugins: [react(), tailwindcss()], define: { // Injected at build time, used as the Sentry `release` tag (see src/lib/sentry.ts). __APP_VERSION__: JSON.stringify(version), }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, server: { port: 5173, proxy: { // Mirrors the tunnel path the API serves in test and production, so the same // Sentry `tunnel` option also works during `pnpm dev` — where this SPA runs on // 5173 and the API on 7221. // // Note this targets our own API rather than Sentry's ingest host directly. The // reference project proxies straight to Sentry, which forces the DSN's project id // into this file and requires keeping it in sync by hand. The API derives the // destination from its own DSN, so there is nothing to synchronise and no project // id in a committed file. '/sentry-tunnel': { target: 'https://localhost:7221', changeOrigin: true, secure: false, }, }, }, test: { globals: true, environment: 'jsdom', setupFiles: ['./src/test/setup.ts'], testTimeout: 20000, css: true, coverage: { provider: 'v8', reporter: ['text', 'html'], include: ['src/**/*.{ts,tsx}'], exclude: [ 'src/**/*.test.{ts,tsx}', 'src/test/**', 'src/mocks/**', 'src/main.tsx', 'src/vite-env.d.ts', // Calls Sentry.init, which cannot run meaningfully under jsdom; its skip-without- // a-DSN behaviour is covered by a test that asserts init was not called. 'src/lib/sentry.ts', ], }, }, }));