import react from '@vitejs/plugin-react'; import { defineConfig } from 'vite'; import { VitePWA } from 'vite-plugin-pwa'; export default defineConfig({ plugins: [ react(), // PWA app-shell caching for offline editing (issue #38). Only build assets // are precached; the service worker never caches `/api` or `/collab` // (no runtime caching + navigation-fallback denylist), so API responses are // always fresh from the network and never poisoned by a stale cache. VitePWA({ registerType: 'autoUpdate', injectRegister: 'auto', workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], navigateFallback: '/index.html', navigateFallbackDenylist: [/^\/api/, /^\/collab/], }, // No dev service worker — the SW is exercised against the production // build (dist) only, which keeps native `vite` dev free of SW caching. devOptions: { enabled: false }, manifest: { name: 'Dorfteich', short_name: 'Dorfteich', description: 'Collaborative wiki', theme_color: '#2f6f4f', background_color: '#ffffff', display: 'standalone', start_url: '/', }, }), ], server: { // Native dev: api on localhost:3001 (3000 may be occupied by other // projects). Containerized dev overrides this via VITE_API_PROXY_TARGET. proxy: { '/api': process.env.VITE_API_PROXY_TARGET ?? 'http://localhost:3001', // The collab WebSocket (issue #36); `ws: true` upgrades the connection. '/collab': { target: process.env.VITE_COLLAB_PROXY_TARGET ?? 'http://localhost:3002', ws: true, }, }, }, });