Better documentation for mode as a replacement for setConfig()
See original GitHub issueLibrary Affected: workbox-cli 5.0.0 - generateSW command
Browser & Platform: all browsers
Issue or Feature Request Description: I am migrating from 4.3.1 to 5.0.0 and tried the inlineWorkboxRuntime option. However I am getting Uncaught (in promise) ReferenceError: workbox is not defined. for v5 cli. Facing this error inside the file mentioned under importScripts option.
Workbox 4.3.1
importWorkboxFrom: "local", importScripts: ["sw-custom.js"]
Workbox 5.0.0
inlineWorkboxRuntime: true, importScripts: ["sw-custom.js"]
Content of sw-custom.js
workbox.setConfig({ debug: true });
This is because workbox is being minified and workbox as a variable is not available. I can see some minified variables like G,g,B,T etc in the debugger for the ServiceWorkerGlobalScope.
Possible Fix I think the inlineWorkboxRuntime option also needs to minify contents of importScripts option.
Please let me know if you need any further inputs from my end.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top GitHub Comments
You can set
mode: 'development'
ormode: 'production'
in the v5generateSW
configuration to toggle between the Workbox runtime that has extra logging enabled and disabled.Sorry about that not being clear; we should add something to https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v4 to call this change out explicitly.
I’m not sure that that’s a reasonable assumption. If you want to use Workbox in that fashion, I’d recommend switching to the
injectManifest
mode. In that mode, you have full control over the contents of your service worker file (including inlining whatever code you want), and Workbox just handles replacing theself.__WB_MANIFEST
variable with the actual precache manifest based on your build config.Folks have historically used
importScripts
for pulling in non-Workbox code, like code for push notifications. They can continue doing that in v5 withinlineWorkboxRuntime: true
if they want. Disallowing that entirely would be too strict.For your particular use case, I think you’re going to have a better time switching to
injectManifest
and following the info at https://developers.google.com/web/tools/workbox/guides/using-bundlers to create a bundle of your service worker file using ES imports.