Skip to content

Commit

Permalink
respect all chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Jun 18, 2017
1 parent bbc93ab commit 6898aa4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 19 deletions.
27 changes: 25 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ var ConcatSource = require("webpack-sources").ConcatSource;
var async = require("async");
var ExtractedModule = require("./ExtractedModule");
var Chunk = require("webpack/lib/Chunk");
var NormalModule = require("webpack/lib/NormalModule");
var OrderUndefinedError = require("./OrderUndefinedError");
var loaderUtils = require("loader-utils");
var validateOptions = require('schema-utils');
var path = require('path');
var OriginalSource = require("webpack-sources").OriginalSource;

var NS = fs.realpathSync(__dirname);

Expand Down Expand Up @@ -233,6 +235,7 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
var options = this.options;
compiler.plugin("this-compilation", function(compilation) {
var extractCompilation = new ExtractTextPluginCompilation();
var toRemoveModules = {};
compilation.plugin("normal-module-loader", function(loaderContext, module) {
loaderContext[NS] = function(content, opt) {
if(options.disable)
Expand Down Expand Up @@ -290,9 +293,14 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
return callback();
}
if(meta.content) {
extractCompilation.addResultToChunk(module.identifier(), meta.content, module, extractedChunk);
var ident = module.identifier();
extractCompilation.addResultToChunk(ident, meta.content, module, extractedChunk);
// remove generated result from chunk
chunk.removeModule(module);
if(toRemoveModules[ident]) {
toRemoveModules[ident].chunks.push(chunk)
} else {
toRemoveModules[ident] = { module: module, chunks: [chunk] };
}
}
callback();
});
Expand Down Expand Up @@ -323,6 +331,21 @@ ExtractTextPlugin.prototype.apply = function(compiler) {
callback();
}.bind(this));
}.bind(this));
compilation.plugin("optimize-module-ids", function(modules){
modules.forEach(function(module){
var data = toRemoveModules[module.identifier()];
if(data) {
var id = module.id;
var newModule = new NormalModule(module.request, module.userRequest, module.rawRequest, [], module.resource, module.parser);
newModule.id = id;
newModule._source = new OriginalSource('// removed by extract-text-webpack-plugin');
data.chunks.forEach(function (chunk) {
chunk.removeModule(module);
chunk.addModule(newModule);
});
}
});
});
compilation.plugin("additional-assets", function(callback) {
extractedChunks.forEach(function(extractedChunk) {
if(extractedChunk.modules.length) {
Expand Down
26 changes: 13 additions & 13 deletions test/cases/multiple-entries-async/expected/0.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
webpackJsonp([0],{

/***/ 11:
/***/ 3:
/***/ (function(module, exports, __webpack_require__) {

exports = module.exports = __webpack_require__(5)(false);
// imports


// module
exports.push([module.i, ".homepage {\n\tcolor: black;\n}\n", ""]);
__webpack_require__(8);

// exports
modules.export = function() {
return 'Route Homepage';
};


/***/ }),

/***/ 2:
/***/ 8:
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(11);
exports = module.exports = __webpack_require__(0)(false);
// imports

modules.export = function() {
return 'Route Homepage';
};

// module
exports.push([module.i, ".homepage {\n\tcolor: black;\n}\n", ""]);

// exports


/***/ })
Expand Down
8 changes: 4 additions & 4 deletions test/cases/multiple-entries-async/expected/1.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
webpackJsonp([1],{

/***/ 1:
/***/ 2:
/***/ (function(module, exports, __webpack_require__) {

__webpack_require__(10);
__webpack_require__(7);

modules.export = function() {
return 'Route Contact';
Expand All @@ -12,10 +12,10 @@ modules.export = function() {

/***/ }),

/***/ 10:
/***/ 7:
/***/ (function(module, exports, __webpack_require__) {

exports = module.exports = __webpack_require__(5)(false);
exports = module.exports = __webpack_require__(0)(false);
// imports


Expand Down

0 comments on commit 6898aa4

Please sign in to comment.