Files
flxn-app/scripts/generate-sw.mjs
T
yohlo e9040bb02f
CI/CD Pipeline / Build and Push App Docker Image (push) Successful in 1m38s
CI/CD Pipeline / Build and Push PocketBase Docker Image (push) Successful in 8s
CI/CD Pipeline / Deploy to Kubernetes (push) Successful in 8m24s
generate sw
2026-07-12 21:51:48 -07:00

73 lines
1.7 KiB
JavaScript

import { generateSW } from 'workbox-build'
const ONE_YEAR = 60 * 60 * 24 * 365
const THIRTY_DAYS = 60 * 60 * 24 * 30
const { count, size, warnings } = await generateSW({
swDest: 'dist/client/sw.js',
globDirectory: 'dist/client',
globPatterns: [
'assets/**/*.{js,css}',
'favicon*.{ico,png}',
'apple-touch-icon.png',
'icon-192x192.png',
'icon-512x512.png',
'site.webmanifest',
'styles.css',
],
navigateFallback: null,
skipWaiting: true,
clientsClaim: true,
cleanupOutdatedCaches: true,
sourcemap: false,
runtimeCaching: [
{
urlPattern: ({ url, request }) =>
url.origin === self.location.origin && request.destination === 'image',
handler: 'CacheFirst',
options: {
cacheName: 'images-cache',
expiration: {
maxEntries: 60,
maxAgeSeconds: THIRTY_DAYS,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: /^https:\/\/fonts\.googleapis\.com\/.*/i,
handler: 'StaleWhileRevalidate',
options: {
cacheName: 'google-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: ONE_YEAR,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
{
urlPattern: /^https:\/\/fonts\.gstatic\.com\/.*/i,
handler: 'CacheFirst',
options: {
cacheName: 'gstatic-fonts-cache',
expiration: {
maxEntries: 10,
maxAgeSeconds: ONE_YEAR,
},
cacheableResponse: {
statuses: [0, 200],
},
},
},
],
})
for (const warning of warnings) console.warn(warning)
console.log(
`sw.js generated: precached ${count} files, ${(size / 1024).toFixed(1)} KiB`,
)