| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var PrefetchDependency = require("./dependencies/PrefetchDependency"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function PrefetchPlugin(context, request) { | 
					
						
							| 
									
										
										
										
											2015-07-16 06:19:23 +08:00
										 |  |  | 	if(!request) { | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 		this.request = context; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		this.context = context; | 
					
						
							|  |  |  | 		this.request = request; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = PrefetchPlugin; | 
					
						
							|  |  |  | PrefetchPlugin.prototype.apply = function(compiler) { | 
					
						
							|  |  |  | 	compiler.plugin("compilation", function(compilation, params) { | 
					
						
							|  |  |  | 		var normalModuleFactory = params.normalModuleFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compilation.dependencyFactories.set(PrefetchDependency, normalModuleFactory); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.plugin("make", function(compilation, callback) { | 
					
						
							| 
									
										
										
										
											2013-12-18 06:21:49 +08:00
										 |  |  | 		compilation.prefetch(this.context || compiler.context, new PrefetchDependency(this.request), callback); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 	}.bind(this)); | 
					
						
							| 
									
										
										
										
											2015-07-08 20:39:02 +08:00
										 |  |  | }; |