1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | if (module.hot) {
|
11 | function checkForUpdate(fromUpdate) {
|
12 | module.hot.check().then(function(updatedModules) {
|
13 | if (!updatedModules) {
|
14 | if (fromUpdate) console.log("[HMR] Update applied.");
|
15 | else console.warn("[HMR] Cannot find update.");
|
16 | return;
|
17 | }
|
18 | return module.hot.apply({
|
19 | ignoreUnaccepted: false,
|
20 | onUnaccepted: function(data) {
|
21 | console.warn("Ignored an update to unaccepted module " + data.chain.join(" -> "));
|
22 | },
|
23 | }).then(function(renewedModules) {
|
24 | require("./log-apply-result")(updatedModules, renewedModules);
|
25 | checkForUpdate(true);
|
26 | });
|
27 | }).catch(function(err) {
|
28 | var status = module.hot.status();
|
29 | if (["abort", "fail"].indexOf(status) >= 0) {
|
30 | console.warn("[HMR] Cannot apply update.");
|
31 | console.warn("[HMR] " + err.stack || err.message);
|
32 | console.warn("[HMR] You need to restart the application!");
|
33 | process.exit(1)
|
34 | } else {
|
35 | console.warn("[HMR] Update failed: " + err.stack || err.message);
|
36 | }
|
37 | });
|
38 | }
|
39 | process.on("message", function(m) {
|
40 | if (m != __resourceQuery.substr(1)) return
|
41 | if (module.hot.status() !== "idle") {
|
42 | console.warn("[HMR] Got signal but currently in " + module.hot.status() + " state.");
|
43 | console.warn("[HMR] Need to be in idle state to start hot update.");
|
44 | return;
|
45 | }
|
46 | checkForUpdate();
|
47 | });
|
48 | } else {
|
49 | throw new Error("[HMR] Hot Module Replacement is disabled.");
|
50 | }
|