webpack/hot/poll.js

34 lines
1.0 KiB
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
*/
2015-05-22 04:58:22 +08:00
/*globals __resourceQuery */
if(module.hot) {
2015-05-22 04:58:22 +08:00
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-05-22 04:58:22 +08:00
if(module.hot.status() in {abort: 1, fail: 1}) {
2015-03-12 06:48:00 +08:00
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.");
}