Repository navigation
Expand file tree
/
Copy pathvite.config.ts
More file actions
189 lines (186 loc) · 6.58 KB
/
Copy pathvite.config.ts
File metadata and controls
189 lines (186 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import { defineConfig } from 'vitest/config'
import react from '@vitejs/plugin-react'
import { VitePWA } from 'vite-plugin-pwa'
import { cloudflare } from "@cloudflare/vite-plugin";
import { readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
// MapLibre 6 loads maplibre-gl-worker.mjs, which imports ./maplibre-gl-shared.mjs by
// relative path. Vite can't see that import, so emit both side by side, unhashed.
const maplibreWorkerFiles = ['maplibre-gl-worker.mjs', 'maplibre-gl-shared.mjs']
const emitMaplibreWorker = () => ({
name: 'emit-maplibre-worker',
apply: 'build' as const,
generateBundle(this: any) {
const dist = createRequire(import.meta.url).resolve('maplibre-gl/package.json').replace('package.json', 'dist/')
for (const file of maplibreWorkerFiles) {
this.emitFile({ type: 'asset', fileName: `maplibre/${file}`, source: readFileSync(dist + file) })
}
},
})
export default defineConfig({
plugins: [react(), emitMaplibreWorker(), VitePWA({
registerType: 'prompt',
injectRegister: 'auto',
// Disable SW in development so we don't trip over aggressive caching
devOptions: {
enabled: false,
},
workbox: {
globPatterns: ['**/*.{js,mjs,css,html,ico,png,svg,webp,pmtiles,json,woff2}'],
maximumFileSizeToCacheInBytes: 5 * 1024 * 1024,
runtimeCaching: [
// Explicit allowlist, not a wildcard — Workbox caches by URL only (ignores
// Authorization), so a blanket rule would silently cache auth-gated/live
// endpoints too. Everything not listed here falls through to the network;
// the API also sends its own Cache-Control as a second layer of defense.
{
urlPattern: /^https:\/\/api\.rivers\.run\/rivers(\?.*)?$/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'rivers-metadata-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 // mirrors the server's stale-while-revalidate=86400
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
// No rule for /rivers/{id} — its only consumer (RiverEditor) needs guaranteed-
// current data, so it bypasses the worker; the API sends `must-revalidate`.
{
// Prefer live data, but don't hang on a bad-but-connected network (lie-fi) —
// fall back to cache after 2s while the live fetch keeps running in the background.
urlPattern: /^https:\/\/api\.rivers\.run\/community\/lists(\?.*)?$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'community-lists-cache',
networkTimeoutSeconds: 2,
expiration: {
maxEntries: 3,
maxAgeSeconds: 60 * 60 * 24 // mirrors the server's stale-while-revalidate=86400
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
// /lists/{id} is public (the ID is the sharing capability) — unlike bare
// /lists, which is auth-gated "my lists" and stays no-store (see api/src/index.ts).
urlPattern: /^https:\/\/api\.rivers\.run\/lists\/[^/]+(\?.*)?$/i,
handler: 'NetworkFirst',
options: {
cacheName: 'lists-detail-cache',
networkTimeoutSeconds: 2,
expiration: {
maxEntries: 30,
maxAgeSeconds: 60 * 60 * 24 // mirrors the server's stale-while-revalidate=86400
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
urlPattern: /^https:\/\/flow\.rivers\.run\/.*/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'flow-data-cache-v2',
expiration: {
maxEntries: 20,
maxAgeSeconds: 60 * 60 * 24 // 1 day
},
broadcastUpdate: {
channelName: 'flow-data-updates',
options: {}
}
}
}
// (Removed dead rules for firebasestorage.googleapis.com and riverdata.json —
// neither is used or referenced anywhere in this app.)
]
},
manifest: {
name: 'Rivers.run',
short_name: 'Rivers.run',
description: 'Every River at your Fingertips!',
theme_color: '#317EFB',
background_color: '#317EFB',
display: 'standalone',
prefer_related_applications: true,
related_applications: [
{
platform: "play",
url: "https://play.google.com/store/apps/details?id=run.rivers.twa",
id: "run.rivers.twa"
}
],
icons: [
{
src: '/icons/icon-72.webp',
sizes: '72x72',
type: 'image/webp'
},
{
src: '/icons/icon-96.webp',
sizes: '96x96',
type: 'image/webp'
},
{
src: '/icons/icon-128.webp',
sizes: '128x128',
type: 'image/webp'
},
{
src: '/icons/icon-192.webp',
sizes: '192x192',
type: 'image/webp'
},
{
src: '/icons/icon-256.webp',
sizes: '256x256',
type: 'image/webp'
},
{
src: '/icons/icon-512.webp',
sizes: '512x512',
type: 'image/webp'
}
]
}
}), process.env.VITEST ? null : cloudflare()],
server: {
host: true,
port: 5173,
strictPort: true,
},
// Dev serves MapLibre from its dist folder, beside the maplibre-gl-worker.mjs it loads by
// relative URL; pre-bundling would move it to .vite/deps where the worker 404s.
optimizeDeps: {
exclude: ['maplibre-gl'],
},
worker: {
format: 'iife',
},
build: {
target: ['es2020', 'edge88', 'firefox78', 'chrome87', 'safari14'],
},
test: {
globals: true,
environment: 'happy-dom', // Better for React/DOM testing than plain node
exclude: ['node_modules', 'dist', '.git', '.claude/**', 'api', 'api-flow', 'functions', 'tests'],
// api/ and api-flow/ need `environment: 'node'` (they're Workers, not
// DOM code) — a single Vitest run can't mix environments in one project,
// so they're declared as separate projects here instead. This makes
// `npm test` from the root genuinely cover all three workspaces in one
// command/report, rather than relying on each CI step to remember to
// `cd` into them separately.
projects: [
{ extends: true, test: { name: 'web' } },
'api/vitest.config.mts',
'api-flow/vitest.config.mts',
],
},
})