shadowwalker / next-pwa

Zero config PWA plugin for Next.js, with workbox 🧰
MIT License
3.86k stars 323 forks source link

Question: How to integrate jakearchibald's indexedDB library (idb) #353

Open ninsky opened 2 years ago

ninsky commented 2 years ago

I have a hard time to integrate Jake Archibalds IndexedDB library "idb" into my PWA in order that it can be used by the service worker.

My application works by integrating "idb" like this when code is called by a service worker:

if ('function' === typeof importScripts) {
    importScripts("https://cdn.jsdelivr.net/npm/idb@7/build/umd.js")
} 

But this code doesn't work for calls not performed by a service worker as the "importScripts" is just in the global scope in case of an service worker request.

As I understand this comment Jake Archibald proposes to use a bundler to make the "idb" library available for the service worker without beeing in need of "importScripts". By doing so the bundled "idb" library would also be available for non service worker calls.

Does anyone have an example how to bundle a library with next-pwa? I think this has to be done by a workbox-webpack-plugin configuaration.

Thanks in advance Nino