vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite
https://vite-pwa-org.netlify.app/
MIT License
3.22k stars 211 forks source link

How do I add support for plugins ? Specially statusPlugin #736

Open Kuro091 opened 3 months ago

Kuro091 commented 3 months ago

https://developer.chrome.com/docs/workbox/using-plugins

Question is how do I translate this piece of code: https://github.com/GoogleChrome/workbox/issues/2599#issuecomment-900304969

into vite pwa config without having to assign a custom base service-worker

which involves having a statusPlugin inside NetworkOnly constructor ?

userquin commented 3 months ago

Check https://github.com/vite-pwa/sveltekit/issues/65#issuecomment-1734213190

For background sync you can use backgroundSync entry, something like this (not tested):

             runtimeCaching: [{
                urlPattern: /\/api\/.*\/*.json/,
                handler: 'NetworkFirst', // <== or NetworkOnly: if so update the options properly
                method: 'POST',
                options: {
                    cacheName: 'api-cache',
                    expiration: {
                      maxEntries: 5,
                      maxAgeSeconds: 60,
                    },
                    backgroundSync: {
                      name: 'api-queue',
                      options: {
                          maxRetentionTime: 60 * 60,
                      },
                    },
                },
            }]