dev-server.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. /*globals window __webpack_hash__ */
  6. if(module.hot) {
  7. var lastHash;
  8. var upToDate = function upToDate() {
  9. return lastHash.indexOf(__webpack_hash__) >= 0;
  10. };
  11. var check = function check() {
  12. module.hot.check(true).then(function(updatedModules) {
  13. if(!updatedModules) {
  14. console.warn("[HMR] Cannot find update. Need to do a full reload!");
  15. console.warn("[HMR] (Probably because of restarting the webpack-dev-server)");
  16. window.location.reload();
  17. return;
  18. }
  19. if(!upToDate()) {
  20. check();
  21. }
  22. require("./log-apply-result")(updatedModules, updatedModules);
  23. if(upToDate()) {
  24. console.log("[HMR] App is up to date.");
  25. }
  26. }).catch(function(err) {
  27. var status = module.hot.status();
  28. if(["abort", "fail"].indexOf(status) >= 0) {
  29. console.warn("[HMR] Cannot apply update. Need to do a full reload!");
  30. console.warn("[HMR] " + err.stack || err.message);
  31. window.location.reload();
  32. } else {
  33. console.warn("[HMR] Update failed: " + err.stack || err.message);
  34. }
  35. });
  36. };
  37. var hotEmitter = require("./emitter");
  38. hotEmitter.on("webpackHotUpdate", function(currentHash) {
  39. lastHash = currentHash;
  40. if(!upToDate() && module.hot.status() === "idle") {
  41. console.log("[HMR] Checking for updates on the server...");
  42. check();
  43. }
  44. });
  45. console.log("[HMR] Waiting for update signal from WDS...");
  46. } else {
  47. throw new Error("[HMR] Hot Module Replacement is disabled.");
  48. }