0

As we now in version 5 of workbox, the importWorkboxFrom config is removed, but if we are using injectManifest how we should import workbox localy? Is the only way in using importScripts with https://storage.googleapis.com/workbox-cdn/releases/5.0.0/workbox-sw.js?

docs says that generateSW uses locally import by default but what about injectManifest? https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v4#build_tool_option_overhaul

SayJeyHi
  • 1,559
  • 4
  • 19
  • 39

1 Answers1

3

If you're using Workbox v5 in InjectManifest mode, then you should consume the Workbox runtime libraries ES modules, and allow webpack to compile/bundle them into the final output swDest file. You don't need to use importScripts() or the CDN anymore.

There more info about making this change at https://developers.google.com/web/tools/workbox/guides/using-bundlers#moving_from_importscripts_to_module_imports

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167
  • thanks, In this way where to put custom importScripts? webpack does compile the workbox-sw and injectManifest will add some data on it. As the `importScripts` property removed in v5 from inject manifest, where we should add custom `importScripts`? – SayJeyHi Mar 03 '20 at 09:10
  • 1
    In v5 in `InjectManifest` mode, you can either include the logic you'd otherwise put into an imported script directly in you top-level `swSrc` file, or alternatively, write `importScripts('path/to/imports.js')` in your `swSrc` file. You have complete control over the contents of your service worker. – Jeff Posnick Mar 03 '20 at 16:27