This commit is contained in:
seb
2026-10-05 08:31:13 +02:00
parent 4d653304cd
commit 8010436157
5 changed files with 295 additions and 151 deletions

View File

@@ -289,8 +289,13 @@ export default defineConfig(({ command }) => ({
...(command === 'build'
? [
VitePWA({
// autoUpdate: the SW calls clientsClaim()/skipWaiting() itself, so a
// new build takes over every open tab on its own.
registerType: 'autoUpdate',
injectRegister: 'auto',
// Registration is done explicitly in src/main.jsx via
// `virtual:pwa-register` with `immediate: true`; that is what makes
// the *page* reload (a bare injected script only swaps the SW).
injectRegister: false,
manifest: {
id: '/',
name: 'Dashfront',
@@ -320,6 +325,13 @@ export default defineConfig(({ command }) => ({
],
},
workbox: {
// NOTE: vite-plugin-pwa only auto-sets these two when
// injectRegister === 'auto'. Because we register manually in
// src/main.jsx (injectRegister: false), they must be explicit —
// otherwise a new SW waits forever behind the old one and no tab
// is ever claimed.
skipWaiting: true,
clientsClaim: true,
globPatterns: ['**/*.{js,css,html,ico,png,svg,webmanifest,woff2}'],
globIgnores: ['**/*.wasm'],
navigateFallback: 'index.html',
@@ -327,7 +339,19 @@ export default defineConfig(({ command }) => ({
},
}),
]
: []),
: [
{
name: 'virtual-pwa-register-stub',
resolveId(id) {
if (id === 'virtual:pwa-register') return '\0virtual:pwa-register';
},
load(id) {
if (id === '\0virtual:pwa-register') {
return 'export function registerSW() { return () => {}; }';
}
},
},
]),
],
server: sharedServer,
preview: sharedServer,