| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2016-12-29 15:10:25 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | const Tapable = require("tapable").Tapable; | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | const SyncWaterfallHook = require("tapable").SyncWaterfallHook; | 
					
						
							|  |  |  | const SyncHook = require("tapable").SyncHook; | 
					
						
							| 
									
										
										
										
											2014-06-03 14:45:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | module.exports = class ModuleTemplate extends Tapable { | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 	constructor(runtimeTemplate) { | 
					
						
							| 
									
										
										
										
											2017-12-07 16:42:33 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 		this.runtimeTemplate = runtimeTemplate; | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		this.hooks = { | 
					
						
							|  |  |  | 			content: new SyncWaterfallHook(["source", "module", "options", "dependencyTemplates"]), | 
					
						
							|  |  |  | 			module: new SyncWaterfallHook(["source", "module", "options", "dependencyTemplates"]), | 
					
						
							|  |  |  | 			render: new SyncWaterfallHook(["source", "module", "options", "dependencyTemplates"]), | 
					
						
							|  |  |  | 			package: new SyncWaterfallHook(["source", "module", "options", "dependencyTemplates"]), | 
					
						
							|  |  |  | 			hash: new SyncHook(["hash"]) | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-29 15:10:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 18:01:51 +08:00
										 |  |  | 	render(module, dependencyTemplates, options) { | 
					
						
							| 
									
										
										
										
											2017-12-07 17:31:00 +08:00
										 |  |  | 		const moduleSource = module.source(dependencyTemplates, this.runtimeTemplate); | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		const moduleSourcePostContent = this.hooks.content.call(moduleSource, module, options, dependencyTemplates); | 
					
						
							|  |  |  | 		const moduleSourcePostModule = this.hooks.module.call(moduleSourcePostContent, module, options, dependencyTemplates); | 
					
						
							|  |  |  | 		const moduleSourcePostRender = this.hooks.render.call(moduleSourcePostModule, module, options, dependencyTemplates); | 
					
						
							|  |  |  | 		return this.hooks.package.call(moduleSourcePostRender, module, options, dependencyTemplates); | 
					
						
							| 
									
										
										
										
											2016-12-29 15:10:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-10-30 20:56:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-29 15:10:25 +08:00
										 |  |  | 	updateHash(hash) { | 
					
						
							|  |  |  | 		hash.update("1"); | 
					
						
							| 
									
										
										
										
											2017-11-29 01:43:01 +08:00
										 |  |  | 		this.hooks.hash.call(hash); | 
					
						
							| 
									
										
										
										
											2016-12-29 15:10:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | }; |