import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' import { VitePWA } from 'vite-plugin-pwa' // Support environment variables for development const BACKEND_PORT = process.env.BACKEND_PORT || '8000' const CLIENT_PORT = process.env.CLIENT_PORT || '5173' // Allow overriding the proxy target for Docker development const PROXY_TARGET = process.env.VITE_API_PROXY_TARGET || `http://localhost:${BACKEND_PORT}` export default defineConfig({ plugins: [ react(), VitePWA({ registerType: 'autoUpdate', includeAssets: ['favicon.ico', 'readur-32.png', 'readur-64.png', 'icons/*.png', 'offline.html'], manifest: { name: 'Readur - Document Intelligence Platform', short_name: 'Readur', description: 'AI-powered document management with OCR and intelligent search', theme_color: '#6366f1', background_color: '#ffffff', display: 'standalone', orientation: 'portrait-primary', scope: '/', start_url: '/', icons: [ { src: '/readur-32.png', sizes: '32x32', type: 'image/png' }, { src: '/readur-64.png', sizes: '64x64', type: 'image/png' }, { src: '/icons/icon-192.png', sizes: '192x192', type: 'image/png', purpose: 'any' }, { src: '/icons/icon-512.png', sizes: '512x512', type: 'image/png', purpose: 'any' }, { src: '/icons/icon-192-maskable.png', sizes: '192x192', type: 'image/png', purpose: 'maskable' }, { src: '/icons/icon-512-maskable.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' } ] }, workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff,woff2}'], globIgnores: ['**/readur.png'], maximumFileSizeToCacheInBytes: 3 * 1024 * 1024, // 3 MB limit // Exclude auth routes from navigation fallback and caching navigateFallbackDenylist: [/^\/api\/auth\//], runtimeCaching: [ { urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i, handler: 'CacheFirst', options: { cacheName: 'google-fonts-cache', expiration: { maxEntries: 10, maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year }, cacheableResponse: { statuses: [0, 200] } } }, { urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i, handler: 'CacheFirst', options: { cacheName: 'gstatic-fonts-cache', expiration: { maxEntries: 10, maxAgeSeconds: 60 * 60 * 24 * 365 // 1 year }, cacheableResponse: { statuses: [0, 200] } } }, { // Only cache non-auth API routes urlPattern: /^\/api\/(?!auth\/).*/, handler: 'NetworkFirst', options: { cacheName: 'api-cache', expiration: { maxEntries: 100, maxAgeSeconds: 60 * 5 // 5 minutes }, networkTimeoutSeconds: 10 } } ] }, devOptions: { enabled: false // Disable PWA in dev mode for faster development } }) ], test: { environment: 'jsdom', setupFiles: ['src/test/setup.ts'], }, server: { port: parseInt(CLIENT_PORT), proxy: { '/api': { target: PROXY_TARGET, changeOrigin: true, }, }, }, build: { outDir: 'dist', assetsDir: 'assets', rollupOptions: { onwarn(warning, warn) { // Suppress "use client" directive warnings from MUI if (warning.code === 'MODULE_LEVEL_DIRECTIVE') { return } warn(warning) } } }, })