This repository has been archived by the owner on Nov 20, 2019. It is now read-only.
Make the plugin play nice with webpack dev middleware #97
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there, this plugin has been very useful for us as we start integrating service workers into our apps. Thanks!
The one thing that was driving me nuts was that when running webpack in dev mode (with webpack dev middleware), the service worker was getting re-generated on every change to any file. (which then triggers the browser to go and install it)
The main reason for this constant regeneration is that in dev mode, webpack only emits the assets that have changed, which was causing the service worker manifest to "lose files" and be recompiled each time. (so on every change the service worker would break! :-( )
This PR fixes that issue by switching the plugin to additively add assets to the manifest as they come in. It only happens when compiler.watchMode === true, so production environments should be unaffected by this change.
Once I fixed the manifest issue, I needed to figure out how to still detect changes to the service worker code itself. To that end, I was going to use the timestamps, but there's a bug in webpack (webpack/webpack#5970) So I ended up using webpack's internal file system to diff the service worker source files manually.
Not the cleanest solution, but it's working super reliably for me!
I'd be willing to look at adding some actual tests for this, but I'm unfamiliar with how to test webpack in a dev kind of setup... :-/