Search code examples
workboxsw-precacheworkbox-webpack-plugin

import workbox from local v5 in webpack-plugin


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


Solution

  • 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