Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

dev-server.js 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 log = require("./log");
  12. var check = function check() {
  13. module.hot
  14. .check(true)
  15. .then(function(updatedModules) {
  16. if (!updatedModules) {
  17. log("warning", "[HMR] Cannot find update. Need to do a full reload!");
  18. log(
  19. "warning",
  20. "[HMR] (Probably because of restarting the webpack-dev-server)"
  21. );
  22. window.location.reload();
  23. return;
  24. }
  25. if (!upToDate()) {
  26. check();
  27. }
  28. require("./log-apply-result")(updatedModules, updatedModules);
  29. if (upToDate()) {
  30. log("info", "[HMR] App is up to date.");
  31. }
  32. })
  33. .catch(function(err) {
  34. var status = module.hot.status();
  35. if (["abort", "fail"].indexOf(status) >= 0) {
  36. log(
  37. "warning",
  38. "[HMR] Cannot apply update. Need to do a full reload!"
  39. );
  40. log("warning", "[HMR] " + log.formatError(err));
  41. window.location.reload();
  42. } else {
  43. log("warning", "[HMR] Update failed: " + log.formatError(err));
  44. }
  45. });
  46. };
  47. var hotEmitter = require("./emitter");
  48. hotEmitter.on("webpackHotUpdate", function(currentHash) {
  49. lastHash = currentHash;
  50. if (!upToDate() && module.hot.status() === "idle") {
  51. log("info", "[HMR] Checking for updates on the server...");
  52. check();
  53. }
  54. });
  55. log("info", "[HMR] Waiting for update signal from WDS...");
  56. } else {
  57. throw new Error("[HMR] Hot Module Replacement is disabled.");
  58. }