Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jharris4
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant