2015-03-12 06:48:00 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2015-05-22 04:58:22 +08:00
|
|
|
/*globals window __webpack_hash__ */
|
2014-09-03 19:17:37 +08:00
|
|
|
if(module.hot) {
|
2015-10-18 05:46:42 +08:00
|
|
|
var lastHash;
|
2014-10-12 18:24:03 +08:00
|
|
|
var upToDate = function upToDate() {
|
2015-10-18 05:46:42 +08:00
|
|
|
return lastHash.indexOf(__webpack_hash__) >= 0;
|
2014-10-12 18:24:03 +08:00
|
|
|
};
|
|
|
|
var check = function check() {
|
2015-06-13 17:45:28 +08:00
|
|
|
module.hot.check().then(function(updatedModules) {
|
2015-01-18 17:57:31 +08:00
|
|
|
if(!updatedModules) {
|
|
|
|
console.warn("[HMR] Cannot find update. Need to do a full reload!");
|
2015-05-22 04:58:22 +08:00
|
|
|
console.warn("[HMR] (Probably because of restarting the webpack-dev-server)");
|
2015-01-18 17:57:31 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-09-03 19:17:37 +08:00
|
|
|
|
2016-08-06 23:31:24 +08:00
|
|
|
return module.hot.apply({
|
2016-06-24 17:17:25 +08:00
|
|
|
ignoreUnaccepted: true,
|
|
|
|
ignoreDeclined: true,
|
2016-07-02 23:30:21 +08:00
|
|
|
ignoreErrored: true,
|
2016-06-24 17:17:25 +08:00
|
|
|
onUnaccepted: function(data) {
|
|
|
|
console.warn("Ignored an update to unaccepted module " + data.chain.join(" -> "));
|
|
|
|
},
|
|
|
|
onDeclined: function(data) {
|
|
|
|
console.warn("Ignored an update to declined module " + data.chain.join(" -> "));
|
2016-07-02 23:30:21 +08:00
|
|
|
},
|
|
|
|
onErrored: function(data) {
|
|
|
|
console.warn("Ignored an error while updating module " + data.moduleId + " (" + data.type + ")");
|
2016-06-24 17:17:25 +08:00
|
|
|
}
|
2016-06-15 23:08:33 +08:00
|
|
|
}).then(function(renewedModules) {
|
2014-09-03 19:17:37 +08:00
|
|
|
if(!upToDate()) {
|
|
|
|
check();
|
|
|
|
}
|
|
|
|
|
2015-03-12 06:48:00 +08:00
|
|
|
require("./log-apply-result")(updatedModules, renewedModules);
|
2014-09-03 19:17:37 +08:00
|
|
|
|
|
|
|
if(upToDate()) {
|
|
|
|
console.log("[HMR] App is up to date.");
|
|
|
|
}
|
|
|
|
});
|
2015-06-13 17:45:28 +08:00
|
|
|
}).catch(function(err) {
|
2016-06-21 03:46:27 +08:00
|
|
|
var status = module.hot.status();
|
|
|
|
if(["abort", "fail"].indexOf(status) >= 0) {
|
2015-06-13 17:45:28 +08:00
|
|
|
console.warn("[HMR] Cannot check for update. Need to do a full reload!");
|
|
|
|
console.warn("[HMR] " + err.stack || err.message);
|
|
|
|
} else {
|
|
|
|
console.warn("[HMR] Update check failed: " + err.stack || err.message);
|
|
|
|
}
|
2014-09-03 19:17:37 +08:00
|
|
|
});
|
2014-10-12 18:24:03 +08:00
|
|
|
};
|
2015-10-18 05:46:42 +08:00
|
|
|
var hotEmitter = require("./emitter");
|
|
|
|
hotEmitter.on("webpackHotUpdate", function(currentHash) {
|
|
|
|
lastHash = currentHash;
|
2016-06-16 11:54:42 +08:00
|
|
|
if(!upToDate()) {
|
|
|
|
var status = module.hot.status();
|
|
|
|
if(status === "idle") {
|
|
|
|
console.log("[HMR] Checking for updates on the server...");
|
|
|
|
check();
|
|
|
|
} else if(["abort", "fail"].indexOf(status) >= 0) {
|
|
|
|
console.warn("[HMR] Cannot apply update as a previous update " + status + "ed. Need to do a full reload!");
|
|
|
|
}
|
2014-09-03 19:17:37 +08:00
|
|
|
}
|
2014-10-08 00:20:02 +08:00
|
|
|
});
|
2014-09-03 19:17:37 +08:00
|
|
|
console.log("[HMR] Waiting for update signal from WDS...");
|
|
|
|
} else {
|
2015-02-13 11:30:24 +08:00
|
|
|
throw new Error("[HMR] Hot Module Replacement is disabled.");
|
2014-09-03 19:17:37 +08:00
|
|
|
}
|