webpack/hot/poll.js

41 lines
1.2 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 */
2018-02-25 09:00:20 +08:00
if (module.hot) {
var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
var log = require("./log");
2015-07-16 06:27:37 +08:00
2023-05-15 23:49:46 +08:00
/**
* @param {boolean=} fromUpdate true when called from update
*/
2016-10-29 21:57:58 +08:00
var checkForUpdate = function checkForUpdate(fromUpdate) {
2018-02-25 09:00:20 +08:00
if (module.hot.status() === "idle") {
module.hot
.check(true)
2020-03-29 06:10:15 +08:00
.then(function (updatedModules) {
if (!updatedModules) {
2018-02-25 09:00:20 +08:00
if (fromUpdate) log("info", "[HMR] Update applied.");
return;
}
require("./log-apply-result")(updatedModules, updatedModules);
checkForUpdate(true);
})
2020-03-29 06:10:15 +08:00
.catch(function (err) {
2018-02-25 09:00:20 +08:00
var status = module.hot.status();
if (["abort", "fail"].indexOf(status) >= 0) {
log("warning", "[HMR] Cannot apply update.");
log("warning", "[HMR] " + log.formatError(err));
2018-02-25 09:00:20 +08:00
log("warning", "[HMR] You need to restart the application!");
} else {
log("warning", "[HMR] Update failed: " + log.formatError(err));
2018-02-25 09:00:20 +08:00
}
});
}
2017-01-11 17:51:58 +08:00
};
2015-03-12 06:48:00 +08:00
setInterval(checkForUpdate, hotPollInterval);
} else {
throw new Error("[HMR] Hot Module Replacement is disabled.");
}