2026-10-03 13:33:50 +02:00
|
|
|
import { defineConfig } from 'vitest/config';
|
|
|
|
|
import react from '@vitejs/plugin-react';
|
|
|
|
|
import { VitePWA } from 'vite-plugin-pwa';
|
2026-10-03 14:29:28 +02:00
|
|
|
import basicSsl from '@vitejs/plugin-basic-ssl';
|
2026-10-03 19:56:49 +02:00
|
|
|
import { statSync } from 'node:fs';
|
2026-10-03 19:14:41 +02:00
|
|
|
import { APP_NAME } from './src/config';
|
2026-10-03 13:33:50 +02:00
|
|
|
|
2026-10-03 19:56:49 +02:00
|
|
|
// Exact (decoded) sizes of the big data files: servers compress and stream them without a Content-Length, so the loading bar needs these.
|
|
|
|
|
const size = (f: string) => { try { return statSync(f).size; } catch { return 0; } };
|
|
|
|
|
const DATA_BYTES = { snapshot: size('public/data/kk-snapshot.json'), transit: size('public/data/kk-transit.json') };
|
|
|
|
|
|
2026-10-03 13:33:50 +02:00
|
|
|
export default defineConfig({
|
|
|
|
|
base: './',
|
2026-10-03 19:56:49 +02:00
|
|
|
define: { __DATA_BYTES__: JSON.stringify(DATA_BYTES) },
|
2026-10-03 13:33:50 +02:00
|
|
|
plugins: [
|
|
|
|
|
react(),
|
2026-10-03 19:14:41 +02:00
|
|
|
// index.html uses %APP_NAME%: one name for the whole app (src/config.ts)
|
|
|
|
|
{ name: 'app-name', transformIndexHtml: (html: string) => html.replaceAll('%APP_NAME%', APP_NAME) },
|
2026-10-03 14:29:28 +02:00
|
|
|
// HTTPS=1 pnpm preview:https -> phones need a secure context for motion sensors and GPS
|
|
|
|
|
...(process.env.HTTPS ? [basicSsl()] : []),
|
2026-10-03 13:33:50 +02:00
|
|
|
VitePWA({
|
|
|
|
|
registerType: 'autoUpdate',
|
|
|
|
|
includeAssets: ['uswds/sprite.svg', 'icons/*.png', 'icons/*.svg'],
|
|
|
|
|
manifest: {
|
2026-10-03 19:14:41 +02:00
|
|
|
name: APP_NAME,
|
|
|
|
|
short_name: APP_NAME,
|
2026-10-03 13:33:50 +02:00
|
|
|
description:
|
|
|
|
|
'Sprawdź dostępność miejsc i tras w Krakowie dla osób na wózkach i rodziców z wózkami dziecięcymi.',
|
|
|
|
|
lang: 'pl',
|
|
|
|
|
start_url: './',
|
|
|
|
|
scope: './',
|
|
|
|
|
display: 'standalone',
|
|
|
|
|
background_color: '#ffffff',
|
|
|
|
|
theme_color: '#1b1b1b',
|
|
|
|
|
icons: [
|
|
|
|
|
{ src: 'icons/icon-192.png', sizes: '192x192', type: 'image/png' },
|
|
|
|
|
{ src: 'icons/icon-512.png', sizes: '512x512', type: 'image/png' },
|
|
|
|
|
{ src: 'icons/icon-maskable-512.png', sizes: '512x512', type: 'image/png', purpose: 'maskable' },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
workbox: {
|
2026-10-03 19:56:49 +02:00
|
|
|
// Offline-first: the whole app (code, fonts, icons, places, paths, timetable) is precached on the first visit.
|
2026-10-03 13:33:50 +02:00
|
|
|
globPatterns: ['**/*.{js,mjs,css,html,svg,png,json,woff2}'],
|
2026-10-03 19:56:49 +02:00
|
|
|
maximumFileSizeToCacheInBytes: 12 * 1024 * 1024, // the places snapshot is ~5.5 MB
|
2026-10-03 13:33:50 +02:00
|
|
|
navigateFallback: 'index.html',
|
2026-10-03 19:56:49 +02:00
|
|
|
navigateFallbackDenylist: [/^\/rt\//], // live feeds are never replaced by the app shell
|
|
|
|
|
cleanupOutdatedCaches: true,
|
|
|
|
|
clientsClaim: true,
|
|
|
|
|
skipWaiting: true,
|
2026-10-03 13:33:50 +02:00
|
|
|
runtimeCaching: [
|
2026-10-03 19:56:49 +02:00
|
|
|
{
|
|
|
|
|
// street map: the offline pack (src/lib/offline.ts) fills this cache; tiles seen while browsing land here too
|
|
|
|
|
urlPattern: /^https:\/\/tile\.openstreetmap\.org\/.*/,
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'osm-tiles',
|
|
|
|
|
expiration: { maxEntries: 3000, maxAgeSeconds: 60 * 60 * 24 * 180, purgeOnQuotaError: true },
|
|
|
|
|
cacheableResponse: { statuses: [0, 200] },
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-10-03 14:29:28 +02:00
|
|
|
{
|
|
|
|
|
urlPattern: /^https:\/\/server\.arcgisonline\.com\/.*/,
|
|
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
|
|
|
|
cacheName: 'sat-tiles',
|
2026-10-03 19:56:49 +02:00
|
|
|
expiration: { maxEntries: 1500, maxAgeSeconds: 60 * 60 * 24 * 60, purgeOnQuotaError: true },
|
2026-10-03 14:29:28 +02:00
|
|
|
cacheableResponse: { statuses: [0, 200] },
|
|
|
|
|
},
|
|
|
|
|
},
|
2026-10-03 13:33:50 +02:00
|
|
|
{
|
2026-10-03 19:56:49 +02:00
|
|
|
// photo assessment: the on-device AI runtime and model are large; once used online they work offline too
|
|
|
|
|
urlPattern: ({ url }: { url: URL }) => url.pathname.endsWith('.wasm') || /(^|\.)(huggingface\.co|hf\.co)$/.test(url.hostname),
|
2026-10-03 13:33:50 +02:00
|
|
|
handler: 'CacheFirst',
|
|
|
|
|
options: {
|
2026-10-03 19:56:49 +02:00
|
|
|
cacheName: 'ai-runtime',
|
|
|
|
|
expiration: { maxEntries: 40, purgeOnQuotaError: true },
|
2026-10-03 13:33:50 +02:00
|
|
|
cacheableResponse: { statuses: [0, 200] },
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
],
|
2026-10-03 19:14:41 +02:00
|
|
|
// ZTP Kraków serves GTFS-Realtime without CORS headers: `rt/*` is proxied for `pnpm dev` and `pnpm preview`.
|
|
|
|
|
// A static production host needs the same rule (e.g. nginx `location /rt/ { proxy_pass https://gtfs.ztp.krakow.pl/; }`).
|
|
|
|
|
server: { proxy: { '/rt': { target: 'https://gtfs.ztp.krakow.pl', changeOrigin: true, rewrite: (p) => p.replace(/^\/rt/, '') } } },
|
|
|
|
|
preview: { proxy: { '/rt': { target: 'https://gtfs.ztp.krakow.pl', changeOrigin: true, rewrite: (p) => p.replace(/^\/rt/, '') } } },
|
2026-10-03 13:33:50 +02:00
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
loadPaths: ['node_modules/@uswds/uswds/packages'],
|
|
|
|
|
quietDeps: true,
|
|
|
|
|
silenceDeprecations: ['import', 'mixed-decls', 'global-builtin', 'color-functions'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
test: { environment: 'node', include: ['src/**/*.test.ts'] },
|
|
|
|
|
});
|