import { readFileSync } from 'node:fs'; import { svelte } from '@sveltejs/vite-plugin-svelte'; import { defineConfig } from 'vite'; import { VitePWA } from 'vite-plugin-pwa'; const { version: appVersion } = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf8')); const appVersionAsset = { name: 'pardis-app-version', generateBundle() { this.emitFile({ type: 'asset', fileName: 'app-version.json', source: JSON.stringify({ version: appVersion }), }); }, }; export default defineConfig({ server: { host: '0.0.0.0', proxy: { '/api/sync': 'http://127.0.0.1:3001' }, }, preview: { proxy: { '/api/sync': 'http://127.0.0.1:3001' } }, plugins: [ appVersionAsset, svelte(), VitePWA({ // Never `autoUpdate`: a worker swap mid-day reloads the page under the // user's hands. The app decides when to apply an update (see // src/lib/updates.svelte.js) and only offers it while no day is running. registerType: 'prompt', pwaAssets: { image: 'public/icon.svg', }, manifest: { name: 'Pardis - suivi des heures', short_name: 'Pardis', description: "Suivi hors ligne des heures de chantier.", lang: 'fr', dir: 'ltr', start_url: '/', scope: '/', display: 'standalone', orientation: 'portrait', background_color: '#ffffff', theme_color: '#0047b3', categories: ['productivity', 'utilities'], }, workbox: { // The whole app is a handful of files; precache it all so a cold start // offline is identical to a warm one. // // `webmanifest` is deliberately NOT in this list: the plugin injects its // own manifest entry, and a glob that also matches it produces two // precache entries for the same URL with different revisions. Workbox // rejects conflicting entries, the install handler throws, and nothing // gets cached at all — the app silently stops working offline. globPatterns: ['**/*.{js,css,html,svg,png,ico,ttf,otf,txt}'], cleanupOutdatedCaches: true, clientsClaim: false, }, }), ], test: { include: ['src/**/*.test.js', 'server/**/*.test.js'], environment: 'node', }, });