2026-03-08 17:41:38 +01:00
|
|
|
import { defineConfig } from 'vite';
|
|
|
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
2026-03-23 15:35:39 +01:00
|
|
|
base: './',
|
2026-03-08 17:41:38 +01:00
|
|
|
define: {
|
|
|
|
|
// Injected as a global — changes every build, breaking any stale cache
|
|
|
|
|
__BUILD_REVISION__: JSON.stringify(
|
|
|
|
|
`${new Date().toISOString().slice(0, 16)}`,
|
|
|
|
|
),
|
|
|
|
|
},
|
|
|
|
|
plugins: [
|
|
|
|
|
VitePWA({
|
|
|
|
|
registerType: 'autoUpdate',
|
|
|
|
|
workbox: {
|
|
|
|
|
// Precache all built assets (JS/CSS get content hashes from Vite;
|
|
|
|
|
// files in public/ like shelters.json get a Workbox revision hash
|
|
|
|
|
// computed from their content, so any change triggers re-fetch).
|
|
|
|
|
globPatterns: ['**/*.{js,css,html,json,png,svg,ico,webmanifest}'],
|
|
|
|
|
|
|
|
|
|
// Remove old precache entries from previous builds
|
|
|
|
|
cleanupOutdatedCaches: true,
|
|
|
|
|
|
|
|
|
|
// SPA: serve index.html for all navigation requests
|
2026-03-23 15:35:39 +01:00
|
|
|
navigateFallback: 'index.html',
|
2026-03-08 17:41:38 +01:00
|
|
|
|
|
|
|
|
// Vite already hashes JS/CSS filenames — skip Workbox's
|
|
|
|
|
// cache-bust query parameter for those
|
|
|
|
|
dontCacheBustURLsMatching: /\.[0-9a-f]{8}\./,
|
|
|
|
|
|
|
|
|
|
// Runtime caching for map tiles (not precached — cached as viewed)
|
|
|
|
|
runtimeCaching: [
|
|
|
|
|
{
|
|
|
|
|
urlPattern: /^https:\/\/[abc]\.tile\.openstreetmap\.org\/.*/,
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'osm-tiles',
|
|
|
|
|
expiration: {
|
|
|
|
|
maxEntries: 5000,
|
|
|
|
|
maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days
|
|
|
|
|
},
|
|
|
|
|
cacheableResponse: {
|
2026-03-23 14:27:45 +01:00
|
|
|
statuses: [200],
|
2026-03-08 17:41:38 +01:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
manifest: false, // We provide our own manifest.webmanifest
|
|
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
'@': '/src',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
});
|