From 0ef202f2df2ad096dde8f901d390bef3e08874d4 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Sat, 2 Jul 2022 17:59:03 +0200 Subject: [PATCH] feat: support debugging PWA in dev (#4853) * feat: support enabling pwa in dev * enable workbox debug * add prebuild script * fix lint --- .env.development | 9 ++++++++ package.json | 3 ++- public/index.html | 16 +++++++++++++ {src => public}/service-worker.js | 37 ++++++++++++++++++++++--------- scripts/prebuild.js | 20 +++++++++++++++++ src/serviceWorker.tsx | 6 ++++- 6 files changed, 78 insertions(+), 13 deletions(-) rename {src => public}/service-worker.js (68%) create mode 100644 scripts/prebuild.js diff --git a/.env.development b/.env.development index f04f0868..1a5fbda3 100644 --- a/.env.development +++ b/.env.development @@ -11,3 +11,12 @@ REACT_APP_WS_SERVER_URL=http://localhost:3002 REACT_APP_PORTAL_URL= REACT_APP_FIREBASE_CONFIG='{"apiKey":"AIzaSyCMkxA60XIW8KbqMYL7edC4qT5l4qHX2h8","authDomain":"excalidraw-oss-dev.firebaseapp.com","projectId":"excalidraw-oss-dev","storageBucket":"excalidraw-oss-dev.appspot.com","messagingSenderId":"664559512677","appId":"1:664559512677:web:a385181f2928d328a7aa8c"}' + +# put these in your .env.local, or make sure you don't commit! +# must be lowercase `true` when turned on +# +# whether to enable Service Workers in development +REACT_APP_DEV_ENABLE_SW= +# whether to disable live reload / HMR. Usuaully what you want to do when +# debugging Service Workers. +REACT_APP_DEV_DISABLE_LIVE_RELOAD= diff --git a/package.json b/package.json index 8f27edb9..e9aed502 100644 --- a/package.json +++ b/package.json @@ -94,7 +94,8 @@ "build:app:docker": "REACT_APP_DISABLE_SENTRY=true react-scripts build", "build:app": "REACT_APP_GIT_SHA=$VERCEL_GIT_COMMIT_SHA react-scripts build", "build:version": "node ./scripts/build-version.js", - "build": "yarn build:app && yarn build:version", + "build:prebuild": "node ./scripts/prebuild.js", + "build": "yarn build:prebuild && yarn build:app && yarn build:version", "eject": "react-scripts eject", "fix:code": "yarn test:code --fix", "fix:other": "yarn prettier --write", diff --git a/public/index.html b/public/index.html index 31e4ed56..0c576a29 100644 --- a/public/index.html +++ b/public/index.html @@ -98,6 +98,22 @@ /> + <% if (process.env.REACT_APP_DEV_DISABLE_LIVE_RELOAD === "true") { %> + + <% } %>