import { execSync } from 'node:child_process'; import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import { VitePWA } from 'vite-plugin-pwa'; function getCommit(): string { try { return execSync('git rev-parse --short HEAD').toString().trim(); } catch { return 'dev'; } } export default defineConfig({ define: { __APP_VERSION__: JSON.stringify({ commit: getCommit(), builtAt: new Date().toISOString() }), }, plugins: [ react(), VitePWA({ registerType: 'autoUpdate', injectRegister: false, devOptions: { enabled: false, }, manifest: { name: 'CityTracker', short_name: 'CityTracker', description: "Track cities you've visited or plan to visit on a map.", start_url: '/', scope: '/', display: 'standalone', theme_color: '#1971c2', background_color: '#f7f7f5', icons: [ { src: '/pwa-192x192.png', sizes: '192x192', type: 'image/png', }, { src: '/pwa-512x512.png', sizes: '512x512', type: 'image/png', }, { src: '/maskable-512x512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable', }, ], }, workbox: { // /api and /uploads are intentionally left uncached so city data and // photos always come from the network, never a stale service worker cache. runtimeCaching: [ { urlPattern: /^https:\/\/[abc]\.tile\.openstreetmap\.org\/.*/, handler: 'CacheFirst', options: { cacheName: 'osm-tiles', expiration: { maxEntries: 500, maxAgeSeconds: 60 * 60 * 24 * 7, }, }, }, ], }, }), ], server: { port: 5173, proxy: { '/api': 'http://localhost:3000', '/uploads': 'http://localhost:3000', }, }, build: { outDir: 'dist', }, });