| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-22 19:05:58 +08:00
										 |  |  | const { Tapable, SyncWaterfallHook, SyncHook } = require("tapable"); | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  | /** @typedef {import("./ModuleTemplate")} ModuleTemplate */ | 
					
						
							|  |  |  | /** @typedef {import("./Chunk")} Chunk */ | 
					
						
							|  |  |  | /** @typedef {import("./Module")} Module} */ | 
					
						
							| 
									
										
										
										
											2018-09-14 05:25:26 +08:00
										 |  |  | /** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */ | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash} */ | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} RenderManifestOptions | 
					
						
							|  |  |  |  * @property {Chunk} chunk the chunk used to render | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  |  * @property {string} hash | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  |  * @property {string} fullHash | 
					
						
							| 
									
										
										
										
											2018-05-08 20:31:51 +08:00
										 |  |  |  * @property {TODO} outputOptions | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  |  * @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates | 
					
						
							| 
									
										
										
										
											2018-05-08 20:31:51 +08:00
										 |  |  |  * @property {Map<TODO, TODO>} dependencyTemplates | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | module.exports = class ChunkTemplate extends Tapable { | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	constructor(outputOptions) { | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 		super(); | 
					
						
							|  |  |  | 		this.outputOptions = outputOptions || {}; | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		this.hooks = { | 
					
						
							| 
									
										
										
										
											2018-07-02 22:18:49 +08:00
										 |  |  | 			/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */ | 
					
						
							| 
									
										
										
										
											2018-01-24 16:39:49 +08:00
										 |  |  | 			renderManifest: new SyncWaterfallHook(["result", "options"]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			modules: new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"chunk", | 
					
						
							|  |  |  | 				"moduleTemplate", | 
					
						
							|  |  |  | 				"dependencyTemplates" | 
					
						
							|  |  |  | 			]), | 
					
						
							|  |  |  | 			render: new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"chunk", | 
					
						
							|  |  |  | 				"moduleTemplate", | 
					
						
							|  |  |  | 				"dependencyTemplates" | 
					
						
							|  |  |  | 			]), | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 			renderWithEntry: new SyncWaterfallHook(["source", "chunk"]), | 
					
						
							|  |  |  | 			hash: new SyncHook(["hash"]), | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			hashForChunk: new SyncHook(["hash", "chunk"]) | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-05-20 13:39:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {RenderManifestOptions} options render manifest options | 
					
						
							| 
									
										
										
										
											2018-05-08 20:31:51 +08:00
										 |  |  | 	 * @returns {TODO[]} returns render manifest | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 	getRenderManifest(options) { | 
					
						
							|  |  |  | 		const result = []; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-24 16:39:49 +08:00
										 |  |  | 		this.hooks.renderManifest.call(result, options); | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return result; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * Updates hash with information from this template | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash to update | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							|  |  |  | 		hash.update("ChunkTemplate"); | 
					
						
							|  |  |  | 		hash.update("2"); | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		this.hooks.hash.call(hash); | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-25 05:17:12 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | 	/** | 
					
						
							| 
									
										
										
										
											2018-09-14 05:25:26 +08:00
										 |  |  | 	 * TODO webpack 5: remove moduleTemplate and dependencyTemplates | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | 	 * Updates hash with chunk-specific information from this template | 
					
						
							|  |  |  | 	 * @param {Hash} hash the hash to update | 
					
						
							|  |  |  | 	 * @param {Chunk} chunk the chunk | 
					
						
							| 
									
										
										
										
											2018-09-14 05:25:26 +08:00
										 |  |  | 	 * @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render | 
					
						
							|  |  |  | 	 * @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-14 05:25:26 +08:00
										 |  |  | 	updateHashForChunk(hash, chunk, moduleTemplate, dependencyTemplates) { | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 		this.updateHash(hash); | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		this.hooks.hashForChunk.call(hash, chunk); | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-25 05:17:12 +08:00
										 |  |  | }; |