Open houtan-rocky opened 7 months ago
you can try adding an env var when testing, then use it to disable PWA.
@userquin Isn't there a way to not unregister other SW's? If you can show me the direction I might be able to help with that.
using generateSW
I guess no, can you provide a minimal reproduction? Maybe I can check what's happening...
If you use a custom service worker you can import mockServiceWorker.js
script, but since you use generateSW
strategy there is no way to include that script (iirc you can only have one sw per scope).
check registering the msw sw in another scope: check last entry here https://stackoverflow.com/questions/77292614/vite-pwa-not-able-to-register-mock-service-worker-in-parallel-with-other-servi
@houtan-rocky can you try adding a custom sw importing this module on it? It is a custom msw/mockServiceWorker.js
registering logic when import.meta.vitest
is present (if not using Vitest you will need to add some entry to Vite define
or use some env variable, the code shouldn't be included in production build).
You can use JavaScript
, just remove all types from the module.
Then in your custom sw.ts
import the mock-sw.ts
:
import './mock-sw.ts'`
For example, using @vite-pwa/create-pwa
with inject manifest (the prompt-sw.ts
should be sw.ts
):
Issue: when VitePWA is activated, it conflicts with my MSWJS mock service worker and apparently removes Mock Service Worker from my application.
steps to reproduce: Install React-App through vite installation
install and configure vite-plugin-pwa:
Behaviour: the vite-pwa extension, when enabled, removes the mock service worker, and the below error is shown in the console:
Expected: Extension to not conflict and remove the mock service worker