diff --git a/package.json b/package.json index 9557edef..ecce2539 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,5 @@ "vite-plugin-pwa": "^0.16.4", "vite-tsconfig-paths": "^4.0.7" }, - "types": "module", - "msw": { - "workerDirectory": "public" - } + "types": "module" } diff --git a/public/mockServiceWorker.js b/public/mockServiceWorker.js index 37c65a7a..d3d1a420 100644 --- a/public/mockServiceWorker.js +++ b/public/mockServiceWorker.js @@ -8,7 +8,7 @@ * - Please do NOT serve this file on production. */ -importScripts('./serviceWorker.js'); +importScripts('./sw.js'); const INTEGRITY_CHECKSUM = '3d6b9f06410d179a7f7404d4bf4c3c70'; const activeClientIds = new Set(); diff --git a/public/serviceWorker.js b/public/serviceWorker.js deleted file mode 100644 index 0165db76..00000000 --- a/public/serviceWorker.js +++ /dev/null @@ -1,3 +0,0 @@ -if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('./sw.js'); -} diff --git a/src/main.tsx b/src/main.tsx index 9e919241..d2c73824 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -9,6 +9,14 @@ import { worker } from 'src/mocks/browser'; import App from './App'; +if ('serviceWorker' in navigator) { + if (process.env.NODE_ENV === 'development') { + navigator.serviceWorker.register('/mockServiceWorker.js'); + } else { + navigator.serviceWorker.register('/sw.js'); + } +} + if (process.env.NODE_ENV === 'development') { worker.start(); }