| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { SyncWaterfallHook } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | const Template = require("../Template"); | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | class JsonpMainTemplatePlugin { | 
					
						
							|  |  |  | 	apply(mainTemplate) { | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 		const needChunkOnDemandLoadingCode = chunk => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const chunkGroup of chunk.groupsIterable) { | 
					
						
							|  |  |  | 				if (chunkGroup.getNumberOfChildren() > 0) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		const needChunkLoadingCode = chunk => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const chunkGroup of chunk.groupsIterable) { | 
					
						
							|  |  |  | 				if (chunkGroup.chunks.length > 1) return true; | 
					
						
							|  |  |  | 				if (chunkGroup.getNumberOfChildren() > 0) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		const needEntryDeferringCode = chunk => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			for (const chunkGroup of chunk.groupsIterable) { | 
					
						
							|  |  |  | 				if (chunkGroup.chunks.length > 1) return true; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 		const needPrefetchingCode = chunk => { | 
					
						
							|  |  |  | 			const allPrefetchChunks = chunk.getChildIdsByOrdersMap(true).prefetch; | 
					
						
							|  |  |  | 			return allPrefetchChunks && Object.keys(allPrefetchChunks).length; | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		// TODO refactor this
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		if (!mainTemplate.hooks.jsonpScript) { | 
					
						
							|  |  |  | 			mainTemplate.hooks.jsonpScript = new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"chunk", | 
					
						
							|  |  |  | 				"hash" | 
					
						
							|  |  |  | 			]); | 
					
						
							| 
									
										
										
										
											2017-12-23 14:13:13 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		if (!mainTemplate.hooks.linkPreload) { | 
					
						
							|  |  |  | 			mainTemplate.hooks.linkPreload = new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"chunk", | 
					
						
							|  |  |  | 				"hash" | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (!mainTemplate.hooks.linkPrefetch) { | 
					
						
							|  |  |  | 			mainTemplate.hooks.linkPrefetch = new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"chunk", | 
					
						
							|  |  |  | 				"hash" | 
					
						
							|  |  |  | 			]); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-12-23 14:13:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		const getScriptSrcPath = (hash, chunk, chunkIdExpression) => { | 
					
						
							|  |  |  | 			const chunkFilename = mainTemplate.outputOptions.chunkFilename; | 
					
						
							|  |  |  | 			const chunkMaps = chunk.getChunkMaps(); | 
					
						
							|  |  |  | 			return mainTemplate.getAssetPath(JSON.stringify(chunkFilename), { | 
					
						
							|  |  |  | 				hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 				hashWithLength: length => | 
					
						
							|  |  |  | 					`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, | 
					
						
							|  |  |  | 				chunk: { | 
					
						
							|  |  |  | 					id: `" + ${chunkIdExpression} + "`, | 
					
						
							|  |  |  | 					hash: `" + ${JSON.stringify( | 
					
						
							|  |  |  | 						chunkMaps.hash | 
					
						
							|  |  |  | 					)}[${chunkIdExpression}] + "`,
 | 
					
						
							|  |  |  | 					hashWithLength(length) { | 
					
						
							|  |  |  | 						const shortChunkHashMap = Object.create(null); | 
					
						
							|  |  |  | 						for (const chunkId of Object.keys(chunkMaps.hash)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 							if (typeof chunkMaps.hash[chunkId] === "string") { | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 								shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr( | 
					
						
							|  |  |  | 									0, | 
					
						
							|  |  |  | 									length | 
					
						
							|  |  |  | 								); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 							} | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						} | 
					
						
							|  |  |  | 						return `" + ${JSON.stringify( | 
					
						
							|  |  |  | 							shortChunkHashMap | 
					
						
							|  |  |  | 						)}[${chunkIdExpression}] + "`;
 | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					name: `" + (${JSON.stringify( | 
					
						
							|  |  |  | 						chunkMaps.name | 
					
						
							|  |  |  | 					)}[${chunkIdExpression}]||${chunkIdExpression}) + "`,
 | 
					
						
							|  |  |  | 					contentHash: { | 
					
						
							|  |  |  | 						javascript: `" + ${JSON.stringify( | 
					
						
							|  |  |  | 							chunkMaps.contentHash.javascript | 
					
						
							|  |  |  | 						)}[${chunkIdExpression}] + "`
 | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					contentHashWithLength: { | 
					
						
							|  |  |  | 						javascript: length => { | 
					
						
							|  |  |  | 							const shortContentHashMap = {}; | 
					
						
							|  |  |  | 							const contentHash = chunkMaps.contentHash.javascript; | 
					
						
							|  |  |  | 							for (const chunkId of Object.keys(contentHash)) { | 
					
						
							|  |  |  | 								if (typeof contentHash[chunkId] === "string") { | 
					
						
							|  |  |  | 									shortContentHashMap[chunkId] = contentHash[chunkId].substr( | 
					
						
							|  |  |  | 										0, | 
					
						
							|  |  |  | 										length | 
					
						
							|  |  |  | 									); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 							return `" + ${JSON.stringify( | 
					
						
							|  |  |  | 								shortContentHashMap | 
					
						
							|  |  |  | 							)}[${chunkIdExpression}] + "`;
 | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				contentHashType: "javascript" | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		mainTemplate.hooks.localVars.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			(source, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2018-05-04 16:43:49 +08:00
										 |  |  | 				const extraCode = []; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (needChunkLoadingCode(chunk)) { | 
					
						
							| 
									
										
										
										
											2018-05-04 16:43:49 +08:00
										 |  |  | 					extraCode.push( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"", | 
					
						
							|  |  |  | 						"// object to store loaded and loading chunks", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						"// undefined = chunk not loaded, null = chunk preloaded/prefetched", | 
					
						
							|  |  |  | 						"// Promise = chunk loading, 0 = chunk loaded", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"var installedChunks = {", | 
					
						
							|  |  |  | 						Template.indent( | 
					
						
							|  |  |  | 							chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n") | 
					
						
							|  |  |  | 						), | 
					
						
							|  |  |  | 						"};", | 
					
						
							| 
									
										
										
										
											2018-05-04 16:43:49 +08:00
										 |  |  | 						"", | 
					
						
							|  |  |  | 						needEntryDeferringCode(chunk) ? "var deferredModules = [];" : "" | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (needChunkOnDemandLoadingCode(chunk)) { | 
					
						
							|  |  |  | 					extraCode.push( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						"// script path function", | 
					
						
							|  |  |  | 						"function jsonpScriptSrc(chunkId) {", | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							|  |  |  | 							`return ${mainTemplate.requireFn}.p + ${getScriptSrcPath( | 
					
						
							|  |  |  | 								hash, | 
					
						
							|  |  |  | 								chunk, | 
					
						
							|  |  |  | 								"chunkId" | 
					
						
							|  |  |  | 							)}`
 | 
					
						
							|  |  |  | 						]), | 
					
						
							| 
									
										
										
										
											2018-05-04 16:43:49 +08:00
										 |  |  | 						"}" | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-05-04 16:43:49 +08:00
										 |  |  | 				if (extraCode.length === 0) return source; | 
					
						
							|  |  |  | 				return Template.asString([source, ...extraCode]); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		mainTemplate.hooks.jsonpScript.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(_, chunk, hash) => { | 
					
						
							|  |  |  | 				const crossOriginLoading = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.crossOriginLoading; | 
					
						
							|  |  |  | 				const chunkLoadTimeout = mainTemplate.outputOptions.chunkLoadTimeout; | 
					
						
							|  |  |  | 				const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType; | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 				return Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					"var script = document.createElement('script');", | 
					
						
							| 
									
										
										
										
											2018-05-28 15:58:17 +08:00
										 |  |  | 					"var onScriptComplete;", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					jsonpScriptType | 
					
						
							|  |  |  | 						? `script.type = ${JSON.stringify(jsonpScriptType)};` | 
					
						
							|  |  |  | 						: "", | 
					
						
							|  |  |  | 					"script.charset = 'utf-8';", | 
					
						
							| 
									
										
										
										
											2018-03-18 19:44:32 +08:00
										 |  |  | 					`script.timeout = ${chunkLoadTimeout / 1000};`, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					crossOriginLoading | 
					
						
							|  |  |  | 						? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | 
					
						
							|  |  |  | 						: "", | 
					
						
							|  |  |  | 					`if (${mainTemplate.requireFn}.nc) {`, | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 					Template.indent( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);` | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 					), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					"}", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					"script.src = jsonpScriptSrc(chunkId);", | 
					
						
							| 
									
										
										
										
											2018-05-28 15:58:17 +08:00
										 |  |  | 					"onScriptComplete = function (event) {", | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 					Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"// avoid mem leaks in IE.", | 
					
						
							|  |  |  | 						"script.onerror = script.onload = null;", | 
					
						
							|  |  |  | 						"clearTimeout(timeout);", | 
					
						
							|  |  |  | 						"var chunk = installedChunks[chunkId];", | 
					
						
							|  |  |  | 						"if(chunk !== 0) {", | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							"if(chunk) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							|  |  |  | 								"var errorType = event && (event.type === 'load' ? 'missing' : event.type);", | 
					
						
							|  |  |  | 								"var realSrc = event && event.target && event.target.src;", | 
					
						
							|  |  |  | 								"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');", | 
					
						
							|  |  |  | 								"error.type = errorType;", | 
					
						
							|  |  |  | 								"error.request = realSrc;", | 
					
						
							|  |  |  | 								"chunk[1](error);" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							"installedChunks[chunkId] = undefined;" | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 						]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"}" | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 					]), | 
					
						
							| 
									
										
										
										
											2018-05-06 16:36:28 +08:00
										 |  |  | 					"};", | 
					
						
							| 
									
										
										
										
											2018-05-28 15:58:17 +08:00
										 |  |  | 					"var timeout = setTimeout(function(){", | 
					
						
							|  |  |  | 					Template.indent([ | 
					
						
							|  |  |  | 						"onScriptComplete({ type: 'timeout', target: script });" | 
					
						
							|  |  |  | 					]), | 
					
						
							|  |  |  | 					`}, ${chunkLoadTimeout});`, | 
					
						
							| 
									
										
										
										
											2018-05-15 14:32:08 +08:00
										 |  |  | 					"script.onerror = script.onload = onScriptComplete;" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		mainTemplate.hooks.linkPreload.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(_, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2018-05-31 01:17:19 +08:00
										 |  |  | 				const crossOriginLoading = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.crossOriginLoading; | 
					
						
							|  |  |  | 				const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return Template.asString([ | 
					
						
							|  |  |  | 					"var link = document.createElement('link');", | 
					
						
							|  |  |  | 					jsonpScriptType | 
					
						
							|  |  |  | 						? `link.type = ${JSON.stringify(jsonpScriptType)};` | 
					
						
							|  |  |  | 						: "", | 
					
						
							|  |  |  | 					"link.charset = 'utf-8';", | 
					
						
							|  |  |  | 					crossOriginLoading | 
					
						
							|  |  |  | 						? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | 
					
						
							|  |  |  | 						: "", | 
					
						
							|  |  |  | 					`if (${mainTemplate.requireFn}.nc) {`, | 
					
						
							|  |  |  | 					Template.indent( | 
					
						
							|  |  |  | 						`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);` | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					"}", | 
					
						
							|  |  |  | 					'link.rel = "preload";', | 
					
						
							|  |  |  | 					'link.as = "script";', | 
					
						
							|  |  |  | 					"link.href = jsonpScriptSrc(chunkId);" | 
					
						
							|  |  |  | 				]); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.linkPrefetch.tap( | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			(_, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 				const crossOriginLoading = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.crossOriginLoading; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-31 01:17:19 +08:00
										 |  |  | 				return Template.asString([ | 
					
						
							|  |  |  | 					"var link = document.createElement('link');", | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 					crossOriginLoading | 
					
						
							|  |  |  | 						? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};` | 
					
						
							|  |  |  | 						: "", | 
					
						
							|  |  |  | 					`if (${mainTemplate.requireFn}.nc) {`, | 
					
						
							|  |  |  | 					Template.indent( | 
					
						
							|  |  |  | 						`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);` | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					"}", | 
					
						
							| 
									
										
										
										
											2018-05-31 01:17:19 +08:00
										 |  |  | 					'link.rel = "prefetch";', | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 					'link.as = "script";', | 
					
						
							| 
									
										
										
										
											2018-05-31 01:17:19 +08:00
										 |  |  | 					"link.href = jsonpScriptSrc(chunkId);" | 
					
						
							|  |  |  | 				]); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.requireEnsure.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin load", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			(source, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 				return Template.asString([ | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 					source, | 
					
						
							|  |  |  | 					"", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					"// JSONP chunk loading for javascript", | 
					
						
							|  |  |  | 					"", | 
					
						
							|  |  |  | 					"var installedChunkData = installedChunks[chunkId];", | 
					
						
							|  |  |  | 					'if(installedChunkData !== 0) { // 0 means "already installed".', | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 					Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"", | 
					
						
							|  |  |  | 						'// a Promise means "currently loading".', | 
					
						
							|  |  |  | 						"if(installedChunkData) {", | 
					
						
							|  |  |  | 						Template.indent(["promises.push(installedChunkData[2]);"]), | 
					
						
							|  |  |  | 						"} else {", | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							"// setup Promise in chunk cache", | 
					
						
							|  |  |  | 							"var promise = new Promise(function(resolve, reject) {", | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 							Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								"installedChunkData = installedChunks[chunkId] = [resolve, reject];" | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 							]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							"});", | 
					
						
							|  |  |  | 							"promises.push(installedChunkData[2] = promise);", | 
					
						
							|  |  |  | 							"", | 
					
						
							|  |  |  | 							"// start chunk loading", | 
					
						
							|  |  |  | 							"var head = document.getElementsByTagName('head')[0];", | 
					
						
							|  |  |  | 							mainTemplate.hooks.jsonpScript.call("", chunk, hash), | 
					
						
							|  |  |  | 							"head.appendChild(script);" | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 						]), | 
					
						
							|  |  |  | 						"}" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					]), | 
					
						
							|  |  |  | 					"}" | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 				]); | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 		mainTemplate.hooks.requireEnsure.tap( | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				name: "JsonpMainTemplatePlugin preload", | 
					
						
							|  |  |  | 				stage: 10 | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2018-04-17 00:00:34 +08:00
										 |  |  | 				const chunkMap = chunk.getChildIdsByOrdersMap().preload; | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 				if (!chunkMap || Object.keys(chunkMap).length === 0) return source; | 
					
						
							|  |  |  | 				return Template.asString([ | 
					
						
							|  |  |  | 					source, | 
					
						
							|  |  |  | 					"", | 
					
						
							|  |  |  | 					"// chunk preloadng for javascript", | 
					
						
							|  |  |  | 					"", | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 					`var chunkPreloadMap = ${JSON.stringify(chunkMap, null, "\t")};`, | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					"", | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 					"var chunkPreloadData = chunkPreloadMap[chunkId];", | 
					
						
							|  |  |  | 					"if(chunkPreloadData) {", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 						"var head = document.getElementsByTagName('head')[0];", | 
					
						
							|  |  |  | 						"chunkPreloadData.forEach(function(chunkId) {", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 							"if(installedChunks[chunkId] === undefined) {", | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 							Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 								"installedChunks[chunkId] = null;", | 
					
						
							|  |  |  | 								mainTemplate.hooks.linkPreload.call("", chunk, hash), | 
					
						
							|  |  |  | 								"head.appendChild(link);" | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 							]), | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 							"}" | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 						]), | 
					
						
							| 
									
										
										
										
											2018-04-17 01:35:02 +08:00
										 |  |  | 						"});" | 
					
						
							| 
									
										
										
										
											2018-04-16 16:27:22 +08:00
										 |  |  | 					]), | 
					
						
							|  |  |  | 					"}" | 
					
						
							|  |  |  | 				]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		mainTemplate.hooks.requireExtensions.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk) => { | 
					
						
							|  |  |  | 				if (!needChunkOnDemandLoadingCode(chunk)) return source; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 				return Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					source, | 
					
						
							| 
									
										
										
										
											2017-04-23 00:59:15 +08:00
										 |  |  | 					"", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					"// on error function for async loading", | 
					
						
							|  |  |  | 					`${ | 
					
						
							|  |  |  | 						mainTemplate.requireFn | 
					
						
							|  |  |  | 					}.oe = function(err) { console.error(err); throw err; };`
 | 
					
						
							| 
									
										
										
										
											2017-04-23 00:59:15 +08:00
										 |  |  | 				]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.bootstrap.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							|  |  |  | 				if (needChunkLoadingCode(chunk)) { | 
					
						
							|  |  |  | 					const withDefer = needEntryDeferringCode(chunk); | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 					const withPrefetch = needPrefetchingCode(chunk); | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					return Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						source, | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						"// install a JSONP callback for chunk loading", | 
					
						
							|  |  |  | 						"function webpackJsonpCallback(data) {", | 
					
						
							|  |  |  | 						Template.indent([ | 
					
						
							|  |  |  | 							"var chunkIds = data[0];", | 
					
						
							| 
									
										
										
										
											2018-03-21 13:48:08 +08:00
										 |  |  | 							"var moreModules = data[1];", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							withDefer ? "var executeModules = data[2];" : "", | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 							withPrefetch ? "var prefetchChunks = data[3] || [];" : "", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							'// 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];", | 
					
						
							|  |  |  | 								"if(installedChunks[chunkId]) {", | 
					
						
							|  |  |  | 								Template.indent("resolves.push(installedChunks[chunkId][0]);"), | 
					
						
							|  |  |  | 								"}", | 
					
						
							|  |  |  | 								"installedChunks[chunkId] = 0;" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							"for(moduleId in moreModules) {", | 
					
						
							|  |  |  | 							Template.indent([ | 
					
						
							|  |  |  | 								"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {", | 
					
						
							|  |  |  | 								Template.indent( | 
					
						
							|  |  |  | 									mainTemplate.renderAddModule( | 
					
						
							|  |  |  | 										hash, | 
					
						
							|  |  |  | 										chunk, | 
					
						
							|  |  |  | 										"moduleId", | 
					
						
							|  |  |  | 										"moreModules[moduleId]" | 
					
						
							|  |  |  | 									) | 
					
						
							|  |  |  | 								), | 
					
						
							|  |  |  | 								"}" | 
					
						
							|  |  |  | 							]), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							"if(parentJsonpFunction) parentJsonpFunction(data);", | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 							withPrefetch | 
					
						
							|  |  |  | 								? Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 										"// chunk prefetching for javascript", | 
					
						
							|  |  |  | 										"var head = document.getElementsByTagName('head')[0];", | 
					
						
							|  |  |  | 										"prefetchChunks.forEach(function(chunkId) {", | 
					
						
							|  |  |  | 										Template.indent([ | 
					
						
							|  |  |  | 											"if(installedChunks[chunkId] === undefined) {", | 
					
						
							|  |  |  | 											Template.indent([ | 
					
						
							|  |  |  | 												"installedChunks[chunkId] = null;", | 
					
						
							|  |  |  | 												mainTemplate.hooks.linkPrefetch.call("", chunk, hash), | 
					
						
							|  |  |  | 												"head.appendChild(link);" | 
					
						
							|  |  |  | 											]), | 
					
						
							|  |  |  | 											"}" | 
					
						
							|  |  |  | 										]), | 
					
						
							|  |  |  | 										"});" | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 								  ]) | 
					
						
							|  |  |  | 								: "", | 
					
						
							| 
									
										
										
										
											2018-06-05 00:02:17 +08:00
										 |  |  | 							"while(resolves.length) {", | 
					
						
							|  |  |  | 							Template.indent("resolves.shift()();"), | 
					
						
							|  |  |  | 							"}", | 
					
						
							|  |  |  | 							withDefer | 
					
						
							|  |  |  | 								? Template.asString([ | 
					
						
							|  |  |  | 										"", | 
					
						
							|  |  |  | 										"// add entry modules from loaded chunk to deferred list", | 
					
						
							|  |  |  | 										"deferredModules.push.apply(deferredModules, executeModules || []);", | 
					
						
							|  |  |  | 										"", | 
					
						
							|  |  |  | 										"// run deferred modules when all chunks ready", | 
					
						
							|  |  |  | 										"return checkDeferredModules();" | 
					
						
							|  |  |  | 								  ]) | 
					
						
							|  |  |  | 								: "" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						]), | 
					
						
							|  |  |  | 						"};", | 
					
						
							|  |  |  | 						withDefer | 
					
						
							|  |  |  | 							? Template.asString([ | 
					
						
							|  |  |  | 									"function checkDeferredModules() {", | 
					
						
							|  |  |  | 									Template.indent([ | 
					
						
							|  |  |  | 										"var result;", | 
					
						
							|  |  |  | 										"for(var i = 0; i < deferredModules.length; i++) {", | 
					
						
							|  |  |  | 										Template.indent([ | 
					
						
							|  |  |  | 											"var deferredModule = deferredModules[i];", | 
					
						
							| 
									
										
										
										
											2018-03-13 16:45:23 +08:00
										 |  |  | 											"var fulfilled = true;", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 											"for(var j = 1; j < deferredModule.length; j++) {", | 
					
						
							|  |  |  | 											Template.indent([ | 
					
						
							|  |  |  | 												"var depId = deferredModule[j];", | 
					
						
							| 
									
										
										
										
											2018-03-13 16:45:23 +08:00
										 |  |  | 												"if(installedChunks[depId] !== 0) fulfilled = false;" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 											]), | 
					
						
							|  |  |  | 											"}", | 
					
						
							| 
									
										
										
										
											2018-03-13 16:45:23 +08:00
										 |  |  | 											"if(fulfilled) {", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 											Template.indent([ | 
					
						
							|  |  |  | 												"deferredModules.splice(i--, 1);", | 
					
						
							|  |  |  | 												"result = " + | 
					
						
							|  |  |  | 													mainTemplate.requireFn + | 
					
						
							|  |  |  | 													"(" + | 
					
						
							|  |  |  | 													mainTemplate.requireFn + | 
					
						
							|  |  |  | 													".s = deferredModule[0]);" | 
					
						
							|  |  |  | 											]), | 
					
						
							|  |  |  | 											"}" | 
					
						
							|  |  |  | 										]), | 
					
						
							|  |  |  | 										"}", | 
					
						
							|  |  |  | 										"return result;" | 
					
						
							|  |  |  | 									]), | 
					
						
							|  |  |  | 									"}" | 
					
						
							| 
									
										
										
										
											2018-03-26 22:56:10 +08:00
										 |  |  | 							  ]) | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							: "" | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					]); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 				return source; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.beforeStartup.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							|  |  |  | 				if (needChunkLoadingCode(chunk)) { | 
					
						
							|  |  |  | 					var jsonpFunction = mainTemplate.outputOptions.jsonpFunction; | 
					
						
							|  |  |  | 					var globalObject = mainTemplate.outputOptions.globalObject; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					return Template.asString([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						`var jsonpArray = ${globalObject}[${JSON.stringify( | 
					
						
							|  |  |  | 							jsonpFunction | 
					
						
							|  |  |  | 						)}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`,
 | 
					
						
							|  |  |  | 						"var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);", | 
					
						
							|  |  |  | 						"jsonpArray.push = webpackJsonpCallback;", | 
					
						
							|  |  |  | 						"jsonpArray = jsonpArray.slice();", | 
					
						
							|  |  |  | 						"for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);", | 
					
						
							|  |  |  | 						"var parentJsonpFunction = oldJsonpFunction;", | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						source | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 					]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return source; | 
					
						
							| 
									
										
										
										
											2018-01-20 00:06:59 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-06-05 00:02:17 +08:00
										 |  |  | 		mainTemplate.hooks.beforeStartup.tap( | 
					
						
							| 
									
										
										
										
											2018-05-31 05:36:53 +08:00
										 |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							| 
									
										
										
										
											2018-06-02 01:51:39 +08:00
										 |  |  | 				const prefetchChunks = chunk.getChildIdsByOrders().prefetch; | 
					
						
							|  |  |  | 				if ( | 
					
						
							|  |  |  | 					needChunkLoadingCode(chunk) && | 
					
						
							|  |  |  | 					prefetchChunks && | 
					
						
							|  |  |  | 					prefetchChunks.length | 
					
						
							|  |  |  | 				) { | 
					
						
							| 
									
										
										
										
											2018-05-31 05:36:53 +08:00
										 |  |  | 					return Template.asString([ | 
					
						
							|  |  |  | 						source, | 
					
						
							| 
									
										
										
										
											2018-06-04 23:49:55 +08:00
										 |  |  | 						`webpackJsonpCallback([[], {}, 0, ${JSON.stringify( | 
					
						
							|  |  |  | 							prefetchChunks | 
					
						
							|  |  |  | 						)}]);`
 | 
					
						
							| 
									
										
										
										
											2018-05-31 05:36:53 +08:00
										 |  |  | 					]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return source; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		mainTemplate.hooks.startup.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							|  |  |  | 				if (needEntryDeferringCode(chunk)) { | 
					
						
							|  |  |  | 					if (chunk.hasEntryModule()) { | 
					
						
							|  |  |  | 						const entries = [chunk.entryModule].filter(Boolean).map(m => | 
					
						
							|  |  |  | 							[m.id].concat( | 
					
						
							|  |  |  | 								Array.from(chunk.groupsIterable)[0] | 
					
						
							|  |  |  | 									.chunks.filter(c => c !== chunk) | 
					
						
							|  |  |  | 									.map(c => c.id) | 
					
						
							|  |  |  | 							) | 
					
						
							|  |  |  | 						); | 
					
						
							|  |  |  | 						return Template.asString([ | 
					
						
							|  |  |  | 							"// add entry module to deferred list", | 
					
						
							|  |  |  | 							`deferredModules.push(${entries | 
					
						
							|  |  |  | 								.map(e => JSON.stringify(e)) | 
					
						
							|  |  |  | 								.join(", ")});`,
 | 
					
						
							|  |  |  | 							"// run deferred modules when ready", | 
					
						
							| 
									
										
										
										
											2018-06-05 00:02:17 +08:00
										 |  |  | 							"return checkDeferredModules();" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						]); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						return Template.asString([ | 
					
						
							|  |  |  | 							"// run deferred modules from other chunks", | 
					
						
							|  |  |  | 							"checkDeferredModules();" | 
					
						
							|  |  |  | 						]); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				return source; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.hotBootstrap.tap( | 
					
						
							|  |  |  | 			"JsonpMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk, hash) => { | 
					
						
							|  |  |  | 				const globalObject = mainTemplate.outputOptions.globalObject; | 
					
						
							|  |  |  | 				const hotUpdateChunkFilename = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.hotUpdateChunkFilename; | 
					
						
							|  |  |  | 				const hotUpdateMainFilename = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.hotUpdateMainFilename; | 
					
						
							|  |  |  | 				const crossOriginLoading = | 
					
						
							|  |  |  | 					mainTemplate.outputOptions.crossOriginLoading; | 
					
						
							|  |  |  | 				const hotUpdateFunction = mainTemplate.outputOptions.hotUpdateFunction; | 
					
						
							|  |  |  | 				const currentHotUpdateChunkFilename = mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 					JSON.stringify(hotUpdateChunkFilename), | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 						hashWithLength: length => | 
					
						
							|  |  |  | 							`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, | 
					
						
							|  |  |  | 						chunk: { | 
					
						
							|  |  |  | 							id: '" + chunkId + "' | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				const currentHotUpdateMainFilename = mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 					JSON.stringify(hotUpdateMainFilename), | 
					
						
							|  |  |  | 					{ | 
					
						
							|  |  |  | 						hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 						hashWithLength: length => | 
					
						
							|  |  |  | 							`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "` | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 				const runtimeSource = Template.getFunctionContent( | 
					
						
							|  |  |  | 					require("./JsonpMainTemplate.runtime.js") | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 					.replace(/\/\/\$semicolon/g, ";") | 
					
						
							|  |  |  | 					.replace(/\$require\$/g, mainTemplate.requireFn) | 
					
						
							|  |  |  | 					.replace( | 
					
						
							|  |  |  | 						/\$crossOriginLoading\$/g, | 
					
						
							|  |  |  | 						crossOriginLoading | 
					
						
							|  |  |  | 							? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}` | 
					
						
							|  |  |  | 							: "" | 
					
						
							|  |  |  | 					) | 
					
						
							|  |  |  | 					.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) | 
					
						
							|  |  |  | 					.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename) | 
					
						
							|  |  |  | 					.replace(/\$hash\$/g, JSON.stringify(hash)); | 
					
						
							|  |  |  | 				return `${source}
 | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | function hotDisposeChunk(chunkId) { | 
					
						
							|  |  |  | 	delete installedChunks[chunkId]; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | var parentHotUpdateCallback = ${globalObject}[${JSON.stringify( | 
					
						
							|  |  |  | 					hotUpdateFunction | 
					
						
							|  |  |  | 				)}]; | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | ${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2017-12-23 14:13:13 +08:00
										 |  |  | 		mainTemplate.hooks.hash.tap("JsonpMainTemplatePlugin", hash => { | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 			hash.update("jsonp"); | 
					
						
							| 
									
										
										
										
											2017-04-23 00:59:15 +08:00
										 |  |  | 			hash.update("5"); | 
					
						
							| 
									
										
										
										
											2017-12-28 01:46:37 +08:00
										 |  |  | 			hash.update(`${mainTemplate.outputOptions.globalObject}`); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			hash.update(`${mainTemplate.outputOptions.chunkFilename}`); | 
					
						
							|  |  |  | 			hash.update(`${mainTemplate.outputOptions.jsonpFunction}`); | 
					
						
							|  |  |  | 			hash.update(`${mainTemplate.outputOptions.hotUpdateFunction}`); | 
					
						
							| 
									
										
										
										
											2017-02-23 00:54:16 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = JsonpMainTemplatePlugin; |