Skip to content

Installing the mockServiceWorker.js file on a host app #2382

Answered by kettanaito
daraclare asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @daraclare. Thank you for your kind words.

You can get the worker script to your users by generating it via the MSW CLI:

npx msw init <PUBLIC_DIR>

You can learn more about the init command here.

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 the postinstall script. Just design what makes sense to your consumers, and keep security in mind (it's generally good…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kettanaito
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2381 on December 06, 2024 11:27.