UNPKG

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