workbox icon indicating copy to clipboard operation
workbox copied to clipboard

Deprecate mode in the InjectManifest config

Open StephanBijzitter opened this issue 4 years ago • 4 comments
trafficstars

Library Affected: workbox-webpack-plugin (latest at time of writing)

Browser & Platform: Irrelevant

Issue or Feature Request Description: The documentation for mode states:

Optional string If set to 'production', then an optimized service worker bundle that excludes debugging info will be produced. If not explicitly configured here, the mode value configured in the current webpack compilation will be used.

I'm currently trying to debug why Safari appears to bypass the service worker fetch handlers on some devices (as reported by customers and reproduced by us), so I wanted to keep the logging enabled for the production build... just to have a bit more information. Setting mode to development did... absolutely nothing noticeable. It seems the code places more priority on NODE_ENV and only retains the logging when I set that to development.

Downside there is, now the entire application is using that NODE_ENV and it grew to over 10MB. Worth it while we're investigating this issue, but definitely not very nice.

When reporting bugs, please include relevant JavaScript Console logs and links to public URLs at which the issue could be reproduced. Not sure if I can provide any useful code

StephanBijzitter avatar May 13 '21 14:05 StephanBijzitter

Not sure if that makes this a bug report or a feature request, but it comes down to:

  • if I set mode: 'development' using the InjectManifest function, I expect to keep the logs in the final bundle, even if NODE_ENV is set to 'production'

StephanBijzitter avatar May 13 '21 14:05 StephanBijzitter

Sorry for the delay in getting back to you.

I'm unfortunately at a loss after spending some time digging into this—our current behavior obviously doesn't accomplish what we want, but I can't figure out whether it's even possible to either override the mode in a child compiler, or to modify/remove the DefinePlugin that has already set process.env.NODE_ENV in the parent compilation, and which the child inherits.

I'm going to ask about this in the webpack issue tracker, but we might just have to mark mode as being deprecated for InjectManifest, and note in the docs that the parent compilation's mode is always used.

jeffposnick avatar Aug 13 '21 00:08 jeffposnick

C.f. https://github.com/webpack/webpack/issues/13984

jeffposnick avatar Aug 13 '21 00:08 jeffposnick

The takeaway from the webpack discussion is that this use case isn't going to be supported. We're stuck inheriting the mode from the main compilation when using InjectManifest. (GenerateSW doesn't actually trigger a webpack compilation, so its mode setting is honored.)

I'll use this issue to track documenting mode in InjectManifest as being deprecated and non-functional, and we will remove it in a future major semver release.

jeffposnick avatar Aug 13 '21 18:08 jeffposnick