pwa-module icon indicating copy to clipboard operation
pwa-module copied to clipboard

Self-hosted Workbox?

Open SoftCreatR opened this issue 3 years ago • 2 comments

I'm relatively new to Nuxt, and stumbled across this module, which works just fine so far.

However, for reasons (GDPR, ...) I would like to self-host Workbox, rather than using a remote CDN.

I found this documentation: https://pwa.nuxtjs.org/workbox#workboxurl

So I've installed the workbox-cdn package. But now, I'm stuck. What I tried was:

  pwa: {
    workbox: {
      workboxURL: `~/node_modules/workbox-cdn/workbox/workbox-sw.js?${Date.now()}`
    },
  },

But that doesn't work (tries to call http://localhost:3000/~/node_modules/workbox-cdn/workbox/workbox-sw.js?1645685080049). Do I need to copy the contents of ~/node_modules/workbox-cdn/workbox to the static directory? Or is there another/more official way?

SoftCreatR avatar Feb 24 '22 06:02 SoftCreatR

Follow up:

I've installed the package recursive-copy-cli and updated the scripts:

"build": "recursive-copy --overwrite ./node_modules/workbox-cdn/workbox ./static/workbox && nuxt build",
"generate": "recursive-copy --overwrite ./node_modules/workbox-cdn/workbox ./static/workbox && nuxt generate",

...

  pwa: {
    workbox: {
      workboxURL: `/workbox/workbox-sw.js?${Date.now()}`,
      config: {
        modulePathPrefix: '/workbox'
      }
    },
  },

This seems to work, but it doesn't feel right.

SoftCreatR avatar Feb 24 '22 07:02 SoftCreatR

@SoftCreatR thx for this solution.... helped me out tremendously.

dreitzner avatar Feb 01 '23 12:02 dreitzner