Skip to content

Make the plugin play nice with webpack dev middleware#97

Open
jharris4 wants to merge 1 commit intooliviertassinari:masterfrom
jharris4:master
Open

Make the plugin play nice with webpack dev middleware#97
jharris4 wants to merge 1 commit intooliviertassinari:masterfrom
jharris4:master

Conversation

@jharris4
Copy link
Copy Markdown

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... :-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant