I just introduced this to a (personal) project and was trying to figure out how to tell if the module has actually changed:
|
watching[path] = watch(path, { persistent: false }, function(eventType, filename) { |
Traditionally, webpack generates a hash for the file contents so that, even if HMR fires on the client, there's a way to tell (via the websocket payload) what the current hash is.
(By comparing the previous hash vs. the current hash for a module, you can determine if there have been any changes, or if the user simple saved twice)
Now, why is this important?
Sometimes HMR can get into a bad state, in which case I've been using double-save to reload the server/client/browser.
Unfortunately, I can't tell what file prompted to HMR, since this line is called with path instead of filename:
|
parent.hot._acceptedDependencies[path](path); |
What would you recommend I do to differentiate changes vs. saved?
My first thought was to change the call to:
// Send the accepted path & the file that triggered the change
parent.hot._acceptedDependencies[path](path, filename);
I just introduced this to a (personal) project and was trying to figure out how to tell if the module has actually changed:
hot-module-replacement/index.js
Line 70 in 834782b
Traditionally, webpack generates a hash for the file contents so that, even if HMR fires on the client, there's a way to tell (via the websocket payload) what the current hash is.
(By comparing the previous hash vs. the current hash for a module, you can determine if there have been any changes, or if the user simple saved twice)
Now, why is this important?
Sometimes HMR can get into a bad state, in which case I've been using double-save to reload the server/client/browser.
Unfortunately, I can't tell what file prompted to HMR, since this line is called with
pathinstead offilename:hot-module-replacement/index.js
Line 97 in 834782b
What would you recommend I do to differentiate changes vs. saved?
My first thought was to change the call to: