Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generateSW uses custom Workbox runtime bundles, not CDN #2064

Closed
jeffposnick opened this issue May 29, 2019 · 2 comments
Closed

generateSW uses custom Workbox runtime bundles, not CDN #2064

jeffposnick opened this issue May 29, 2019 · 2 comments
Labels
Breaking Change Denotes a "major" semver change. Discuss An open question, where input from the community would be appreciated. workbox-build workbox-cli workbox-webpack-plugin
Milestone

Comments

@jeffposnick
Copy link
Contributor

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.

@jeffposnick jeffposnick added Discuss An open question, where input from the community would be appreciated. Breaking Change Denotes a "major" semver change. workbox-build workbox-webpack-plugin workbox-cli labels May 29, 2019
@jeffposnick jeffposnick added this to the v5 milestone May 29, 2019
@jeffposnick
Copy link
Contributor Author

This should be addressed by the current Workbox v5.0.0 alpha.

@Viktor286hearts
Copy link

Viktor286hearts commented Jun 2, 2020

@jeffposnick is there a way to setup destination path for "custom Workbox runtime bundle" or it always saves in the same directory as main generated sw.js file (swDest property)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Denotes a "major" semver change. Discuss An open question, where input from the community would be appreciated. workbox-build workbox-cli workbox-webpack-plugin
Projects
None yet
Development

No branches or pull requests

2 participants