| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2018-07-30 23:08:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | const HotModuleReplacementPlugin = require("../HotModuleReplacementPlugin"); | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | const Template = require("../Template"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | /** @typedef {import("../MainTemplate")} MainTemplate */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | module.exports = class NodeMainTemplatePlugin { | 
					
						
							|  |  |  | 	constructor(asyncChunkLoading) { | 
					
						
							|  |  |  | 		this.asyncChunkLoading = asyncChunkLoading; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {MainTemplate} mainTemplate the main template | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | 	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-06-19 16:35:05 +08:00
										 |  |  | 		const asyncChunkLoading = this.asyncChunkLoading; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		mainTemplate.hooks.localVars.tap( | 
					
						
							|  |  |  | 			"NodeMainTemplatePlugin", | 
					
						
							|  |  |  | 			(source, chunk) => { | 
					
						
							|  |  |  | 				if (needChunkOnDemandLoadingCode(chunk)) { | 
					
						
							|  |  |  | 					return Template.asString([ | 
					
						
							|  |  |  | 						source, | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						"// object to store loaded chunks", | 
					
						
							|  |  |  | 						'// "0" means "already loaded"', | 
					
						
							|  |  |  | 						"var installedChunks = {", | 
					
						
							| 
									
										
										
										
											2018-03-06 16:24:07 +08:00
										 |  |  | 						Template.indent( | 
					
						
							|  |  |  | 							chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n") | 
					
						
							|  |  |  | 						), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"};" | 
					
						
							|  |  |  | 					]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return source; | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.requireExtensions.tap( | 
					
						
							|  |  |  | 			"NodeMainTemplatePlugin", | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			(source, { chunk }) => { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				if (needChunkOnDemandLoadingCode(chunk)) { | 
					
						
							|  |  |  | 					return Template.asString([ | 
					
						
							|  |  |  | 						source, | 
					
						
							|  |  |  | 						"", | 
					
						
							| 
									
										
										
										
											2018-02-26 10:50:05 +08:00
										 |  |  | 						"// uncaught error handler for webpack runtime", | 
					
						
							| 
									
										
										
										
											2018-11-05 20:13:05 +08:00
										 |  |  | 						`__webpack_require__.oe = function(err) {`, | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 						Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							"process.nextTick(function() {", | 
					
						
							|  |  |  | 							Template.indent( | 
					
						
							|  |  |  | 								"throw err; // catch this error by using import().catch()" | 
					
						
							|  |  |  | 							), | 
					
						
							|  |  |  | 							"});" | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 						]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						"};" | 
					
						
							|  |  |  | 					]); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return source; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 		mainTemplate.hooks.requireEnsure.tap( | 
					
						
							|  |  |  | 			"NodeMainTemplatePlugin", | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 			(source, chunkIdExpression, renderContext) => { | 
					
						
							|  |  |  | 				// TODO use chunkIdExpression instead of hard-coded chunkId
 | 
					
						
							|  |  |  | 				const { chunk, hash } = renderContext; | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 				const chunkFilename = mainTemplate.outputOptions.chunkFilename; | 
					
						
							|  |  |  | 				const chunkMaps = chunk.getChunkMaps(); | 
					
						
							|  |  |  | 				const insertMoreModules = [ | 
					
						
							|  |  |  | 					"var moreModules = chunk.modules, chunkIds = chunk.ids;", | 
					
						
							|  |  |  | 					"for(var moduleId in moreModules) {", | 
					
						
							|  |  |  | 					Template.indent( | 
					
						
							|  |  |  | 						mainTemplate.renderAddModule( | 
					
						
							|  |  |  | 							"moduleId", | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | 							"moreModules[moduleId]", | 
					
						
							|  |  |  | 							renderContext | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 						) | 
					
						
							|  |  |  | 					), | 
					
						
							|  |  |  | 					"}" | 
					
						
							|  |  |  | 				]; | 
					
						
							|  |  |  | 				if (asyncChunkLoading) { | 
					
						
							|  |  |  | 					return Template.asString([ | 
					
						
							|  |  |  | 						source, | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						"// ReadFile + VM.run 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
										 |  |  | 							'// array of [resolve, reject, promise] means "currently loading"', | 
					
						
							|  |  |  | 							"if(installedChunkData) {", | 
					
						
							|  |  |  | 							Template.indent(["promises.push(installedChunkData[2]);"]), | 
					
						
							|  |  |  | 							"} else {", | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 							Template.indent([ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								"// load the chunk and return promise to it", | 
					
						
							|  |  |  | 								"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];", | 
					
						
							| 
									
										
										
										
											2018-09-15 02:22:08 +08:00
										 |  |  | 									"var filename = require('path').join(__dirname, " + | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 										mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 											JSON.stringify(`/${chunkFilename}`), | 
					
						
							|  |  |  | 											{ | 
					
						
							|  |  |  | 												hash: `" + ${mainTemplate.renderCurrentHashCode( | 
					
						
							|  |  |  | 													hash | 
					
						
							|  |  |  | 												)} + "`,
 | 
					
						
							|  |  |  | 												hashWithLength: length => | 
					
						
							|  |  |  | 													`" + ${mainTemplate.renderCurrentHashCode( | 
					
						
							|  |  |  | 														hash, | 
					
						
							|  |  |  | 														length | 
					
						
							|  |  |  | 													)} + "`,
 | 
					
						
							|  |  |  | 												chunk: { | 
					
						
							|  |  |  | 													id: '" + chunkId + "', | 
					
						
							|  |  |  | 													hash: `" + ${JSON.stringify( | 
					
						
							|  |  |  | 														chunkMaps.hash | 
					
						
							|  |  |  | 													)}[chunkId] + "`,
 | 
					
						
							|  |  |  | 													hashWithLength: length => { | 
					
						
							|  |  |  | 														const shortChunkHashMap = {}; | 
					
						
							|  |  |  | 														for (const chunkId of Object.keys(chunkMaps.hash)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 															if (typeof chunkMaps.hash[chunkId] === "string") { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 																shortChunkHashMap[chunkId] = chunkMaps.hash[ | 
					
						
							|  |  |  | 																	chunkId | 
					
						
							|  |  |  | 																].substr(0, length); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 															} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 														} | 
					
						
							|  |  |  | 														return `" + ${JSON.stringify( | 
					
						
							|  |  |  | 															shortChunkHashMap | 
					
						
							|  |  |  | 														)}[chunkId] + "`;
 | 
					
						
							|  |  |  | 													}, | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 													contentHash: { | 
					
						
							|  |  |  | 														javascript: `" + ${JSON.stringify( | 
					
						
							|  |  |  | 															chunkMaps.contentHash.javascript | 
					
						
							|  |  |  | 														)}[chunkId] + "`
 | 
					
						
							|  |  |  | 													}, | 
					
						
							|  |  |  | 													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 | 
					
						
							|  |  |  | 															)}[chunkId] + "`;
 | 
					
						
							|  |  |  | 														} | 
					
						
							|  |  |  | 													}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 													name: `" + (${JSON.stringify( | 
					
						
							|  |  |  | 														chunkMaps.name | 
					
						
							|  |  |  | 													)}[chunkId]||chunkId) + "`
 | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 												}, | 
					
						
							|  |  |  | 												contentHashType: "javascript" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 											} | 
					
						
							|  |  |  | 										) + | 
					
						
							| 
									
										
										
										
											2018-09-15 02:22:08 +08:00
										 |  |  | 										");", | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									"require('fs').readFile(filename, 'utf-8',  function(err, content) {", | 
					
						
							|  |  |  | 									Template.indent( | 
					
						
							|  |  |  | 										[ | 
					
						
							|  |  |  | 											"if(err) return reject(err);", | 
					
						
							|  |  |  | 											"var chunk = {};", | 
					
						
							|  |  |  | 											"require('vm').runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)" + | 
					
						
							|  |  |  | 												"(chunk, require, require('path').dirname(filename), filename);" | 
					
						
							|  |  |  | 										] | 
					
						
							|  |  |  | 											.concat(insertMoreModules) | 
					
						
							|  |  |  | 											.concat([ | 
					
						
							|  |  |  | 												"var callbacks = [];", | 
					
						
							|  |  |  | 												"for(var i = 0; i < chunkIds.length; i++) {", | 
					
						
							|  |  |  | 												Template.indent([ | 
					
						
							|  |  |  | 													"if(installedChunks[chunkIds[i]])", | 
					
						
							|  |  |  | 													Template.indent([ | 
					
						
							|  |  |  | 														"callbacks = callbacks.concat(installedChunks[chunkIds[i]][0]);" | 
					
						
							|  |  |  | 													]), | 
					
						
							|  |  |  | 													"installedChunks[chunkIds[i]] = 0;" | 
					
						
							|  |  |  | 												]), | 
					
						
							|  |  |  | 												"}", | 
					
						
							|  |  |  | 												"for(i = 0; i < callbacks.length; i++)", | 
					
						
							|  |  |  | 												Template.indent("callbacks[i]();") | 
					
						
							|  |  |  | 											]) | 
					
						
							|  |  |  | 									), | 
					
						
							|  |  |  | 									"});" | 
					
						
							|  |  |  | 								]), | 
					
						
							|  |  |  | 								"});", | 
					
						
							|  |  |  | 								"promises.push(installedChunkData[2] = promise);" | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | 							]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 							"}" | 
					
						
							| 
									
										
										
										
											2017-11-12 01:48:29 +08:00
										 |  |  | 						]), | 
					
						
							|  |  |  | 						"}" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					]); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					const request = mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 						JSON.stringify(`./${chunkFilename}`), | 
					
						
							|  |  |  | 						{ | 
					
						
							|  |  |  | 							hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 							hashWithLength: length => | 
					
						
							|  |  |  | 								`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, | 
					
						
							|  |  |  | 							chunk: { | 
					
						
							|  |  |  | 								id: '" + chunkId + "', | 
					
						
							|  |  |  | 								hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`, | 
					
						
							|  |  |  | 								hashWithLength: length => { | 
					
						
							|  |  |  | 									const shortChunkHashMap = {}; | 
					
						
							|  |  |  | 									for (const chunkId of Object.keys(chunkMaps.hash)) { | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 										if (typeof chunkMaps.hash[chunkId] === "string") { | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 											shortChunkHashMap[chunkId] = chunkMaps.hash[ | 
					
						
							|  |  |  | 												chunkId | 
					
						
							|  |  |  | 											].substr(0, length); | 
					
						
							| 
									
										
										
										
											2018-05-29 20:50:40 +08:00
										 |  |  | 										} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 									} | 
					
						
							|  |  |  | 									return `" + ${JSON.stringify( | 
					
						
							|  |  |  | 										shortChunkHashMap | 
					
						
							|  |  |  | 									)}[chunkId] + "`;
 | 
					
						
							|  |  |  | 								}, | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 								contentHash: { | 
					
						
							|  |  |  | 									javascript: `" + ${JSON.stringify( | 
					
						
							|  |  |  | 										chunkMaps.contentHash.javascript | 
					
						
							|  |  |  | 									)}[chunkId] + "`
 | 
					
						
							|  |  |  | 								}, | 
					
						
							|  |  |  | 								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 | 
					
						
							|  |  |  | 										)}[chunkId] + "`;
 | 
					
						
							|  |  |  | 									} | 
					
						
							|  |  |  | 								}, | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								name: `" + (${JSON.stringify( | 
					
						
							|  |  |  | 									chunkMaps.name | 
					
						
							|  |  |  | 								)}[chunkId]||chunkId) + "`
 | 
					
						
							| 
									
										
										
										
											2018-03-23 02:52:11 +08:00
										 |  |  | 							}, | 
					
						
							|  |  |  | 							contentHashType: "javascript" | 
					
						
							| 
									
										
										
										
											2018-01-22 20:52:43 +08:00
										 |  |  | 						} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					); | 
					
						
							|  |  |  | 					return Template.asString([ | 
					
						
							|  |  |  | 						source, | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						"// require() chunk loading for javascript", | 
					
						
							|  |  |  | 						"", | 
					
						
							|  |  |  | 						'// "0" is the signal for "already loaded"', | 
					
						
							|  |  |  | 						"if(installedChunks[chunkId] !== 0) {", | 
					
						
							|  |  |  | 						Template.indent( | 
					
						
							|  |  |  | 							[`var chunk = require(${request});`] | 
					
						
							|  |  |  | 								.concat(insertMoreModules) | 
					
						
							|  |  |  | 								.concat([ | 
					
						
							|  |  |  | 									"for(var i = 0; i < chunkIds.length; i++)", | 
					
						
							|  |  |  | 									Template.indent("installedChunks[chunkIds[i]] = 0;") | 
					
						
							|  |  |  | 								]) | 
					
						
							|  |  |  | 						), | 
					
						
							|  |  |  | 						"}" | 
					
						
							|  |  |  | 					]); | 
					
						
							| 
									
										
										
										
											2014-11-02 19:48:15 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		); | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const { hotBootstrap } = HotModuleReplacementPlugin.getMainTemplateHooks( | 
					
						
							|  |  |  | 			mainTemplate | 
					
						
							|  |  |  | 		); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		hotBootstrap.tap("NodeMainTemplatePlugin", (source, chunk, hash) => { | 
					
						
							|  |  |  | 			const hotUpdateChunkFilename = | 
					
						
							|  |  |  | 				mainTemplate.outputOptions.hotUpdateChunkFilename; | 
					
						
							|  |  |  | 			const hotUpdateMainFilename = | 
					
						
							|  |  |  | 				mainTemplate.outputOptions.hotUpdateMainFilename; | 
					
						
							|  |  |  | 			const chunkMaps = chunk.getChunkMaps(); | 
					
						
							|  |  |  | 			const currentHotUpdateChunkFilename = mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 				JSON.stringify(hotUpdateChunkFilename), | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 					hashWithLength: length => | 
					
						
							|  |  |  | 						`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`, | 
					
						
							|  |  |  | 					chunk: { | 
					
						
							|  |  |  | 						id: '" + chunkId + "', | 
					
						
							|  |  |  | 						hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`, | 
					
						
							|  |  |  | 						hashWithLength: length => { | 
					
						
							|  |  |  | 							const shortChunkHashMap = {}; | 
					
						
							|  |  |  | 							for (const chunkId of Object.keys(chunkMaps.hash)) { | 
					
						
							|  |  |  | 								if (typeof chunkMaps.hash[chunkId] === "string") { | 
					
						
							|  |  |  | 									shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr( | 
					
						
							|  |  |  | 										0, | 
					
						
							|  |  |  | 										length | 
					
						
							|  |  |  | 									); | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 								} | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | 							} | 
					
						
							|  |  |  | 							return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`; | 
					
						
							|  |  |  | 						}, | 
					
						
							|  |  |  | 						name: `" + (${JSON.stringify( | 
					
						
							|  |  |  | 							chunkMaps.name | 
					
						
							|  |  |  | 						)}[chunkId]||chunkId) + "`
 | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2018-07-31 00:54:54 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			const currentHotUpdateMainFilename = mainTemplate.getAssetPath( | 
					
						
							|  |  |  | 				JSON.stringify(hotUpdateMainFilename), | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | 
					
						
							|  |  |  | 					hashWithLength: length => | 
					
						
							|  |  |  | 						`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "` | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			); | 
					
						
							|  |  |  | 			return Template.getFunctionContent( | 
					
						
							|  |  |  | 				asyncChunkLoading | 
					
						
							|  |  |  | 					? require("./NodeMainTemplateAsync.runtime") | 
					
						
							|  |  |  | 					: require("./NodeMainTemplate.runtime") | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 				.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) | 
					
						
							|  |  |  | 				.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-12-14 04:35:39 +08:00
										 |  |  | 		mainTemplate.hooks.hash.tap("NodeMainTemplatePlugin", hash => { | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | 			hash.update("node"); | 
					
						
							| 
									
										
										
										
											2018-09-14 05:25:26 +08:00
										 |  |  | 			hash.update("4"); | 
					
						
							| 
									
										
										
										
											2014-08-22 19:51:24 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-19 16:35:05 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-03 03:23:53 +08:00
										 |  |  | }; |