Skip to content

Commit

Permalink
fixed another bug with the CommonsChunkPlugin
Browse files Browse the repository at this point in the history
when using multiple commons chunks
other optimization plugins doesn't optimize perfectly
  • Loading branch information
sokra committed Nov 20, 2015
1 parent a6c4414 commit 181da3c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/optimize/CommonsChunkPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
var nextIdent = 0;

function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks) {
if(options && typeof options === "object" && !Array.isArray(options)) {
this.chunkNames = options.name || options.names;
Expand All @@ -27,7 +29,9 @@ function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks
this.minChunks = minChunks;
this.selectedChunks = selectedChunks;
}
this.ident = __filename + (nextIdent++);
}

module.exports = CommonsChunkPlugin;
CommonsChunkPlugin.prototype.apply = function(compiler) {
var chunkNames = this.chunkNames;
Expand All @@ -36,8 +40,13 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
var selectedChunks = this.selectedChunks;
var async = this.async;
var minSize = this.minSize;
var ident = this.ident;
compiler.plugin("this-compilation", function(compilation) {
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
// only optimize once
if(compilation[ident]) return;
compilation[ident] = true;

var commonChunks;
if(!chunkNames && (selectedChunks === false || async)) {
commonChunks = chunks;
Expand Down Expand Up @@ -163,6 +172,7 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
if(filenameTemplate)
commonChunk.filenameTemplate = filenameTemplate;
}, this);
this.restartApplyPlugins();
});
});
};

0 comments on commit 181da3c

Please sign in to comment.