urara icon indicating copy to clipboard operation
urara copied to clipboard

ServiceWorker doesn't work

Open kwaa opened this issue 1 year ago • 4 comments

ServiceWorker files are not automatically copied to ./build after updating to the latest versions of SvelteKit and Vite.

Progress tracking here, looks like need to wait for antfu/vite-plugin-pwa#327.

But I might be able to create a temporary solution until it updates?

kwaa avatar Sep 02 '22 08:09 kwaa

@kwaa you can check this repo, I just hack the vite-plugin-pwa with a local copy of the plugin using the linked PR: https://github.com/userquin/pwa-sveltekit-vite

EDIT: you will need to download the tgz to your local and install it as a dev dependency: pnpm remove -D vite-plugin-pwa && pnpm add -D ./vite-plugin-pwa-0.12.3.tgz, then, modify your vite.config.js using th eone in the repo.

userquin avatar Sep 04 '22 14:09 userquin

@kwaa you can check this repo, I just hack the vite-plugin-pwa with a local copy of the plugin using the linked PR: https://github.com/userquin/pwa-sveltekit-vite

Oh, thanks! I noticed that, except the code was a bit hard to read.

kwaa avatar Sep 04 '22 14:09 kwaa

the vite plugin pwa is built using Vite 2, so we just get the 3 plugins destructuring the array: we only need to register a new one for the pwa build plugin using the new Vite 3/ Rollup sequential hook and change the order to just run before the kit one (closeBundle hook in kit plugin will run the adapter, and so, we only need to run it before the kit one with the sequential enabled)

userquin avatar Sep 04 '22 14:09 userquin

@kwaa you have some reference for Vite, Rollup and Kit in the repo README file

userquin avatar Sep 04 '22 14:09 userquin