Mobile-first PWA: groups via key-in-fragment links, encrypted outbox and sync over SSE, all split modes, currencies with ECB rate prefill, photos, comments, history and rewind, stats, recurring expenses, CSV and backup, EN/CS, dark/light theme, Web Push decrypted in the service worker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013FYo6JSV1fDU1fm3LU77iF
35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
// Second build step: the service worker, as one classic script at /sw.js
|
|
// (module service workers aren't supported everywhere yet). It precaches
|
|
// whatever the first step put in dist/, so this must run after it.
|
|
import { createHash } from 'node:crypto';
|
|
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
import { join, relative } from 'node:path';
|
|
import { defineConfig } from 'vite';
|
|
|
|
const dist = join(import.meta.dirname, 'dist');
|
|
|
|
function listFiles(dir: string): string[] {
|
|
return readdirSync(dir).flatMap((f) => {
|
|
const p = join(dir, f);
|
|
return statSync(p).isDirectory() ? listFiles(p) : [p];
|
|
});
|
|
}
|
|
|
|
const files = listFiles(dist)
|
|
.map((p) => '/' + relative(dist, p).split('\\').join('/'))
|
|
.filter((p) => p !== '/sw.js' && !p.endsWith('.map'));
|
|
const hash = createHash('sha256');
|
|
for (const f of files.sort()) hash.update(f).update(readFileSync(join(dist, f)));
|
|
|
|
export default defineConfig({
|
|
define: {
|
|
__PRECACHE__: JSON.stringify(files),
|
|
__VERSION__: JSON.stringify(hash.digest('hex').slice(0, 12)),
|
|
},
|
|
build: {
|
|
outDir: 'dist',
|
|
emptyOutDir: false,
|
|
target: 'es2022',
|
|
lib: { entry: 'src/sw.ts', formats: ['iife'], name: 'sw', fileName: () => 'sw.js' },
|
|
},
|
|
});
|