| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const RuntimeModule = require("../RuntimeModule"); | 
					
						
							|  |  |  | const Template = require("../Template"); | 
					
						
							| 
									
										
										
										
											2019-10-11 21:46:57 +08:00
										 |  |  | const chunkHasJs = require("../javascript/JavascriptModulesPlugin").chunkHasJs; | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | const compileBooleanMatcher = require("../util/compileBooleanMatcher"); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | const { getEntryInfo, needEntryDeferringCode } = require("./JsonpHelpers"); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class JsonpChunkLoadingRuntimeModule extends RuntimeModule { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 	constructor(runtimeRequirements, jsonpScript, linkPreload, linkPrefetch) { | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		super("jsonp chunk loading", 10); | 
					
						
							|  |  |  | 		this.runtimeRequirements = runtimeRequirements; | 
					
						
							|  |  |  | 		this.jsonpScript = jsonpScript; | 
					
						
							|  |  |  | 		this.linkPreload = linkPreload; | 
					
						
							|  |  |  | 		this.linkPrefetch = linkPrefetch; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @returns {string} runtime code | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	generate() { | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 		const { compilation, chunk, jsonpScript, linkPreload, linkPrefetch } = this; | 
					
						
							|  |  |  | 		const { runtimeTemplate, chunkGraph, outputOptions } = compilation; | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		const fn = RuntimeGlobals.ensureChunkHandlers; | 
					
						
							|  |  |  | 		const withLoading = this.runtimeRequirements.has( | 
					
						
							|  |  |  | 			RuntimeGlobals.ensureChunkHandlers | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2020-02-07 17:05:51 +08:00
										 |  |  | 		const withDefer = needEntryDeferringCode(compilation, chunk); | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 		const withHmr = this.runtimeRequirements.has( | 
					
						
							|  |  |  | 			RuntimeGlobals.hmrDownloadUpdateHandlers | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const withHmrManifest = this.runtimeRequirements.has( | 
					
						
							|  |  |  | 			RuntimeGlobals.hmrDownloadManifest | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 		const withPrefetch = this.runtimeRequirements.has( | 
					
						
							|  |  |  | 			RuntimeGlobals.prefetchChunkHandlers | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		const withPreload = this.runtimeRequirements.has( | 
					
						
							|  |  |  | 			RuntimeGlobals.preloadChunkHandlers | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		const entries = getEntryInfo(chunkGraph, chunk); | 
					
						
							|  |  |  | 		const jsonpObject = `${outputOptions.globalObject}[${JSON.stringify( | 
					
						
							|  |  |  | 			outputOptions.jsonpFunction | 
					
						
							|  |  |  | 		)}]`;
 | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 		const hasJsMatcher = compileBooleanMatcher( | 
					
						
							|  |  |  | 			chunkGraph.getChunkConditionMap(chunk, chunkHasJs) | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		return Template.asString([ | 
					
						
							|  |  |  | 			"// object to store loaded and loading chunks", | 
					
						
							|  |  |  | 			"// undefined = chunk not loaded, null = chunk preloaded/prefetched", | 
					
						
							|  |  |  | 			"// Promise = chunk loading, 0 = chunk loaded", | 
					
						
							|  |  |  | 			"var installedChunks = {", | 
					
						
							|  |  |  | 			Template.indent( | 
					
						
							|  |  |  | 				chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n") | 
					
						
							|  |  |  | 			), | 
					
						
							|  |  |  | 			"};", | 
					
						
							|  |  |  | 			"", | 
					
						
							|  |  |  | 			withDefer | 
					
						
							|  |  |  | 				? Template.asString([ | 
					
						
							|  |  |  | 						"var deferredModules = [", | 
					
						
							|  |  |  | 						Template.indent(entries.map(e => JSON.stringify(e)).join(",\n")), | 
					
						
							|  |  |  | 						"];" | 
					
						
							|  |  |  | 				  ]) | 
					
						
							|  |  |  | 				: "", | 
					
						
							|  |  |  | 			withLoading | 
					
						
							|  |  |  | 				? Template.asString([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						`${fn}.j = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 							"chunkId, promises", | 
					
						
							|  |  |  | 							hasJsMatcher !== false | 
					
						
							|  |  |  | 								? Template.indent([ | 
					
						
							|  |  |  | 										"// JSONP chunk loading for javascript", | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 										`var installedChunkData = ${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;`, | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 										'if(installedChunkData !== 0) { // 0 means "already installed".', | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 										Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 											"", | 
					
						
							|  |  |  | 											'// a Promise means "currently loading".', | 
					
						
							|  |  |  | 											"if(installedChunkData) {", | 
					
						
							|  |  |  | 											Template.indent([ | 
					
						
							|  |  |  | 												"promises.push(installedChunkData[2]);" | 
					
						
							|  |  |  | 											]), | 
					
						
							|  |  |  | 											"} else {", | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 											Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 												hasJsMatcher === true | 
					
						
							|  |  |  | 													? "if(true) { // all chunks have JS" | 
					
						
							|  |  |  | 													: `if(${hasJsMatcher("chunkId")}) {`, | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 												Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 													"// setup Promise in chunk cache", | 
					
						
							|  |  |  | 													`var promise = new Promise(${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 														"resolve, reject", | 
					
						
							|  |  |  | 														[ | 
					
						
							|  |  |  | 															`installedChunkData = installedChunks[chunkId] = [resolve, reject];` | 
					
						
							|  |  |  | 														] | 
					
						
							|  |  |  | 													)});`,
 | 
					
						
							|  |  |  | 													"promises.push(installedChunkData[2] = promise);", | 
					
						
							|  |  |  | 													"", | 
					
						
							|  |  |  | 													"// start chunk loading", | 
					
						
							|  |  |  | 													`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkScriptFilename}(chunkId);`, | 
					
						
							|  |  |  | 													`var loadingEnded = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 														"", | 
					
						
							|  |  |  | 														[ | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 															`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId)) {`, | 
					
						
							| 
									
										
										
										
											2019-10-29 16:54:03 +08:00
										 |  |  | 															Template.indent([ | 
					
						
							|  |  |  | 																"installedChunkData = installedChunks[chunkId];", | 
					
						
							|  |  |  | 																"if(installedChunkData !== 0) installedChunks[chunkId] = undefined;", | 
					
						
							|  |  |  | 																"if(installedChunkData) return installedChunkData[1];" | 
					
						
							|  |  |  | 															]), | 
					
						
							|  |  |  | 															"}" | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 														] | 
					
						
							|  |  |  | 													)};`,
 | 
					
						
							|  |  |  | 													jsonpScript.call("", chunk), | 
					
						
							|  |  |  | 													"document.head.appendChild(script);" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 												]), | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 												"} else installedChunks[chunkId] = 0;", | 
					
						
							| 
									
										
										
										
											2019-05-22 19:07:10 +08:00
										 |  |  | 												"", | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 												withHmr | 
					
						
							|  |  |  | 													? "if(currentUpdateChunks && currentUpdateChunks[chunkId]) promises.push(loadUpdateChunk(chunkId));" | 
					
						
							|  |  |  | 													: "// no HMR" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 											]), | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 											"}" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 										]), | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 										"}" | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 								  ]) | 
					
						
							|  |  |  | 								: Template.indent([ | 
					
						
							|  |  |  | 										"installedChunks[chunkId] = 0;", | 
					
						
							|  |  |  | 										"", | 
					
						
							|  |  |  | 										withHmr | 
					
						
							|  |  |  | 											? "if(currentUpdateChunks && currentUpdateChunks[chunkId]) promises.push(loadUpdateChunk(chunkId));" | 
					
						
							|  |  |  | 											: "// no HMR" | 
					
						
							|  |  |  | 								  ]) | 
					
						
							|  |  |  | 						)};`
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 				  ]) | 
					
						
							|  |  |  | 				: "// no chunk on demand loading", | 
					
						
							|  |  |  | 			"", | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 			withPrefetch && hasJsMatcher !== false | 
					
						
							|  |  |  | 				? `${ | 
					
						
							|  |  |  | 						RuntimeGlobals.prefetchChunkHandlers | 
					
						
							|  |  |  | 				  }.j = ${runtimeTemplate.basicFunction("chunkId", [ | 
					
						
							|  |  |  | 						`if((!${ | 
					
						
							|  |  |  | 							RuntimeGlobals.hasOwnProperty | 
					
						
							|  |  |  | 						}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${ | 
					
						
							|  |  |  | 							hasJsMatcher === true ? "true" : hasJsMatcher("chunkId") | 
					
						
							|  |  |  | 						}) {`,
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 							"installedChunks[chunkId] = null;", | 
					
						
							|  |  |  | 							linkPrefetch.call("", chunk), | 
					
						
							|  |  |  | 							"document.head.appendChild(link);" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 						]), | 
					
						
							| 
									
										
										
										
											2019-05-20 20:46:31 +08:00
										 |  |  | 						"}" | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 				  ])};`
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 				: "// no prefetching", | 
					
						
							|  |  |  | 			"", | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 			withPreload && hasJsMatcher !== false | 
					
						
							|  |  |  | 				? `${ | 
					
						
							|  |  |  | 						RuntimeGlobals.preloadChunkHandlers | 
					
						
							|  |  |  | 				  }.j = ${runtimeTemplate.basicFunction("chunkId", [ | 
					
						
							|  |  |  | 						`if((!${ | 
					
						
							|  |  |  | 							RuntimeGlobals.hasOwnProperty | 
					
						
							|  |  |  | 						}(installedChunks, chunkId) || installedChunks[chunkId] === undefined) && ${ | 
					
						
							|  |  |  | 							hasJsMatcher === true ? "true" : hasJsMatcher("chunkId") | 
					
						
							|  |  |  | 						}) {`,
 | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							|  |  |  | 							"installedChunks[chunkId] = null;", | 
					
						
							|  |  |  | 							linkPreload.call("", chunk), | 
					
						
							|  |  |  | 							"document.head.appendChild(link);" | 
					
						
							|  |  |  | 						]), | 
					
						
							|  |  |  | 						"}" | 
					
						
							|  |  |  | 				  ])};`
 | 
					
						
							|  |  |  | 				: "// no preloaded", | 
					
						
							|  |  |  | 			"", | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 			withHmr | 
					
						
							|  |  |  | 				? Template.asString([ | 
					
						
							|  |  |  | 						"var currentUpdateChunks;", | 
					
						
							|  |  |  | 						"var currentUpdate;", | 
					
						
							|  |  |  | 						"var currentUpdateRuntime;", | 
					
						
							|  |  |  | 						"var currentUpdatedModulesList;", | 
					
						
							|  |  |  | 						"var waitingUpdateResolves = {};", | 
					
						
							|  |  |  | 						"function loadUpdateChunk(chunkId) {", | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 							`return new Promise(${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 								"resolve, reject", | 
					
						
							|  |  |  | 								[ | 
					
						
							|  |  |  | 									"waitingUpdateResolves[chunkId] = resolve;", | 
					
						
							|  |  |  | 									"// start update chunk loading", | 
					
						
							|  |  |  | 									`var url = ${RuntimeGlobals.publicPath} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId);`, | 
					
						
							|  |  |  | 									`var loadingEnded = ${runtimeTemplate.basicFunction("", [ | 
					
						
							|  |  |  | 										"if(waitingUpdateResolves[chunkId]) {", | 
					
						
							|  |  |  | 										Template.indent([ | 
					
						
							|  |  |  | 											"waitingUpdateResolves[chunkId] = undefined", | 
					
						
							|  |  |  | 											"return reject;" | 
					
						
							|  |  |  | 										]), | 
					
						
							|  |  |  | 										"}" | 
					
						
							|  |  |  | 									])};`,
 | 
					
						
							|  |  |  | 									jsonpScript.call("", chunk), | 
					
						
							|  |  |  | 									"document.head.appendChild(script);" | 
					
						
							|  |  |  | 								] | 
					
						
							|  |  |  | 							)});`
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 						]), | 
					
						
							|  |  |  | 						"}", | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						`${outputOptions.globalObject}[${JSON.stringify( | 
					
						
							|  |  |  | 							outputOptions.hotUpdateFunction | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						)}] = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 							"chunkId, moreModules, runtime", | 
					
						
							|  |  |  | 							[ | 
					
						
							|  |  |  | 								"for(var moduleId in moreModules) {", | 
					
						
							|  |  |  | 								Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 									`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`, | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 									Template.indent([ | 
					
						
							|  |  |  | 										"currentUpdate[moduleId] = moreModules[moduleId];", | 
					
						
							|  |  |  | 										"if(currentUpdatedModulesList) currentUpdatedModulesList.push(moduleId);" | 
					
						
							|  |  |  | 									]), | 
					
						
							|  |  |  | 									"}" | 
					
						
							|  |  |  | 								]), | 
					
						
							|  |  |  | 								"}", | 
					
						
							|  |  |  | 								"if(runtime) currentUpdateRuntime.push(runtime);", | 
					
						
							|  |  |  | 								"if(waitingUpdateResolves[chunkId]) {", | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 									"waitingUpdateResolves[chunkId]();", | 
					
						
							|  |  |  | 									"waitingUpdateResolves[chunkId] = undefined;" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								]), | 
					
						
							|  |  |  | 								"}" | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 							] | 
					
						
							|  |  |  | 						)};`,
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 						"", | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						`${ | 
					
						
							|  |  |  | 							RuntimeGlobals.hmrDownloadUpdateHandlers | 
					
						
							|  |  |  | 						}.jsonp = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 							"chunkIds, removedChunks, removedModules, promises, applyHandlers, updatedModulesList", | 
					
						
							|  |  |  | 							[ | 
					
						
							|  |  |  | 								`applyHandlers.push(${runtimeTemplate.basicFunction("options", [ | 
					
						
							|  |  |  | 									"currentUpdateChunks = undefined;", | 
					
						
							|  |  |  | 									Template.getFunctionContent( | 
					
						
							|  |  |  | 										require("../hmr/JavascriptHotModuleReplacement.runtime.js") | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 									) | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 										.replace(/\$options\$/g, "options") | 
					
						
							|  |  |  | 										.replace(/\$updateModuleFactories\$/g, "currentUpdate") | 
					
						
							|  |  |  | 										.replace( | 
					
						
							|  |  |  | 											/\$updateRuntimeModules\$/g, | 
					
						
							|  |  |  | 											"currentUpdateRuntime" | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 										.replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache) | 
					
						
							|  |  |  | 										.replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData) | 
					
						
							|  |  |  | 										.replace( | 
					
						
							|  |  |  | 											/\$moduleFactories\$/g, | 
					
						
							|  |  |  | 											RuntimeGlobals.moduleFactories | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 										.replace( | 
					
						
							|  |  |  | 											/\/\/ \$dispose\$/g, | 
					
						
							|  |  |  | 											Template.asString([ | 
					
						
							|  |  |  | 												runtimeTemplate.forEach( | 
					
						
							|  |  |  | 													"chunkId", | 
					
						
							|  |  |  | 													"removedChunks", | 
					
						
							|  |  |  | 													"delete installedChunks[chunkId];" | 
					
						
							|  |  |  | 												) | 
					
						
							|  |  |  | 											]) | 
					
						
							|  |  |  | 										) | 
					
						
							|  |  |  | 								])});`,
 | 
					
						
							|  |  |  | 								"currentUpdateChunks = {};", | 
					
						
							|  |  |  | 								`currentUpdate = removedModules.reduce(${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 									"obj, key", | 
					
						
							|  |  |  | 									["obj[key] = false;", "return obj;"] | 
					
						
							|  |  |  | 								)}, {});`,
 | 
					
						
							|  |  |  | 								"currentUpdateRuntime = [];", | 
					
						
							|  |  |  | 								"currentUpdatedModulesList = updatedModulesList;", | 
					
						
							|  |  |  | 								runtimeTemplate.forEach("chunkId", "chunkIds", [ | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 									`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId] !== undefined) {`, | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 									Template.indent(["promises.push(loadUpdateChunk(chunkId));"]), | 
					
						
							|  |  |  | 									"}", | 
					
						
							|  |  |  | 									"currentUpdateChunks[chunkId] = true;" | 
					
						
							|  |  |  | 								]) | 
					
						
							|  |  |  | 							] | 
					
						
							|  |  |  | 						)};`
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 				  ]) | 
					
						
							|  |  |  | 				: "// no HMR", | 
					
						
							|  |  |  | 			"", | 
					
						
							|  |  |  | 			withHmrManifest | 
					
						
							|  |  |  | 				? Template.asString([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						`${ | 
					
						
							|  |  |  | 							RuntimeGlobals.hmrDownloadManifest | 
					
						
							|  |  |  | 						} = ${runtimeTemplate.basicFunction("", [ | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 							'if (typeof fetch === "undefined") throw new Error("No browser support: need fetch API");', | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 							`return fetch(${RuntimeGlobals.publicPath} + ${ | 
					
						
							|  |  |  | 								RuntimeGlobals.getUpdateManifestFilename | 
					
						
							|  |  |  | 							}()).then(${runtimeTemplate.basicFunction("response", [ | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								"if(response.status === 404) return; // no update available", | 
					
						
							|  |  |  | 								'if(!response.ok) throw new Error("Failed to fetch update manifest " + response.statusText);', | 
					
						
							|  |  |  | 								"return response.json();" | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 							])});`
 | 
					
						
							|  |  |  | 						])};`
 | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 				  ]) | 
					
						
							|  |  |  | 				: "// no HMR manifest", | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 			"", | 
					
						
							|  |  |  | 			withDefer | 
					
						
							|  |  |  | 				? Template.asString([ | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						`var checkDeferredModules = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 							"", | 
					
						
							|  |  |  | 							"" | 
					
						
							|  |  |  | 						)};`,
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 						"function checkDeferredModulesImpl() {", | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							|  |  |  | 							"var result;", | 
					
						
							|  |  |  | 							"for(var i = 0; i < deferredModules.length; i++) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							|  |  |  | 								"var deferredModule = deferredModules[i];", | 
					
						
							|  |  |  | 								"var fulfilled = true;", | 
					
						
							|  |  |  | 								"for(var j = 1; j < deferredModule.length; j++) {", | 
					
						
							|  |  |  | 								Template.indent([ | 
					
						
							|  |  |  | 									"var depId = deferredModule[j];", | 
					
						
							|  |  |  | 									"if(installedChunks[depId] !== 0) fulfilled = false;" | 
					
						
							|  |  |  | 								]), | 
					
						
							|  |  |  | 								"}", | 
					
						
							|  |  |  | 								"if(fulfilled) {", | 
					
						
							|  |  |  | 								Template.indent([ | 
					
						
							|  |  |  | 									"deferredModules.splice(i--, 1);", | 
					
						
							|  |  |  | 									"result = " + | 
					
						
							|  |  |  | 										"__webpack_require__(" + | 
					
						
							|  |  |  | 										`${RuntimeGlobals.entryModuleId} = deferredModule[0]);` | 
					
						
							|  |  |  | 								]), | 
					
						
							|  |  |  | 								"}" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 							"if(deferredModules.length === 0) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							|  |  |  | 								`${RuntimeGlobals.startup}();`, | 
					
						
							|  |  |  | 								`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 									"", | 
					
						
							|  |  |  | 									"" | 
					
						
							|  |  |  | 								)}`
 | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 							"return result;" | 
					
						
							|  |  |  | 						]), | 
					
						
							|  |  |  | 						"}", | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction("", [ | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 							"// reset startup function so it can be called again when more startup code is added", | 
					
						
							|  |  |  | 							`${RuntimeGlobals.startup} = ${runtimeTemplate.basicFunction( | 
					
						
							|  |  |  | 								"", | 
					
						
							|  |  |  | 								"" | 
					
						
							|  |  |  | 							)}`,
 | 
					
						
							|  |  |  | 							"jsonpArray = jsonpArray.slice();", | 
					
						
							|  |  |  | 							"for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);", | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 							"return (checkDeferredModules = checkDeferredModulesImpl)();" | 
					
						
							| 
									
										
										
										
											2019-08-27 02:21:07 +08:00
										 |  |  | 						])};`
 | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 				  ]) | 
					
						
							| 
									
										
										
										
											2019-12-19 18:53:54 +08:00
										 |  |  | 				: "// no deferred startup", | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 			"", | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 			withDefer || withLoading | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 				? Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 						"// install a JSONP callback for chunk loading", | 
					
						
							|  |  |  | 						"function webpackJsonpCallback(data) {", | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							|  |  |  | 							"var chunkIds = data[0];", | 
					
						
							|  |  |  | 							"var moreModules = data[1];", | 
					
						
							|  |  |  | 							withDefer ? "var executeModules = data[2];" : "", | 
					
						
							|  |  |  | 							"var runtime = data[3];", | 
					
						
							|  |  |  | 							'// add "moreModules" to the modules object,', | 
					
						
							|  |  |  | 							'// then flag all "chunkIds" as loaded and fire callback', | 
					
						
							|  |  |  | 							"var moduleId, chunkId, i = 0, resolves = [];", | 
					
						
							|  |  |  | 							"for(;i < chunkIds.length; i++) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							|  |  |  | 								"chunkId = chunkIds[i];", | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 								`if(${RuntimeGlobals.hasOwnProperty}(installedChunks, chunkId) && installedChunks[chunkId]) {`, | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								Template.indent("resolves.push(installedChunks[chunkId][0]);"), | 
					
						
							|  |  |  | 								"}", | 
					
						
							|  |  |  | 								"installedChunks[chunkId] = 0;" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							"for(moduleId in moreModules) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							| 
									
										
										
										
											2019-12-02 22:59:37 +08:00
										 |  |  | 								`if(${RuntimeGlobals.hasOwnProperty}(moreModules, moduleId)) {`, | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								Template.indent( | 
					
						
							| 
									
										
										
										
											2019-06-13 16:51:12 +08:00
										 |  |  | 									`${RuntimeGlobals.moduleFactories}[moduleId] = moreModules[moduleId];` | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 								), | 
					
						
							|  |  |  | 								"}" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							| 
									
										
										
										
											2018-11-29 21:13:02 +08:00
										 |  |  | 							"if(runtime) runtime(__webpack_require__);", | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 							"if(parentJsonpFunction) parentJsonpFunction(data);", | 
					
						
							|  |  |  | 							"while(resolves.length) {", | 
					
						
							|  |  |  | 							Template.indent("resolves.shift()();"), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							withDefer | 
					
						
							|  |  |  | 								? Template.asString([ | 
					
						
							|  |  |  | 										"", | 
					
						
							|  |  |  | 										"// add entry modules from loaded chunk to deferred list", | 
					
						
							|  |  |  | 										"if(executeModules) deferredModules.push.apply(deferredModules, executeModules);", | 
					
						
							|  |  |  | 										"", | 
					
						
							|  |  |  | 										"// run deferred modules when all chunks ready", | 
					
						
							|  |  |  | 										"return checkDeferredModules();" | 
					
						
							|  |  |  | 								  ]) | 
					
						
							|  |  |  | 								: "" | 
					
						
							|  |  |  | 						]), | 
					
						
							|  |  |  | 						"};", | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						`var jsonpArray = ${jsonpObject} = ${jsonpObject} || [];`, | 
					
						
							|  |  |  | 						"var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);", | 
					
						
							|  |  |  | 						"jsonpArray.push = webpackJsonpCallback;", | 
					
						
							|  |  |  | 						"var parentJsonpFunction = oldJsonpFunction;" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 				  ]) | 
					
						
							| 
									
										
										
										
											2018-11-28 20:07:40 +08:00
										 |  |  | 				: "// no jsonp function" | 
					
						
							| 
									
										
										
										
											2018-11-23 16:37:33 +08:00
										 |  |  | 		]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = JsonpChunkLoadingRuntimeModule; |