Skip to content

generateSW uses custom Workbox runtime bundles, not CDN #2064

@jeffposnick

Description

@jeffposnick

My current plan for Workbox v5's generateSW mode is to produce output that uses a custom bundle of the Workbox runtime, which includes code for only the features of Workbox that are used by the configuration you provide.

This will effectively automate the process described in "Using Bundlers (webpack/Rollup) with Workbox" for folks who want the simplicity of generateSW mode. (It will use Rollup under the hood for the actual bundling and code elimination.)

Because the underlying template used in generateSW mode looks very different when the Workbox runtime is referenced via a custom bundle vs. when the Workbox runtime is loaded from the CDN via workbox-sw, I plan on removing the ability to use the CDN copy of Workbox with generateSW mode, along with the importWorkboxFrom configuration option.

For the time being, we will still publish bundles of the Workbox runtime to the CDN, but my expectation is that it will be only be useful for injectManifest users. Longer-term, we may phase out the CDN entirely, and encourage all developers to go through a flow that produces a Workbox runtime bundle that's customized for their specific usage.

Parameter changes

As mentioned above, importWorkboxFrom will no longer be supported in generateSW mode.

New configuration parameters that I anticipate adding include:

  • inlineWorkboxRuntime, defaulting to false, which controls whether the Workbox runtime code is inlined into a single service worker file, or whether the runtime code for the Workbox libraries are output into a separate, versioned file that is automatically pulled in to the main service worker via importScripts().

  • mode, defaulting to either process.env.NODE_ENV || 'production', which controls whether terser is used, and whether Workbox's option code for, e.g., enhanced logging is enabled or disabled in the generated bundle.

  • sourcemap, defaulting to true, which controls whether sourcemaps are also created for the generated file(s).

  • babelPresetEnvTargets, defaulting to ['chrome >= 56'], which controls what transpilation is performed via @babel/preset-env when creating the generated file(s). ['chrome >= 56'] matches the setting currently used when we produce our CDN-hosted bundles.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions