2015-03-11 23:48:00 +01:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2015-05-21 22:58:22 +02:00
|
|
|
/*globals window __webpack_hash__ */
|
2018-02-25 02:00:20 +01:00
|
|
|
if (module.hot) {
|
2015-10-17 23:46:42 +02:00
|
|
|
var lastHash;
|
2014-10-12 12:24:03 +02:00
|
|
|
var upToDate = function upToDate() {
|
2015-10-17 23:46:42 +02:00
|
|
|
return lastHash.indexOf(__webpack_hash__) >= 0;
|
2014-10-12 12:24:03 +02:00
|
|
|
};
|
2017-05-31 11:00:41 +02:00
|
|
|
var log = require("./log");
|
2014-10-12 12:24:03 +02:00
|
|
|
var check = function check() {
|
2018-02-25 02:00:20 +01:00
|
|
|
module.hot
|
|
|
|
.check(true)
|
|
|
|
.then(function(updatedModules) {
|
|
|
|
if (!updatedModules) {
|
|
|
|
log("warning", "[HMR] Cannot find update. Need to do a full reload!");
|
|
|
|
log(
|
|
|
|
"warning",
|
|
|
|
"[HMR] (Probably because of restarting the webpack-dev-server)"
|
|
|
|
);
|
|
|
|
window.location.reload();
|
|
|
|
return;
|
|
|
|
}
|
2013-06-19 16:09:46 +02:00
|
|
|
|
2018-02-25 02:00:20 +01:00
|
|
|
if (!upToDate()) {
|
|
|
|
check();
|
|
|
|
}
|
2013-06-19 13:49:57 +02:00
|
|
|
|
2018-02-25 02:00:20 +01:00
|
|
|
require("./log-apply-result")(updatedModules, updatedModules);
|
2015-03-11 23:48:00 +01:00
|
|
|
|
2018-02-25 02:00:20 +01:00
|
|
|
if (upToDate()) {
|
|
|
|
log("info", "[HMR] App is up to date.");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
var status = module.hot.status();
|
|
|
|
if (["abort", "fail"].indexOf(status) >= 0) {
|
|
|
|
log(
|
|
|
|
"warning",
|
|
|
|
"[HMR] Cannot apply update. Need to do a full reload!"
|
|
|
|
);
|
2019-06-12 15:28:45 +02:00
|
|
|
log("warning", "[HMR] " + log.formatError(err));
|
2018-02-25 02:00:20 +01:00
|
|
|
window.location.reload();
|
|
|
|
} else {
|
2019-06-12 15:28:45 +02:00
|
|
|
log("warning", "[HMR] Update failed: " + log.formatError(err));
|
2018-02-25 02:00:20 +01:00
|
|
|
}
|
|
|
|
});
|
2014-10-12 12:24:03 +02:00
|
|
|
};
|
2015-10-17 23:46:42 +02:00
|
|
|
var hotEmitter = require("./emitter");
|
|
|
|
hotEmitter.on("webpackHotUpdate", function(currentHash) {
|
|
|
|
lastHash = currentHash;
|
2018-02-25 02:00:20 +01:00
|
|
|
if (!upToDate() && module.hot.status() === "idle") {
|
2017-05-31 11:00:41 +02:00
|
|
|
log("info", "[HMR] Checking for updates on the server...");
|
2015-10-17 23:46:42 +02:00
|
|
|
check();
|
2013-06-19 13:49:57 +02:00
|
|
|
}
|
2014-10-07 18:20:02 +02:00
|
|
|
});
|
2017-05-31 11:00:41 +02:00
|
|
|
log("info", "[HMR] Waiting for update signal from WDS...");
|
2014-08-27 16:50:40 +02:00
|
|
|
} else {
|
2015-02-13 04:30:24 +01:00
|
|
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
2014-09-03 13:17:37 +02:00
|
|
|
}
|