If I shouldn't serve mockServiceWorker.js in production, then why "public" directory? #464
-
The site doesn't seem to mention anything about this warning in the script:
All examples include copying the script to "public", but this location will make it to production. Or is serving If I'm indeed supposed to keep it away from production, and the script will be installed in "public" upon installing |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi, @silvenon. We are going a bit too harsh on the warning so to make it clear you don't use MSW in production. In practice, you are right, just placing the worker script in a public directory will normally mean that it's also there in production. I trust it to your build setup to remove it when needed, e.g. - name: build
run: npm run build && rm ./public/mockServiceWorker.js Maybe we should be more explicit about this. The problem with mentioning this is that there are multiple ways to solve this and, ultimately, you should know best. So it's hard to recommend "one size fits all" approach. Serving the worker script in production without registering it does nothing. It doesn't affect your site and your app must never load it (that is a hard must). |
Beta Was this translation helpful? Give feedback.
Hi, @silvenon.
We are going a bit too harsh on the warning so to make it clear you don't use MSW in production. In practice, you are right, just placing the worker script in a public directory will normally mean that it's also there in production. I trust it to your build setup to remove it when needed, e.g.
Maybe we should be more explicit about this. The problem with mentioning this is that there are multiple ways to solve this and, ultimately, you should know best. So it's hard to recommend "one size fits all" approach.
Serving the worker script in production without registering it does nothing. It doesn't affec…