diff --git a/.changeset/slow-ties-vanish.md b/.changeset/slow-ties-vanish.md new file mode 100644 index 000000000..90d1eb5a6 --- /dev/null +++ b/.changeset/slow-ties-vanish.md @@ -0,0 +1,5 @@ +--- +'preact-cli': patch +--- + +Fix path normalization for service worker. http://example.comsw.js -> http://example.com/sw.js diff --git a/packages/cli/lib/lib/entry.js b/packages/cli/lib/lib/entry.js index 92e2d616f..9d925e26b 100644 --- a/packages/cli/lib/lib/entry.js +++ b/packages/cli/lib/lib/entry.js @@ -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') ); }