22 MIT License http://www.opensource.org/licenses/mit-license.php
33 Author Tobias Koppers @sokra
44*/
5+ var nextIdent = 0 ;
6+
57function 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+
3135module . exports = CommonsChunkPlugin ;
3236CommonsChunkPlugin . 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