I am using create-react-app 4 and the cra-template-pwa (source)
By default, it looks like the service-worker is only used in production builds:
export function register(config) {
if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) {
That's a problem for me since building the production build takes a long time, hence I would like to register the service-worker while dev builds too.
In order to get that result I removed the check process.env.NODE_ENV === 'production' and also another isLocalhost check.
Now, even the debug build is trying to load the www.example.com/service-worker.js, just as I hoped.
The problem now is, this file is inside src. Which makes sense since it is using imports as you can see here. But because of this, the file itself is not accessible from the webbrowser and therefore www.example.com/service-worker.js is for sure unreachable.
Copying the file into public does not work either
Uncaught SyntaxError: Cannot use import statement outside a module
I fear I haven't really understood which part belongs to JS, which one to NodeJS, which one to reactjs and which one to CRA.
So my question now is:
Is there a way to get the "path" of the "translated" service-worker.js (after imports,..)?