mischnic / parcel-plugin-sw-cache

📦👷 Parcel plugin for caching using a service worker
https://npm.im/parcel-plugin-sw-cache
MIT License
47 stars 6 forks source link

publicURL issue when using SPA in Firebase. #6

Closed supertopoz closed 6 years ago

supertopoz commented 6 years ago

Currently the navigatorFallback for the workbox looks like this:

workbox.generateSW(
                Object.assign({
                    globDirectory: outDir,
                    globPatterns: ['**\/*.{html,js,css,jpg,png}'],
                    swDest: swDest,
                    navigateFallback: publicURL + "/index.html",
                    clientsClaim: true,
                    skipWaiting: true,
                    "templatedUrls": {
                        "/": ["index.html"]
                    }

This can cause an issue with when the publicURL is equal to "/". The issue is that the generated service worker output sets the the workbox.routing.registerNavigatorRoute to look like this:

workbox.routing.registerNavigationRoute("//index.html");

As a result I have to change the code for the navigateFallback to be like this.

navigateFallback: publicURL + "index.html",

If I don't do this deployment to Firebase fails when the front end routes are reloaded. ideally the registerNavigationRoute should look like this when the service worker is created.

workbox.routing.registerNavigationRoute("/index.html");
mischnic commented 6 years ago

Thank you!

Fixed by #7

mischnic commented 6 years ago

Fixed in v0.2.3