Skip to content

Commit 6898aa4

Browse files
committed
respect all chunks
1 parent bbc93ab commit 6898aa4

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

index.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ var ConcatSource = require("webpack-sources").ConcatSource;
77
var async = require("async");
88
var ExtractedModule = require("./ExtractedModule");
99
var Chunk = require("webpack/lib/Chunk");
10+
var NormalModule = require("webpack/lib/NormalModule");
1011
var OrderUndefinedError = require("./OrderUndefinedError");
1112
var loaderUtils = require("loader-utils");
1213
var validateOptions = require('schema-utils');
1314
var path = require('path');
15+
var OriginalSource = require("webpack-sources").OriginalSource;
1416

1517
var NS = fs.realpathSync(__dirname);
1618

@@ -233,6 +235,7 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
233235
var options = this.options;
234236
compiler.plugin("this-compilation", function(compilation) {
235237
var extractCompilation = new ExtractTextPluginCompilation();
238+
var toRemoveModules = {};
236239
compilation.plugin("normal-module-loader", function(loaderContext, module) {
237240
loaderContext[NS] = function(content, opt) {
238241
if(options.disable)
@@ -290,9 +293,14 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
290293
return callback();
291294
}
292295
if(meta.content) {
293-
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
296+
var ident = module.identifier();
297+
extractCompilation.addResultToChunk(ident, meta.content, module, extractedChunk);
294298
// remove generated result from chunk
295-
chunk.removeModule(module);
299+
if(toRemoveModules[ident]) {
300+
toRemoveModules[ident].chunks.push(chunk)
301+
} else {
302+
toRemoveModules[ident] = { module: module, chunks: [chunk] };
303+
}
296304
}
297305
callback();
298306
});
@@ -323,6 +331,21 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
323331
callback();
324332
}.bind(this));
325333
}.bind(this));
334+
compilation.plugin("optimize-module-ids", function(modules){
335+
modules.forEach(function(module){
336+
var data = toRemoveModules[module.identifier()];
337+
if(data) {
338+
var id = module.id;
339+
var newModule = new NormalModule(module.request, module.userRequest, module.rawRequest, [], module.resource, module.parser);
340+
newModule.id = id;
341+
newModule._source = new OriginalSource('// removed by extract-text-webpack-plugin');
342+
data.chunks.forEach(function (chunk) {
343+
chunk.removeModule(module);
344+
chunk.addModule(newModule);
345+
});
346+
}
347+
});
348+
});
326349
compilation.plugin("additional-assets", function(callback) {
327350
extractedChunks.forEach(function(extractedChunk) {
328351
if(extractedChunk.modules.length) {

test/cases/multiple-entries-async/expected/0.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
webpackJsonp([0],{
22

3-
/***/ 11:
3+
/***/ 3:
44
/***/ (function(module, exports, __webpack_require__) {
55

6-
exports = module.exports = __webpack_require__(5)(false);
7-
// imports
8-
9-
10-
// module
11-
exports.push([module.i, ".homepage {\n\tcolor: black;\n}\n", ""]);
6+
__webpack_require__(8);
127

13-
// exports
8+
modules.export = function() {
9+
return 'Route Homepage';
10+
};
1411

1512

1613
/***/ }),
1714

18-
/***/ 2:
15+
/***/ 8:
1916
/***/ (function(module, exports, __webpack_require__) {
2017

21-
__webpack_require__(11);
18+
exports = module.exports = __webpack_require__(0)(false);
19+
// imports
2220

23-
modules.export = function() {
24-
return 'Route Homepage';
25-
};
21+
22+
// module
23+
exports.push([module.i, ".homepage {\n\tcolor: black;\n}\n", ""]);
24+
25+
// exports
2626

2727

2828
/***/ })

test/cases/multiple-entries-async/expected/1.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
webpackJsonp([1],{
22

3-
/***/ 1:
3+
/***/ 2:
44
/***/ (function(module, exports, __webpack_require__) {
55

6-
__webpack_require__(10);
6+
__webpack_require__(7);
77

88
modules.export = function() {
99
return 'Route Contact';
@@ -12,10 +12,10 @@ modules.export = function() {
1212

1313
/***/ }),
1414

15-
/***/ 10:
15+
/***/ 7:
1616
/***/ (function(module, exports, __webpack_require__) {
1717

18-
exports = module.exports = __webpack_require__(5)(false);
18+
exports = module.exports = __webpack_require__(0)(false);
1919
// imports
2020

2121

0 commit comments

Comments
 (0)