fix: pwa cache

This commit is contained in:
hamster1963
2024-12-05 10:20:45 +08:00
parent 4032ff62a2
commit 9073fa6429
8 changed files with 139 additions and 3 deletions

View File

@@ -19,6 +19,7 @@ export default defineConfig({
base: "/",
define: {
"import.meta.env.VITE_GIT_HASH": JSON.stringify(getGitHash()),
"import.meta.env.VITE_APP_VERSION": JSON.stringify(process.env.npm_package_version || "1.0.0"),
},
plugins: [
react(),
@@ -50,8 +51,58 @@ export default defineConfig({
],
},
workbox: {
navigateFallbackDenylist: [/^\/dashboard/],
clientsClaim: true,
skipWaiting: true,
cleanupOutdatedCaches: true,
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: 60 * 60 * 24 * 365 // <== 365 days
},
cacheableResponse: {
statuses: [0, 200]
}
}
},
{
urlPattern: /^https:\/\/api\.nezha\.dev\/.*/i,
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
expiration: {
maxEntries: 100,
maxAgeSeconds: 60 * 5 // <== 5 minutes
},
cacheableResponse: {
statuses: [0, 200]
}
}
}
]
},
devOptions: {
enabled: true,
type: 'module'
}
}),
],
resolve: {