Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robotpapier opened this issue Apr 5, 2022 · 5 comments

Comments

@robotpapier
Copy link

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
Copy link
Member

userquin commented Apr 5, 2022

@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
Copy link
Member

userquin commented Apr 5, 2022

@robotpapier check this issue antfu-collective/vitesse#159

@robotpapier
Copy link
Author

Thanks for the hints, I'll have look!

@redbar0n
Copy link

@robotpapier how did it go?

@robotpapier
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants