项目原始demo,不改动
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
Den här utvecklingskatalogen är arkiverad. Du kan se filer och klona katalogen, men inte öppna ärenden eller genomföra push- eller pull-förfrågningar.
 
 
 
 

53 rader
1.6 KiB

  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 log = require("./log");
  8. var checkForUpdate = function checkForUpdate(fromUpdate) {
  9. module.hot.check().then(function(updatedModules) {
  10. if(!updatedModules) {
  11. if(fromUpdate)
  12. log("info", "[HMR] Update applied.");
  13. else
  14. log("warning", "[HMR] Cannot find update.");
  15. return;
  16. }
  17. return module.hot.apply({
  18. ignoreUnaccepted: true,
  19. onUnaccepted: function(data) {
  20. log("warning", "Ignored an update to unaccepted module " + data.chain.join(" -> "));
  21. },
  22. }).then(function(renewedModules) {
  23. require("./log-apply-result")(updatedModules, renewedModules);
  24. checkForUpdate(true);
  25. return null;
  26. });
  27. }).catch(function(err) {
  28. var status = module.hot.status();
  29. if(["abort", "fail"].indexOf(status) >= 0) {
  30. log("warning", "[HMR] Cannot apply update.");
  31. log("warning", "[HMR] " + err.stack || err.message);
  32. log("warning", "[HMR] You need to restart the application!");
  33. } else {
  34. log("warning", "[HMR] Update failed: " + err.stack || err.message);
  35. }
  36. });
  37. };
  38. process.on(__resourceQuery.substr(1) || "SIGUSR2", function() {
  39. if(module.hot.status() !== "idle") {
  40. log("warning", "[HMR] Got signal but currently in " + module.hot.status() + " state.");
  41. log("warning", "[HMR] Need to be in idle state to start hot update.");
  42. return;
  43. }
  44. checkForUpdate();
  45. });
  46. } else {
  47. throw new Error("[HMR] Hot Module Replacement is disabled.");
  48. }