glam/frontend/vite.config.ts
2025-12-21 00:01:54 +01:00

140 lines
3.7 KiB
TypeScript

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: {
// =======================================================================
// REMOTE BACKEND: Proxy to bronhouder.nl (Hetzner server)
// To switch back to local, change 'https://bronhouder.nl' to 'http://localhost:PORT'
// =======================================================================
// PostgreSQL API proxy
'/api/postgres': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// Geo API proxy (PostGIS backend)
'/api/geo': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// TypeDB API proxy
'/api/typedb': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// DuckLake API proxy
'/ducklake': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// Qdrant vector database proxy
'/qdrant': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// RAG API proxy
'/api/rag': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// Generic API fallback
'/api': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// Profile entity API proxy
'/api/profile-entity': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
// Oxigraph SPARQL endpoint proxy
'/sparql': {
target: 'https://bronhouder.nl',
changeOrigin: true,
secure: true,
},
},
},
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}',
],
},
},
});