| 
									
										
										
										
											2015-03-12 06:48:00 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2024-07-31 12:23:44 +08:00
										 |  |  | /* globals __webpack_hash__ */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | if (module.hot) { | 
					
						
							| 
									
										
										
										
											2023-05-15 23:49:46 +08:00
										 |  |  | 	/** @type {undefined|string} */ | 
					
						
							| 
									
										
										
										
											2015-10-18 05:46:42 +08:00
										 |  |  | 	var lastHash; | 
					
						
							| 
									
										
										
										
											2014-10-12 18:24:03 +08:00
										 |  |  | 	var upToDate = function upToDate() { | 
					
						
							| 
									
										
										
										
											2023-05-15 23:49:46 +08:00
										 |  |  | 		return /** @type {string} */ (lastHash).indexOf(__webpack_hash__) >= 0; | 
					
						
							| 
									
										
										
										
											2014-10-12 18:24:03 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-05-31 17:00:41 +08:00
										 |  |  | 	var log = require("./log"); | 
					
						
							| 
									
										
										
										
											2014-10-12 18:24:03 +08:00
										 |  |  | 	var check = function check() { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		module.hot | 
					
						
							|  |  |  | 			.check() | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 					log("warning", "[HMR] Cannot find update. Need to do a full reload!"); | 
					
						
							|  |  |  | 					log( | 
					
						
							|  |  |  | 						"warning", | 
					
						
							|  |  |  | 						"[HMR] (Probably because of restarting the webpack-dev-server)" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 					return; | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return module.hot | 
					
						
							|  |  |  | 					.apply({ | 
					
						
							|  |  |  | 						ignoreUnaccepted: true, | 
					
						
							|  |  |  | 						ignoreDeclined: true, | 
					
						
							|  |  |  | 						ignoreErrored: true, | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 						onUnaccepted: function (data) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							log( | 
					
						
							|  |  |  | 								"warning", | 
					
						
							|  |  |  | 								"Ignored an update to unaccepted module " + | 
					
						
							|  |  |  | 									data.chain.join(" -> ") | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 						onDeclined: function (data) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							log( | 
					
						
							|  |  |  | 								"warning", | 
					
						
							|  |  |  | 								"Ignored an update to declined module " + | 
					
						
							|  |  |  | 									data.chain.join(" -> ") | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						}, | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 						onErrored: function (data) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							log("error", data.error); | 
					
						
							|  |  |  | 							log( | 
					
						
							|  |  |  | 								"warning", | 
					
						
							|  |  |  | 								"Ignored an error while updating module " + | 
					
						
							|  |  |  | 									data.moduleId + | 
					
						
							|  |  |  | 									" (" + | 
					
						
							|  |  |  | 									data.type + | 
					
						
							|  |  |  | 									")" | 
					
						
							|  |  |  | 							); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}) | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 					.then(function (renewedModules) { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						if (!upToDate()) { | 
					
						
							|  |  |  | 							check(); | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						require("./log-apply-result")(updatedModules, renewedModules); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						if (upToDate()) { | 
					
						
							|  |  |  | 							log("info", "[HMR] App is up to date."); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 			}) | 
					
						
							| 
									
										
										
										
											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 check for update. Need to do a full reload!" | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2019-06-12 21:28:45 +08:00
										 |  |  | 					log("warning", "[HMR] " + log.formatError(err)); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2019-06-12 21:28:45 +08:00
										 |  |  | 					log("warning", "[HMR] Update check failed: " + log.formatError(err)); | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-10-12 18:24:03 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2015-10-18 05:46:42 +08:00
										 |  |  | 	var hotEmitter = require("./emitter"); | 
					
						
							| 
									
										
										
										
											2020-03-29 06:10:15 +08:00
										 |  |  | 	hotEmitter.on("webpackHotUpdate", function (currentHash) { | 
					
						
							| 
									
										
										
										
											2015-10-18 05:46:42 +08:00
										 |  |  | 		lastHash = currentHash; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!upToDate()) { | 
					
						
							| 
									
										
										
										
											2016-06-16 11:54:42 +08:00
										 |  |  | 			var status = module.hot.status(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			if (status === "idle") { | 
					
						
							| 
									
										
										
										
											2017-05-31 17:00:41 +08:00
										 |  |  | 				log("info", "[HMR] Checking for updates on the server..."); | 
					
						
							| 
									
										
										
										
											2016-06-16 11:54:42 +08:00
										 |  |  | 				check(); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} else if (["abort", "fail"].indexOf(status) >= 0) { | 
					
						
							|  |  |  | 				log( | 
					
						
							|  |  |  | 					"warning", | 
					
						
							|  |  |  | 					"[HMR] Cannot apply update as a previous update " + | 
					
						
							|  |  |  | 						status + | 
					
						
							|  |  |  | 						"ed. Need to do a full reload!" | 
					
						
							|  |  |  | 				); | 
					
						
							| 
									
										
										
										
											2016-06-16 11:54:42 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-10-08 00:20:02 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2017-05-31 17:00:41 +08:00
										 |  |  | 	log("info", "[HMR] Waiting for update signal from WDS..."); | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | } else { | 
					
						
							| 
									
										
										
										
											2015-02-13 11:30:24 +08:00
										 |  |  | 	throw new Error("[HMR] Hot Module Replacement is disabled."); | 
					
						
							| 
									
										
										
										
											2014-09-03 19:17:37 +08:00
										 |  |  | } |