From 5e4cbc1ef59c9b06d0336465325ce8ae32c107dd Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Wed, 23 Aug 2023 23:27:24 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20MSW=20=EC=84=A4=EC=A0=95=20=EB=A1=A4?= =?UTF-8?q?=EB=B0=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/mockServiceWorker.js | 2 +- public/serviceWorker.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 public/serviceWorker.js 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'); -} From 46565870fe6c8cf472b7e2307a8b5a59a4f8777b Mon Sep 17 00:00:00 2001 From: Lee sang Yeop Date: Wed, 23 Aug 2023 23:27:42 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Fix:=20=EA=B0=9C=EB=B0=9C=ED=99=98=EA=B2=BD?= =?UTF-8?q?=EC=97=90=EB=A7=8C=20MSW=EA=B0=80=20=EC=84=9C=EB=B9=84=EC=8A=A4?= =?UTF-8?q?=EC=9B=8C=EC=BB=A4=EC=97=90=20=EB=93=B1=EB=A1=9D=EB=90=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +---- src/main.tsx | 8 ++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) 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/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(); }