vite-plugin-pwa icon indicating copy to clipboard operation
vite-plugin-pwa copied to clipboard

feat: `SvelteKit Vite Plugin` support

Open userquin opened this issue 3 years ago • 11 comments

This PR also fix the sveltekit-pwa example.

~~supersedes #319 (ESM part)~~: ESM already included in another PR

closes #324

userquin avatar Jul 07 '22 23:07 userquin

Deploy Preview for vite-plugin-pwa ready!

Name Link
Latest commit f7927c22b89470ff1cf9acf621cf160e79163904
Latest deploy log https://app.netlify.com/sites/vite-plugin-pwa/deploys/62dc26193ed0fa0008711f03
Deploy Preview https://deploy-preview-327--vite-plugin-pwa.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Jul 07 '22 23:07 netlify[bot]

woohoo! so nice you were able to remove pwa.js!

Still need the sequential, but yeah, finally removed.

@antfu: it seems that VitePress finally included the buildEnd hook!, we can remove it also from the docs (awaiting new release).

userquin avatar Jul 13 '22 15:07 userquin

@benmccann @antfu I'll remove the ESM support here and make another separate PR, it can take a while to fix the sequential in Vite.

I'll include also the manifestTransform here for SvelteKit integration.

userquin avatar Jul 13 '22 19:07 userquin

I would merge what you have here for SvelteKit support. It's a big improvement. Adding a new hook to Vite may take quite awhile, especially since I'm not even sure what API to propose yet, so I wouldn't block on it

benmccann avatar Jul 13 '22 19:07 benmccann

ok, requesting review from Anthony ~~(will not work)~~

userquin avatar Jul 13 '22 19:07 userquin

To be honest, I am not sure about having hard-code SvelteKit support directly in this plugin - it could couple with Svelte and make the maintenance harder. I would suggest this either be done on SvelteKit side, or have a higher level plugin like sveltekit-plugin-pwa or vite-plugin-sveltekit-pwa on top of this plugin. If we go with that, I think we are happy to expose the necessary APIs for it to manipulate the config, etc. /cc @benmccann

antfu avatar Jul 15 '22 00:07 antfu

@benmccann we're going to wait https://github.com/sveltejs/kit/issues/5306 to avoid using the sequential plugin

userquin avatar Jul 18 '22 22:07 userquin

To be honest, I am not sure about having hard-code SvelteKit support directly in this plugin - it could couple with Svelte and make the maintenance harder. I would suggest this either be done on SvelteKit side, or have a higher level plugin like sveltekit-plugin-pwa or vite-plugin-sveltekit-pwa on top of this plugin. If we go with that, I think we are happy to expose the necessary APIs for it to manipulate the config, etc. /cc @benmccann

@antfu, it looks like there are two big items here:

  • integrations/sveltekit/plugin.ts is dealing with the fact that SSR requires multiple builds (https://github.com/vitejs/vite/issues/5936) and we have a SvelteKit bug (https://github.com/sveltejs/kit/issues/5306). With any luck, fixing that SvelteKit issue will allow us to drop this file
  • integrations/sveltekit/config.ts is primarily dealing with figuring out what URLs are in the application from layout of the prerendered (i.e. SSG-generated) files on disk. It would be nice if we could make that more generic and robust

We've had a lot of requests to create a sitemap.xml (https://github.com/sveltejs/kit/issues/1142). If we did that, then you could utilize that file, which would remove the need to understand the directory layout of SvelteKit's output and could be shared by all frameworks

benmccann avatar Jul 20 '22 22:07 benmccann

@antfu this PR is ready to review, I only need to change the docs: we can include this PR in the next release (0.12.4).

It is working, but we need to await SvelteKit to fix the process.exit in the closeBundle hook: we've included a sequential plugin hook that sleeps 1sc and then call pwa closeBundle hook and finally call kit closeBundle hook.

I'll include a warning in the docs about process.exit problem.

Once SvelteKit fix the process.exit, we only need to remove the sequential plugin and we're done: the pwa build plugin will be always called after kit plugin since it has enforce post, and so, we don't need to change anything.

https://github.com/sveltejs/kit/issues/5306

userquin avatar Jul 22 '22 10:07 userquin

@benmccann removed the sequential plugin (adapter plugin from integrations), awaiting merging https://github.com/sveltejs/kit/pull/5678 and new kit release: rn the sveltekit example stops working, we only need the new version

userquin avatar Jul 23 '22 10:07 userquin

Maybe this can help 🤞 : https://github.com/vitejs/vite/pull/9326

userquin avatar Jul 23 '22 23:07 userquin

included in the new integration repo

userquin avatar Oct 03 '22 16:10 userquin