| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const RuntimeGlobals = require("../RuntimeGlobals"); | 
					
						
							|  |  |  | const RuntimeModule = require("../RuntimeModule"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | /** @typedef {import("../Compilation")} Compilation */ | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | class StartupEntrypointRuntimeModule extends RuntimeModule { | 
					
						
							| 
									
										
										
										
											2023-05-25 03:37:58 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {boolean} asyncChunkLoading use async chunk loading | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 	constructor(asyncChunkLoading) { | 
					
						
							|  |  |  | 		super("startup entrypoint"); | 
					
						
							|  |  |  | 		this.asyncChunkLoading = asyncChunkLoading; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2023-06-17 01:13:03 +08:00
										 |  |  | 	 * @returns {string | null} runtime code | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	generate() { | 
					
						
							| 
									
										
										
										
											2023-06-13 01:24:59 +08:00
										 |  |  | 		const compilation = /** @type {Compilation} */ (this.compilation); | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 		const { runtimeTemplate } = compilation; | 
					
						
							|  |  |  | 		return `${ | 
					
						
							|  |  |  | 			RuntimeGlobals.startupEntrypoint | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 		} = ${runtimeTemplate.basicFunction("result, chunkIds, fn", [ | 
					
						
							|  |  |  | 			"// arguments: chunkIds, moduleId are deprecated", | 
					
						
							|  |  |  | 			"var moduleId = chunkIds;", | 
					
						
							|  |  |  | 			`if(!fn) chunkIds = result, fn = ${runtimeTemplate.returningFunction( | 
					
						
							| 
									
										
										
										
											2023-05-19 23:55:47 +08:00
										 |  |  | 				`${RuntimeGlobals.require}(${RuntimeGlobals.entryModuleId} = moduleId)` | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 			)};`,
 | 
					
						
							|  |  |  | 			...(this.asyncChunkLoading | 
					
						
							|  |  |  | 				? [ | 
					
						
							| 
									
										
										
										
											2023-05-19 23:55:47 +08:00
										 |  |  | 						`return Promise.all(chunkIds.map(${RuntimeGlobals.ensureChunk}, ${ | 
					
						
							|  |  |  | 							RuntimeGlobals.require | 
					
						
							|  |  |  | 						})).then(${runtimeTemplate.basicFunction("", [ | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 							"var r = fn();", | 
					
						
							|  |  |  | 							"return r === undefined ? result : r;" | 
					
						
							|  |  |  | 						])})`
 | 
					
						
							| 
									
										
										
										
											2024-01-14 09:41:34 +08:00
										 |  |  | 					] | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 				: [ | 
					
						
							| 
									
										
										
										
											2023-05-19 23:55:47 +08:00
										 |  |  | 						`chunkIds.map(${RuntimeGlobals.ensureChunk}, ${RuntimeGlobals.require})`, | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 						"var r = fn();", | 
					
						
							|  |  |  | 						"return r === undefined ? result : r;" | 
					
						
							| 
									
										
										
										
											2024-01-14 09:41:34 +08:00
										 |  |  | 					]) | 
					
						
							| 
									
										
										
										
											2021-03-09 03:18:49 +08:00
										 |  |  | 		])}`;
 | 
					
						
							| 
									
										
										
										
											2020-06-29 17:46:16 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = StartupEntrypointRuntimeModule; |