| 
									
										
										
										
											2013-03-26 23:54:41 +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-01-13 04:38:38 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 14:27:44 +08:00
										 |  |  | const { 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-06-25 16:44:54 +08:00
										 |  |  | /** @typedef {import("./util/createHash").Hash} Hash} */ | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | /** @typedef {import("webpack-sources").Source} Source} */ | 
					
						
							|  |  |  | /** @typedef {import("./ModuleTemplate").RenderContext} RenderContext} */ | 
					
						
							| 
									
										
										
										
											2018-09-15 19:10:58 +08:00
										 |  |  | /** @typedef {import("./MainTemplate").UpdateHashForChunkContext} UpdateHashForChunkContext} */ | 
					
						
							| 
									
										
										
										
											2018-08-14 22:40:37 +08:00
										 |  |  | /** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions} */ | 
					
						
							|  |  |  | /** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry} */ | 
					
						
							| 
									
										
										
										
											2018-05-01 23:47:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 14:27:44 +08:00
										 |  |  | module.exports = class ChunkTemplate { | 
					
						
							| 
									
										
										
										
											2017-01-13 04:38:38 +08:00
										 |  |  | 	constructor(outputOptions) { | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 		this.outputOptions = outputOptions || {}; | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +08:00
										 |  |  | 		this.hooks = Object.freeze({ | 
					
						
							| 
									
										
										
										
											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-07-24 23:35:36 +08:00
										 |  |  | 			/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			modules: new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"moduleTemplate", | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 				"renderContext" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			]), | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 			/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */ | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			render: new SyncWaterfallHook([ | 
					
						
							|  |  |  | 				"source", | 
					
						
							|  |  |  | 				"moduleTemplate", | 
					
						
							| 
									
										
										
										
											2018-07-24 23:35:36 +08:00
										 |  |  | 				"renderContext" | 
					
						
							| 
									
										
										
										
											2018-02-25 09:00:20 +08:00
										 |  |  | 			]), | 
					
						
							| 
									
										
										
										
											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"]) | 
					
						
							| 
									
										
										
										
											2018-07-30 20:25:40 +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-08-14 22:40:37 +08:00
										 |  |  | 	 * @returns {RenderManifestEntry[]} 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-15 19:10:58 +08:00
										 |  |  | 	 * @param {UpdateHashForChunkContext} context options object | 
					
						
							| 
									
										
										
										
											2018-06-25 16:44:54 +08:00
										 |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2018-09-15 19:10:58 +08:00
										 |  |  | 	updateHashForChunk(hash, chunk, context) { | 
					
						
							| 
									
										
										
										
											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
										 |  |  | }; |