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) {
|
2022-03-14 05:54:18 +08:00
|
|
|
var hotPollInterval = +__resourceQuery.slice(1) || 10 * 60 * 1000;
|
2017-05-31 17:00:41 +08:00
|
|
|
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) {
|
2021-08-05 22:03:13 +08:00
|
|
|
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.");
|
2019-06-12 21:28:45 +08:00
|
|
|
log("warning", "[HMR] " + log.formatError(err));
|
2018-02-25 09:00:20 +08:00
|
|
|
log("warning", "[HMR] You need to restart the application!");
|
|
|
|
} else {
|
2019-06-12 21:28:45 +08:00
|
|
|
log("warning", "[HMR] Update failed: " + log.formatError(err));
|
2018-02-25 09:00:20 +08:00
|
|
|
}
|
|
|
|
});
|
2013-06-19 19:49:57 +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.");
|
|
|
|
}
|