From 59007f5973fa50d20df4801d5f2131883301c6db Mon Sep 17 00:00:00 2001 From: Markus Thielker Date: Tue, 24 Dec 2024 12:49:47 +0100 Subject: [PATCH] N-FIN-83: fix serwist configuration --- src/app/service-worker.ts | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/app/service-worker.ts b/src/app/service-worker.ts index f68e452..82b4457 100644 --- a/src/app/service-worker.ts +++ b/src/app/service-worker.ts @@ -1,15 +1,46 @@ -import { defaultCache } from '@serwist/next/browser'; import type { PrecacheEntry } from '@serwist/precaching'; -import { installSerwist } from '@serwist/sw'; +import { defaultCache } from '@serwist/next/worker'; +import { Serwist, SerwistGlobalConfig } from 'serwist'; declare const self: ServiceWorkerGlobalScope & { __SW_MANIFEST: (PrecacheEntry | string)[] | undefined; }; -installSerwist({ +declare global { + interface WorkerGlobalScope extends SerwistGlobalConfig { + // Change this attribute's name to your \`injectionPoint\`. + // \`injectionPoint\` is an InjectManifest option. + // See https://serwist.pages.dev/docs/build/configuring + __SW_MANIFEST: (PrecacheEntry | string)[] | undefined; + } +} + +const serwist = new Serwist({ + // A list of URLs that should be cached. Usually, you don't generate + // this list yourself; rather, you'd rely on a Serwist build tool/your framework + // to do it for you. In this example, it is generated by \`@serwist/vite\`. precacheEntries: self.__SW_MANIFEST, + // Options to customize how Serwist precaches the URLs. + precacheOptions: { + // Whether outdated caches should be removed. + cleanupOutdatedCaches: true, + concurrency: 10, + ignoreURLParametersMatching: [], + }, + // Whether the service worker should skip waiting and become the active one. skipWaiting: true, + // Whether the service worker should claim any currently available clients. clientsClaim: true, + // Whether navigation preloading should be used. navigationPreload: true, + // Whether Serwist should log in development mode. + disableDevLogs: true, + // A list of runtime caching entries. When a request is made and its URL match + // any of the entries, the response to it will be cached according to the matching + // entry's \`handler\`. This does not apply to precached URLs. runtimeCaching: defaultCache, + // Other options... + // See https://serwist.pages.dev/docs/serwist/core/serwist }); + +serwist.addEventListeners();