import { readFileSync } from 'node:fs'; import react from '@vitejs/plugin-react'; import { defineConfig } from 'vitest/config'; interface PackageJson { version: string; kvitt: { versionCode: number }; } const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')) as PackageJson; /** API paths of contracts/openapi.yaml; `npm run dev` forwards them to a local kvitt-server (README). */ const API_PREFIXES = [ '/health', '/setup', '/invites', '/me', '/users', '/devices', '/accounts', '/categories', '/recurring-templates', '/sync', '/settlements', '/apk', ]; const devApi = process.env.KVITT_DEV_API ?? 'http://localhost:8080'; export default defineConfig({ base: '/app/', plugins: [react()], define: { __KVITT_VERSION_NAME__: JSON.stringify(pkg.version), __KVITT_VERSION_CODE__: JSON.stringify(pkg.kvitt.versionCode), }, server: { proxy: Object.fromEntries(API_PREFIXES.map((prefix) => [prefix, { target: devApi, changeOrigin: true }])), }, build: { outDir: 'dist', sourcemap: false, rolldownOptions: { output: { // Libraries in their own chunks: they change less often than the app, so browsers keep them across deploys. codeSplitting: { groups: [ { name: 'react', test: /node_modules[\\/](react|react-dom|scheduler)[\\/]/ }, { name: 'vendor', test: /node_modules[\\/]/ }, ], }, }, }, }, test: { environment: 'jsdom', setupFiles: ['src/test/setup.ts'], include: ['src/**/*.test.{ts,tsx}'], css: { modules: { classNameStrategy: 'non-scoped' } }, }, });