Installing the mockServiceWorker.js file on a host app #2382
-
Hi, thanks for msw, it's a real great library, very easy to get up and running 😀 We have a library which is imported into a host app. We want to use MSW to provide a sandbox environment for our users. This is just to let the user to get a POC running using our library without hitting our internal API. However, we are having an issue as the host app does not contain the mockServiceWorker.js file, as it is unaware of anything contained in our library. Is there a way to install this file from our library? Or a better way to get this working for our users? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hi, @daraclare. Thank you for your kind words. You can get the worker script to your users by generating it via the MSW CLI:
I recommend adding You are free to design a better experience if you want to, based on the context your library executes in. For example, you can ship All of this is relevant for the browser usage only. The worker isn't needed for the Node.js usage. |
Beta Was this translation helpful? Give feedback.
Hi, @daraclare. Thank you for your kind words.
You can get the worker script to your users by generating it via the MSW CLI:
I recommend adding
msw
as a dependency to your library and asking your consumers to run this command to copy the worker script to their public directories.You are free to design a better experience if you want to, based on the context your library executes in. For example, you can ship
mockServiceWorker.js
as a part of your library's assets, and then copy the script during thepostinstall
script. Just design what makes sense to your consumers, and keep security in mind (it's generally good…