|
2 | 2 | MIT License http://www.opensource.org/licenses/mit-license.php |
3 | 3 | Author Tobias Koppers @sokra |
4 | 4 | */ |
5 | | -var DelegatedPlugin = require("./DelegatedPlugin"); |
6 | | -var ExternalsPlugin = require("./ExternalsPlugin"); |
| 5 | +var DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency"); |
| 6 | +var DelegatedModuleFactoryPlugin = require("./DelegatedModuleFactoryPlugin"); |
| 7 | +var ExternalModuleFactoryPlugin = require("./ExternalModuleFactoryPlugin"); |
| 8 | +var fs = require("fs"); |
7 | 9 |
|
8 | 10 | function DllReferencePlugin(options) { |
9 | 11 | this.options = options; |
10 | 12 | } |
11 | 13 | module.exports = DllReferencePlugin; |
12 | 14 | DllReferencePlugin.prototype.apply = function(compiler) { |
13 | | - var name = this.options.name || this.options.manifest.name; |
14 | | - var sourceType = this.options.sourceType || "var"; |
15 | | - var externals = {}; |
16 | | - var source = "dll-reference " + name; |
17 | | - externals[source] = name; |
18 | | - compiler.apply(new ExternalsPlugin(sourceType, externals)); |
19 | | - compiler.apply(new DelegatedPlugin({ |
20 | | - source: source, |
21 | | - type: this.options.type, |
22 | | - scope: this.options.scope, |
23 | | - context: this.options.context, |
24 | | - content: this.options.content || this.options.manifest.content |
25 | | - })); |
| 15 | + compiler.plugin("compilation", function(compilation, params) { |
| 16 | + var normalModuleFactory = params.normalModuleFactory; |
| 17 | + |
| 18 | + compilation.dependencyFactories.set(DelegatedSourceDependency, normalModuleFactory); |
| 19 | + }); |
| 20 | + compiler.plugin("before-compile", function(params, callback) { |
| 21 | + var manifest = this.options.manifest; |
| 22 | + if(typeof manifest === "string") { |
| 23 | + params.compilationDependencies.push(manifest); |
| 24 | + fs.readFile(manifest, "utf-8", function(err, result) { |
| 25 | + if(err) return callback(err); |
| 26 | + params["dll reference " + manifest] = JSON.parse(result); |
| 27 | + return callback(); |
| 28 | + }); |
| 29 | + } else { |
| 30 | + return callback(); |
| 31 | + } |
| 32 | + }.bind(this)); |
| 33 | + compiler.plugin("compile", function(params) { |
| 34 | + var manifest = this.options.manifest; |
| 35 | + if(typeof manifest === "string") { |
| 36 | + manifest = params["dll reference " + manifest]; |
| 37 | + } |
| 38 | + var name = this.options.name || manifest.name; |
| 39 | + var sourceType = this.options.sourceType || "var"; |
| 40 | + var externals = {}; |
| 41 | + var source = "dll-reference " + name; |
| 42 | + externals[source] = name; |
| 43 | + params.normalModuleFactory.apply(new ExternalModuleFactoryPlugin(sourceType, externals)); |
| 44 | + params.normalModuleFactory.apply(new DelegatedModuleFactoryPlugin({ |
| 45 | + source: source, |
| 46 | + type: this.options.type, |
| 47 | + scope: this.options.scope, |
| 48 | + context: this.options.context || compiler.options.context, |
| 49 | + content: this.options.content || manifest.content |
| 50 | + })); |
| 51 | + }.bind(this)); |
26 | 52 | }; |
0 commit comments