Skip to content

Commit

Permalink
fix: Correcting path normalization for service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Nov 20, 2020
1 parent 67fafc8 commit ba2a41d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-ties-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Fix path normalization for service worker. http://example.comsw.js -> http://example.com/sw.js
10 changes: 7 additions & 3 deletions packages/cli/lib/lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@ if (process.env.NODE_ENV === 'development') {
// only add a debug sw if webpack service worker is not requested.
if (process.env.ADD_SW === undefined && 'serviceWorker' in navigator) {
// eslint-disable-next-line no-undef
navigator.serviceWorker.register(__webpack_public_path__ + 'sw-debug.js');
navigator.serviceWorker.register(
normalizeURL(__webpack_public_path__) + 'sw-debug.js'
);
} else if (process.env.ADD_SW && 'serviceWorker' in navigator) {
// eslint-disable-next-line no-undef
navigator.serviceWorker.register(
__webpack_public_path__ + (process.env.ES_BUILD ? 'sw-esm.js' : 'sw.js')
normalizeURL(__webpack_public_path__) +
(process.env.ES_BUILD ? 'sw-esm.js' : 'sw.js')
);
}
} else if (process.env.ADD_SW && 'serviceWorker' in navigator) {
// eslint-disable-next-line no-undef
navigator.serviceWorker.register(
__webpack_public_path__ + (process.env.ES_BUILD ? 'sw-esm.js' : 'sw.js')
normalizeURL(__webpack_public_path__) +
(process.env.ES_BUILD ? 'sw-esm.js' : 'sw.js')
);
}

Expand Down

0 comments on commit ba2a41d

Please sign in to comment.