Open leonhma opened 2 years ago
@userquin has been working to make https://github.com/antfu/vite-plugin-pwa work with SvelteKit and has it pretty well figured out. There are two known issues: https://github.com/sveltejs/kit/issues/5308 and https://github.com/sveltejs/kit/issues/5306. I have a PR out to fix the first one already
Is there a reason you don't just contribute to vite-plugin-pwa
instead of writing your own plugin?
Thank you. I'll take a look at vite-plugin-pwa.
Originally, when looking for how to make my project into a pwa, if found this too, but as far as I understand, this generates a service worker for you. I want to have a bit more control over the service worker, so my idea was to handle the manifest and the icons and apple splash screens via the plugin, and use sveltekit's sw.ts
as the service worker. Also, it tries to be zero-config for sveltekit specifically.
I just took some time to look at antfu's repo, and the strategy they are using, is just copying the service worker and manifest into the build output. IMO it would be much better to make use of vite's/rollup's emitFile
in order to somewhat reliably inject those files (for different adapters).
As I see it, vite plugins at the moment are kinda broken, which #5306 seeks to fix.
@leonhma we've changed it since the sveltekit plugin was setting the webmanifest file into the immutable folder, originally we had the output pointing to the .sveltekit folder, check the history
@leonhma I'm digging into why UnoCSS doesn't scan app.html in a SvelteKit project but it does just fine in a vite-svelte project. I've made minimal repros of the transformIndexHtml
vite plugin hook working in a vite-svelte project and not working in SvelteKit project.
Somehow vite-pwa is using this hook in SvelteKit though so it looks like there is some way to get a Vite plugin to recognize app.html
as the file to pass to transformIndexHtml
. I suspect this is happening somewhere in the
@vite-pwa/sveltekit config.ts file but haven't had a chance to fully understand that code.
Is there a maintainer who can help explain how to point Vite's transformIndexHtml
hook to process SvelteKit's app.html
file?
@leonhma I have the exact same issue with you, and trying this.emitFile
in buildStart
now seems to work
Describe the bug
I am currently writing a plugin that is supposed to generate the manifest and images needed for a pwa, and the user can bring their own service worker, in order to be as customisable as possible. The icons are resized into a bunch of different variants and then emitted using
emitFiles
. Prior function doesn't give any errors and returns an resolveId that resolves to a valid URL. Everything seems to work, but in the end, nothing turns up in the build output, and when requesting_app/manifest.webmanifest
or any of the images the server responds with the 404 page.I have also tested this using a plain vue3 app, and it works flawlessly.
Reproduction
Since I don't have the plugin published, you will have to also clone https://github.com/leonhma/vite-plugin-webmanifest.git and use
yarn link
. Here is the original relevant plugin code:Here's a URL to the repo for reproduction: https://github.com/leonhma/repro-sveltekit-vite-emitfiles.git
Logs
System Info
Severity
blocking an upgrade
Additional Information
No response