Skip to content

Commit 530fad4

Browse files
committed
allow to pass abs path to manifest property of DllReferencePlugin
manifest is loaded on compilation
1 parent a0a920d commit 530fad4

3 files changed

Lines changed: 59 additions & 27 deletions

File tree

lib/Compilation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ Compilation.prototype.summarizeDependencies = function summarizeDependencies() {
855855
}
856856
return newArray;
857857
}
858-
this.fileDependencies = [];
858+
this.fileDependencies = (this.compilationDependencies || []).slice();
859859
this.contextDependencies = [];
860860
this.missingDependencies = [];
861861
this.children.forEach(function(child) {

lib/Compiler.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ Compiler.prototype.newCompilation = function(params) {
424424
compilation.contextTimestamps = this.contextTimestamps;
425425
compilation.name = this.name;
426426
compilation.records = this.records;
427+
compilation.compilationDependencies = params.compilationDependencies;
427428
this.applyPlugins("this-compilation", compilation, params);
428429
this.applyPlugins("compilation", compilation, params);
429430
return compilation;
@@ -444,30 +445,35 @@ Compiler.prototype.createContextModuleFactory = function() {
444445
Compiler.prototype.newCompilationParams = function() {
445446
var params = {
446447
normalModuleFactory: this.createNormalModuleFactory(),
447-
contextModuleFactory: this.createContextModuleFactory()
448+
contextModuleFactory: this.createContextModuleFactory(),
449+
compilationDependencies: []
448450
};
449451
return params;
450452
};
451453

452454
Compiler.prototype.compile = function(callback) {
453455
var params = this.newCompilationParams();
454-
this.applyPlugins("compile", params);
455-
456-
var compilation = this.newCompilation(params);
457-
458-
this.applyPluginsParallel("make", compilation, function(err) {
456+
this.applyPluginsAsync("before-compile", params, function(err) {
459457
if(err) return callback(err);
460458

461-
compilation.finish();
459+
this.applyPlugins("compile", params);
460+
461+
var compilation = this.newCompilation(params);
462462

463-
compilation.seal(function(err) {
463+
this.applyPluginsParallel("make", compilation, function(err) {
464464
if(err) return callback(err);
465465

466-
this.applyPluginsAsync("after-compile", compilation, function(err) {
466+
compilation.finish();
467+
468+
compilation.seal(function(err) {
467469
if(err) return callback(err);
468470

469-
return callback(null, compilation);
470-
});
471+
this.applyPluginsAsync("after-compile", compilation, function(err) {
472+
if(err) return callback(err);
473+
474+
return callback(null, compilation);
475+
});
476+
}.bind(this));
471477
}.bind(this));
472478
}.bind(this));
473479
};

lib/DllReferencePlugin.js

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,51 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
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");
79

810
function DllReferencePlugin(options) {
911
this.options = options;
1012
}
1113
module.exports = DllReferencePlugin;
1214
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));
2652
};

0 commit comments

Comments
 (0)