- Powershell
npm run build; serve -s build -p 3005
- Open
http://localhost:3005
in browser - Install as App
- Edit some files, then re-build
npm run build; serve -s build -p 3005
- Watch App auto-updates itself
- For demo purpose, the update check is done every 10 seconds
- see Video pwa-auto-update.mp4
- Auto updater hinges on the addition of the following
console.log
statement inservice-worker.ts
-
// Any other custom service worker logic can go here. const buildVersion = (): void => { // eslint-disable-next-line no-console console.log("Build version: ", process.env.REACT_APP_BUILD_VERSION); }; buildVersion();
.env.REACT_APP_BUILD_VERSION
is updated automatically on everynpm run build
, see.\package.json
-
- The tricky bit is when this auto-updater code is added AFTER an app is installed
- Timeline:
- Build app WITHOUT auto-updater, called
app-v0
- Install & run
app-v0
- Edit some files, add auto-updater bit, rebuild as
app-v1
app-v0
is still running, restart itapp-v0
detects that an updateapp-v1
is available, downloads and installsapp-v1
- Close
app-v0
to activateapp-v1
- Re-open app,
app-v1
runs now - auto-updater should work as expected now
- Close
- Build app WITHOUT auto-updater, called
- Timeline: