Skip to content

Commit 181da3c

Browse files
committed
fixed another bug with the CommonsChunkPlugin
when using multiple commons chunks other optimization plugins doesn't optimize perfectly
1 parent a6c4414 commit 181da3c

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/optimize/CommonsChunkPlugin.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
MIT License http://www.opensource.org/licenses/mit-license.php
33
Author Tobias Koppers @sokra
44
*/
5+
var nextIdent = 0;
6+
57
function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks) {
68
if(options && typeof options === "object" && !Array.isArray(options)) {
79
this.chunkNames = options.name || options.names;
@@ -27,7 +29,9 @@ function CommonsChunkPlugin(options, filenameTemplate, selectedChunks, minChunks
2729
this.minChunks = minChunks;
2830
this.selectedChunks = selectedChunks;
2931
}
32+
this.ident = __filename + (nextIdent++);
3033
}
34+
3135
module.exports = CommonsChunkPlugin;
3236
CommonsChunkPlugin.prototype.apply = function(compiler) {
3337
var chunkNames = this.chunkNames;
@@ -36,8 +40,13 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
3640
var selectedChunks = this.selectedChunks;
3741
var async = this.async;
3842
var minSize = this.minSize;
43+
var ident = this.ident;
3944
compiler.plugin("this-compilation", function(compilation) {
4045
compilation.plugin(["optimize-chunks", "optimize-extracted-chunks"], function(chunks) {
46+
// only optimize once
47+
if(compilation[ident]) return;
48+
compilation[ident] = true;
49+
4150
var commonChunks;
4251
if(!chunkNames && (selectedChunks === false || async)) {
4352
commonChunks = chunks;
@@ -163,6 +172,7 @@ CommonsChunkPlugin.prototype.apply = function(compiler) {
163172
if(filenameTemplate)
164173
commonChunk.filenameTemplate = filenameTemplate;
165174
}, this);
175+
this.restartApplyPlugins();
166176
});
167177
});
168178
};

0 commit comments

Comments
 (0)