Skip to content

Commit e568ba2

Browse files
RISCfutureclaude
andcommitted
Add vite-plugin-pwa for offline support and auto-update
Generates a Workbox service worker that precaches the app shell. Eliminates the chunk-staleness race for users with stale HTML after a deploy and makes the app installable / offline-capable. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9949d44 commit e568ba2

3 files changed

Lines changed: 2588 additions & 194 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"typescript-eslint": "^8.58.0",
6969
"vite": "^8.0.2",
7070
"vite-plugin-csp-guard": "^3.0.0",
71+
"vite-plugin-pwa": "^1.2.0",
7172
"vite-plugin-vue-devtools": "^8.1.1",
7273
"vitest": "^4.1.1",
7374
"vue-eslint-parser": "^10.4.0",

vite.config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { fileURLToPath, URL } from 'node:url'
33
import { defineConfig } from 'vite'
44
import vue from '@vitejs/plugin-vue'
55
import vueDevTools from 'vite-plugin-vue-devtools'
6+
import { VitePWA } from 'vite-plugin-pwa'
67

78
// https://vite.dev/config/
89
export default defineConfig(async ({ command }) => {
@@ -36,8 +37,25 @@ export default defineConfig(async ({ command }) => {
3637
}
3738

3839
return {
39-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
40-
plugins: [vue(), vueDevTools({ launchEditor: 'rubymine' }), cspPlugin as any].filter(Boolean),
40+
plugins: [
41+
vue(),
42+
vueDevTools({ launchEditor: 'rubymine' }),
43+
VitePWA({
44+
registerType: 'autoUpdate',
45+
manifest: false,
46+
injectRegister: 'script',
47+
workbox: {
48+
globPatterns: ['**/*.{js,css,html,svg,png,ico,webmanifest,woff,woff2}'],
49+
navigateFallback: 'index.html',
50+
navigateFallbackDenylist: [/^\/api/, /\.map$/],
51+
cleanupOutdatedCaches: true,
52+
clientsClaim: true,
53+
skipWaiting: true,
54+
},
55+
}),
56+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
57+
cspPlugin as any,
58+
].filter(Boolean),
4159
resolve: {
4260
alias: {
4361
'@': fileURLToPath(new URL('./src', import.meta.url)),

0 commit comments

Comments
 (0)