vite-pwa / vite-plugin-pwa

Zero-config PWA for Vite

Home Page:https://vite-pwa-org.netlify.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to generate sw.js with precaching after prerendering with vite-plugin-ssr

robotpapier opened this issue · comments

Hi,
I am using vite-plugin-pwa with vite-plugin-ssr
but it seems like the plugin generates the sw.js file with the precaching path before vite-plugin-ssr prerenders for production.
Resulting in my routes present in the sw.js and are not cached.

How can tel vite-plugin-pwa to generate the sw.js file after vite-plugin-ssr prerender ?

@robotpapier you should use transformManifest callback on workbox or injectManifest plugin option, add routes in that callback.

I'm not familiar with SSR Apps, I only use it on SSG: vite-ssg will execute twice the plugin, former on the vite lifecycle and later after vite-ssg finish build.

You can also check for example the script on docs when building using vitepress or check the sveltekit example. On sveltekit we have a similar porblem with the adapter configured, called after build, so we need to rebuild the pwa (when using static adapter).

Thanks for the hints, I'll have look!

@robotpapier how did it go?

@redbar0n Hi, I don't remember what I did with this plugin but now I use Sveltekit to pwa any pages I want using manifest files
and for the page I want to be a pwa I use svelte:head to load the manifest.json file
<svelte:head> <title>Page 1</title> <meta name="description" content="" /> <link rel="manifest" crossorigin="use-credentials" href="manifests/my_manifest.json" /> </svelte:head>