Skip to content

Commit f7d5bbf

Browse files
committed
report dependencies
fixed watch issue
1 parent de90220 commit f7d5bbf

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ ExtractTextPlugin.loader = function(options) {
2828
ExtractTextPlugin.extract = function(before, loader) {
2929
if(loader) {
3030
return [
31-
ExtractTextPlugin.loader({remove: true, extract: false}),
31+
ExtractTextPlugin.loader({omit: before.split("!").length, extract: true, remove: true}),
3232
before,
33-
ExtractTextPlugin.loader(),
3433
loader
3534
].join("!");
3635
} else {
3736
loader = before;
3837
return [
39-
ExtractTextPlugin.loader(),
38+
ExtractTextPlugin.loader({remove: true}),
4039
loader
4140
].join("!");
4241
}
@@ -51,23 +50,22 @@ ExtractTextPlugin.prototype.loader = function(options) {
5150
ExtractTextPlugin.prototype.extract = function(before, loader) {
5251
if(loader) {
5352
return [
54-
this.loader({remove: true, extract: false}),
53+
this.loader({move: before.split("!").length, extract: true, remove: true}),
5554
before,
56-
this.loader(),
5755
loader
5856
].join("!");
5957
} else {
6058
loader = before;
6159
return [
62-
this.loader(),
60+
this.loader({remove: true}),
6361
loader
6462
].join("!");
6563
}
6664
};
6765

6866
ExtractTextPlugin.prototype.apply = function(compiler) {
6967
var options = this.options;
70-
compiler.plugin("compilation", function(compilation) {
68+
compiler.plugin("this-compilation", function(compilation) {
7169
compilation.plugin("normal-module-loader", function(loaderContext, module) {
7270
loaderContext[__dirname] = function(text, opt) {
7371
if(typeof text !== "string" && text !== null)
@@ -99,7 +97,9 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
9997
}
10098
meta = module.meta[__dirname];
10199
if(typeof meta.text !== "string") {
102-
return callback(new Error(module.identifier() + " doesn't export text"));
100+
var err = new Error(module.identifier() + " doesn't export text");
101+
compilation.errors.push(err);
102+
return callback();
103103
}
104104
text.push(meta.text);
105105
callback();

loader.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ module.exports = function(source) {
1515
module.exports.pitch = function(request, preReq, data) {
1616
this.cacheable && this.cacheable();
1717
var query = loaderUtils.parseQuery(this.query);
18+
this.addDependency(this.resourcePath);
1819
if(this[__dirname](null, query)) {
20+
if(query.omit) {
21+
this.loaderIndex += +query.omit + 1;
22+
request = request.split("!").slice(+query.omit).join("!");
23+
}
1924
if(query.remove) {
2025
var resultSource = "// removed by extract-text-webpack-plugin";
2126
} else {
@@ -56,13 +61,19 @@ module.exports.pitch = function(request, preReq, data) {
5661
if(!source) {
5762
return callback(new Error("Didn't get a result from child compiler"));
5863
}
64+
compilation.fileDependencies.forEach(function(dep) {
65+
this.addDependency(dep);
66+
}, this);
67+
compilation.contextDependencies.forEach(function(dep) {
68+
this.addContextDependency(dep);
69+
}, this);
5970
try {
6071
var text = this.exec(source, request);
6172
this[__dirname](text, query);
62-
callback(null, resultSource);
6373
} catch(e) {
64-
callback(e);
74+
return callback(e);
6575
}
76+
callback(null, resultSource);
6677
}.bind(this));
6778
} else {
6879
this[__dirname]("", query);

0 commit comments

Comments
 (0)