| 
									
										
										
										
											2015-05-17 17:06:35 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); | 
					
						
							|  |  |  | var DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin"); | 
					
						
							|  |  |  | var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin"); | 
					
						
							| 
									
										
										
										
											2015-05-17 17:06:35 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function DllReferencePlugin(options) { | 
					
						
							|  |  |  | 	this.options = options; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = DllReferencePlugin; | 
					
						
							|  |  |  | DllReferencePlugin.prototype.apply = function(compiler) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 	compiler.plugin("compilation", function(compilation, params) { | 
					
						
							|  |  |  | 		var normalModuleFactory = params.normalModuleFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 	compiler.plugin("before-compile", function(params, callback) { | 
					
						
							|  |  |  | 		var manifest = this.options.manifest; | 
					
						
							|  |  |  | 		if(typeof manifest === "string") { | 
					
						
							|  |  |  | 			params.compilationDependencies.push(manifest); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			compiler.inputFileSystem.readFile(manifest, function(err, result) { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				params["dll reference " + manifest] = JSON.parse(result.toString("utf-8")); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | 	compiler.plugin("compile", function(params) { | 
					
						
							|  |  |  | 		var manifest = this.options.manifest; | 
					
						
							|  |  |  | 		if(typeof manifest === "string") { | 
					
						
							|  |  |  | 			manifest = params["dll reference " + manifest]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		var name = this.options.name || manifest.name; | 
					
						
							|  |  |  | 		var sourceType = this.options.sourceType || "var"; | 
					
						
							|  |  |  | 		var externals = {}; | 
					
						
							|  |  |  | 		var source = "dll-reference " + name; | 
					
						
							|  |  |  | 		externals[source] = name; | 
					
						
							|  |  |  | 		params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(sourceType, externals)); | 
					
						
							|  |  |  | 		params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin({ | 
					
						
							|  |  |  | 			source: source, | 
					
						
							|  |  |  | 			type: this.options.type, | 
					
						
							|  |  |  | 			scope: this.options.scope, | 
					
						
							|  |  |  | 			context: this.options.context || compiler.options.context, | 
					
						
							| 
									
										
										
										
											2016-09-07 20:57:53 +08:00
										 |  |  | 			content: this.options.content || manifest.content, | 
					
						
							|  |  |  | 			extensions: this.options.extensions | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 		})); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							| 
									
										
										
										
											2015-05-17 17:06:35 +08:00
										 |  |  | }; |