1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
/*globals window __webpack_hash__ */
|
6 |
|
|
if (module.hot) {
|
7 |
|
|
var lastHash;
|
8 |
|
|
var upToDate = function upToDate() {
|
9 |
|
|
return lastHash.indexOf(__webpack_hash__) >= 0;
|
10 |
|
|
};
|
11 |
|
|
var log = require("./log");
|
12 |
|
|
var check = function check() {
|
13 |
|
|
module.hot
|
14 |
|
|
.check(true)
|
15 |
|
|
.then(function(updatedModules) {
|
16 |
|
|
if (!updatedModules) {
|
17 |
|
|
log("warning", "[HMR] Cannot find update. Need to do a full reload!");
|
18 |
|
|
log(
|
19 |
|
|
"warning",
|
20 |
|
|
"[HMR] (Probably because of restarting the webpack-dev-server)"
|
21 |
|
|
);
|
22 |
|
|
window.location.reload();
|
23 |
|
|
return;
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
if (!upToDate()) {
|
27 |
|
|
check();
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
require("./log-apply-result")(updatedModules, updatedModules);
|
31 |
|
|
|
32 |
|
|
if (upToDate()) {
|
33 |
|
|
log("info", "[HMR] App is up to date.");
|
34 |
|
|
}
|
35 |
|
|
})
|
36 |
|
|
.catch(function(err) {
|
37 |
|
|
var status = module.hot.status();
|
38 |
|
|
if (["abort", "fail"].indexOf(status) >= 0) {
|
39 |
|
|
log(
|
40 |
|
|
"warning",
|
41 |
|
|
"[HMR] Cannot apply update. Need to do a full reload!"
|
42 |
|
|
);
|
43 |
|
|
log("warning", "[HMR] " + log.formatError(err));
|
44 |
|
|
window.location.reload();
|
45 |
|
|
} else {
|
46 |
|
|
log("warning", "[HMR] Update failed: " + log.formatError(err));
|
47 |
|
|
}
|
48 |
|
|
});
|
49 |
|
|
};
|
50 |
|
|
var hotEmitter = require("./emitter");
|
51 |
|
|
hotEmitter.on("webpackHotUpdate", function(currentHash) {
|
52 |
|
|
lastHash = currentHash;
|
53 |
|
|
if (!upToDate() && module.hot.status() === "idle") {
|
54 |
|
|
log("info", "[HMR] Checking for updates on the server...");
|
55 |
|
|
check();
|
56 |
|
|
}
|
57 |
|
|
});
|
58 |
|
|
log("info", "[HMR] Waiting for update signal from WDS...");
|
59 |
|
|
} else {
|
60 |
|
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
61 |
|
|
}
|