You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.1 KiB

4 years ago
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /*globals __resourceQuery */
  6. if (module.hot) {
  7. var hotPollInterval = +__resourceQuery.substr(1) || 10 * 60 * 1000;
  8. var log = require("./log");
  9. var checkForUpdate = function checkForUpdate(fromUpdate) {
  10. if (module.hot.status() === "idle") {
  11. module.hot
  12. .check(true)
  13. .then(function(updatedModules) {
  14. if (!updatedModules) {
  15. if (fromUpdate) log("info", "[HMR] Update applied.");
  16. return;
  17. }
  18. require("./log-apply-result")(updatedModules, updatedModules);
  19. checkForUpdate(true);
  20. })
  21. .catch(function(err) {
  22. var status = module.hot.status();
  23. if (["abort", "fail"].indexOf(status) >= 0) {
  24. log("warning", "[HMR] Cannot apply update.");
  25. log("warning", "[HMR] " + log.formatError(err));
  26. log("warning", "[HMR] You need to restart the application!");
  27. } else {
  28. log("warning", "[HMR] Update failed: " + log.formatError(err));
  29. }
  30. });
  31. }
  32. };
  33. setInterval(checkForUpdate, hotPollInterval);
  34. } else {
  35. throw new Error("[HMR] Hot Module Replacement is disabled.");
  36. }