generate sw
This commit is contained in:
+1
-1
@@ -17,7 +17,7 @@ yarn.lock
|
||||
/playwright-report/
|
||||
/blob-report/
|
||||
/playwright/.cache/
|
||||
/scripts/
|
||||
/_scripts/
|
||||
/pb_data/
|
||||
/.tanstack/
|
||||
/dist/
|
||||
@@ -0,0 +1,73 @@
|
||||
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`,
|
||||
)
|
||||
Reference in New Issue
Block a user