1234567891011121314151617181920212223242526272829303132333435363738 |
- import { clientsClaim } from 'workbox-core'
- import { cleanupOutdatedCaches, precacheAndRoute } from 'workbox-precaching'
- declare let self: ServiceWorkerGlobalScope
- self.skipWaiting()
- self.addEventListener('message', (event) => {
- if (event.data && event.data.type === 'SKIP_WAITING') self.skipWaiting()
- })
- clientsClaim()
- cleanupOutdatedCaches()
- if (import.meta.env.MODE !== 'development') {
- precacheAndRoute(
- self.__WB_MANIFEST.map((entry) => {
- const base = import.meta.env.VITE_RUBY_PUBLIC_OUTPUT_DIR
-
-
-
-
- if (typeof entry === 'string') return `../${base}/${entry}`
- return { ...entry, url: `../${base}/${entry.url}` }
- }),
- )
- }
- if (import.meta.env.MODE === 'development') {
- console.groupCollapsed("Service worker doesn't precache in development mode")
- self.__WB_MANIFEST.forEach((entry) =>
- console.log(typeof entry === 'string' ? entry : entry.url),
- )
- console.groupEnd()
- precacheAndRoute([])
- }
|