UNPKG

@vite-pwa/create-pwa

Version:
28 lines (21 loc) 758 B
/// <reference types="vite/client" /> /// <reference lib="webworker" /> import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from 'workbox-precaching' import { clientsClaim } from 'workbox-core' import { NavigationRoute, registerRoute } from 'workbox-routing' declare let self: ServiceWorkerGlobalScope // self.__WB_MANIFEST is the default injection point precacheAndRoute(self.__WB_MANIFEST) // clean old assets cleanupOutdatedCaches() let allowlist: RegExp[] | undefined // in dev mode, we disable precaching to avoid caching issues if (import.meta.env.DEV) allowlist = [/^\/$/] // to allow work offline registerRoute(new NavigationRoute( createHandlerBoundToURL('/'), { allowlist }, )) self.skipWaiting() clientsClaim()