vite-pwa / vite-plugin-pwa

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

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

Open robthepaper opened 2 years ago

robthepaper commented 2 years ago

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 ?

userquin commented 2 years ago

@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).

userquin commented 2 years ago

@robotpapier check this issue https://github.com/antfu/vitesse/issues/159

robthepaper commented 2 years ago

Thanks for the hints, I'll have look!

redbar0n commented 9 months ago

@robotpapier how did it go?

robthepaper commented 8 months ago

@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 to load the manifest.json file `

Page 1
<meta name="description" content="" />
<link rel="manifest" crossorigin="use-credentials" href="manifests/my_manifest.json" />

</svelte:head>`