import { defineConfig } from 'vitest/config' import react from '@vitejs/plugin-react' import path from 'path' import fs from 'fs' // Generate a build timestamp for version checking const buildTimestamp = new Date().toISOString(); // https://vite.dev/config/ export default defineConfig({ logLevel: 'info', plugins: [ react(), // Plugin to generate version.json on build { name: 'generate-version-file', closeBundle() { const distPath = path.resolve(__dirname, 'dist'); // Ensure dist directory exists before writing if (!fs.existsSync(distPath)) { fs.mkdirSync(distPath, { recursive: true }); } const versionInfo = { buildTimestamp, generatedAt: new Date().toISOString(), }; fs.writeFileSync( path.resolve(distPath, 'version.json'), JSON.stringify(versionInfo, null, 2) ); console.log('[generate-version-file] Created dist/version.json with timestamp:', buildTimestamp); }, }, ], // Inject build timestamp into the app define: { 'import.meta.env.VITE_BUILD_TIMESTAMP': JSON.stringify(buildTimestamp), }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, build: { // Increase chunk size warning limit (mermaid is large) chunkSizeWarningLimit: 2000, rollupOptions: { output: { // Manual chunks to separate large dependencies manualChunks: { maplibre: ['maplibre-gl'], }, }, }, }, optimizeDeps: { include: ['maplibre-gl'], // Exclude mermaid from pre-bundling - it's dynamically imported exclude: ['mermaid'], }, server: { port: 5173, proxy: { // PostgreSQL API proxy '/api/postgres': { target: 'http://localhost:3001', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/postgres/, ''), }, // Geo API proxy (PostGIS backend on port 8002) '/api/geo': { target: 'http://localhost:8002', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/geo/, ''), }, // TypeDB API proxy '/api/typedb': { target: 'http://localhost:8002', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/typedb/, ''), }, // DuckLake API proxy '/ducklake': { target: 'http://localhost:8765', changeOrigin: true, rewrite: (path) => path.replace(/^\/ducklake/, ''), }, // Qdrant vector database proxy (port 6333) '/qdrant': { target: 'http://localhost:6333', changeOrigin: true, rewrite: (path) => path.replace(/^\/qdrant/, ''), }, // RAG API proxy (Heritage RAG backend on port 8003) '/api/rag': { target: 'http://localhost:8003', changeOrigin: true, }, // Generic API fallback '/api': { target: 'http://localhost:8000', changeOrigin: true, }, // Profile entity API proxy '/api/profile-entity': { target: 'http://localhost:8001', changeOrigin: true, rewrite: (path) => path.replace(/^\/api\/profile-entity/, ''), }, // Oxigraph SPARQL endpoint proxy '/sparql': { target: 'http://127.0.0.1:7878', changeOrigin: true, rewrite: (path) => path.replace(/^\/sparql/, ''), }, }, }, test: { globals: true, environment: 'jsdom', setupFiles: './tests/setup.ts', coverage: { provider: 'v8', reporter: ['text', 'json', 'html'], exclude: [ 'node_modules/', 'tests/', '**/*.test.{ts,tsx}', '**/*.spec.{ts,tsx}', ], }, }, });