webpack/hot/poll.js

33 lines
1003 B
JavaScript
Raw Normal View History

2015-03-12 06:48:00 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
if(module.hot) {
var hotPollInterval = +(__resourceQuery.substr(1)) || (10*60*1000);
2015-03-12 06:48:00 +08:00
function checkForUpdate(fromUpdate) {
if(module.hot.status() === "idle") {
2015-03-12 06:48:00 +08:00
module.hot.check(true, function(err, updatedModules) {
if(err) {
2015-03-12 06:48:00 +08:00
if(module.hot.status() in {abort:1,fail:1}) {
console.warn("[HMR] Cannot apply update.");
console.warn("[HMR] " + err.stack || err.message);
console.warn("[HMR] You need to restart the application!");
} else {
console.warn("[HMR] Update failed: " + err.stack || err.message);
}
return;
}
2015-03-12 06:48:00 +08:00
if(!updatedModules) {
if(fromUpdate) console.log("[HMR] Update applied.");
return;
}
require("./log-apply-result")(updatedModules, updatedModules);
checkForUpdate(true);
});
}
2015-03-12 06:48:00 +08:00
}
setInterval(checkForUpdate, hotPollInterval);
} else {
throw new Error("[HMR] Hot Module Replacement is disabled.");
}