2013-12-03 16:27:15 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/ *  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									MIT  License  http : //www.opensource.org/licenses/mit-license.php
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									Author  Tobias  Koppers  @ sokra 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								* /  
						 
					
						
							
								
									
										
										
										
											2017-01-04 21:50:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								"use strict" ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								let  nextIdent  =  0 ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  CommonsChunkPlugin  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									constructor ( options )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( arguments . length  >  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-05 03:34:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											throw  new  Error ( ` Deprecation notice: CommonsChunkPlugin now only takes a single argument. Either an options
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 19:15:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								object  * or *  the  name  of  the  chunk .  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Example :  if  your  old  code  looked  like  this :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									new  webpack . optimize . CommonsChunkPlugin ( 'vendor' ,  'vendor.bundle.js' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You  would  change  it  to :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									new  webpack . optimize . CommonsChunkPlugin ( {  name :  'vendor' ,  filename :  'vendor.bundle.js'  } ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The  available  options  are :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									name :  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									names :  string [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									filename :  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									minChunks :  number 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									chunks :  string [ ] 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									children :  boolean 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									async :  boolean 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									minSize :  number ` );
 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 21:50:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-10 19:15:41 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  normalizedOptions  =  this . normalizeOptions ( options ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . chunkNames  =  normalizedOptions . chunkNames ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 17:41:12 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										this . filenameTemplate  =  normalizedOptions . filenameTemplate ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										this . minChunks  =  normalizedOptions . minChunks ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . selectedChunks  =  normalizedOptions . selectedChunks ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:00:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										this . children  =  normalizedOptions . children ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										this . async  =  normalizedOptions . async ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										this . minSize  =  normalizedOptions . minSize ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										this . ident  =  _ _filename  +  ( nextIdent ++ ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									normalizeOptions ( options )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( Array . isArray ( options ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												chunkNames :  options , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( typeof  options  ===  "string" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												chunkNames :  [ options ] , 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 21:50:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// options.children and options.chunk may not be used together
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( options . children  &&  options . chunks )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											throw  new  Error ( "You can't and it does not make any sense to use \"children\" and \"chunk\" options together." ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  options . async  and  options . filename  are  also  not  possible  together 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  as  filename  specifies  how  the  chunk  is  called  but  "async"  implies 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  that  webpack  will  take  care  of  loading  this  file . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( options . async  &&  options . filename )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											throw  new  Error ( ` You can not specify a filename if you use the  \" async \"  option.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								You  can  however  specify  the  name  of  the  async  chunk  by  passing  the  desired  string  as  the  \ "async\"  option . ` );
  
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:27:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  Make  sure  this  is  either  an  array  or  undefined . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  "name"  can  be  a  string  and 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  "names"  a  string  or  an  array 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  chunkNames  =  options . name  ||  options . names  ?  [ ] . concat ( options . name  ||  options . names )  :  undefined ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											chunkNames :  chunkNames , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											filenameTemplate :  options . filename , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											minChunks :  options . minChunks , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											selectedChunks :  options . chunks , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											children :  options . children , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											async :  options . async , 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											minSize :  options . minSize 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
									
										
										
										
											2016-01-22 12:01:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:30:53 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									apply ( compiler )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										compiler . plugin ( "this-compilation" ,  ( compilation )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											compilation . plugin ( [ "optimize-chunks" ,  "optimize-extracted-chunks" ] ,  ( chunks )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// only optimize once
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if ( compilation [ this . ident ] )  return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												compilation [ this . ident ]  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												/ * * 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												 *  Creates  a  list  of  "common" "  chunks  based  on  the  options . 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												 *  The  list  is  made  up  of  preexisting  or  newly  created  chunks . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 *  -  If  chunk  has  the  name  as  specified  in  the  chunkNames  it  is  put  in  the  list 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 *  -  If  no  chunk  with  the  name  as  given  in  chunkNames  exists  a  new  chunk  is  created  and  added  to  the  list 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												 *  These  chunks  are  the  "targets"  for  extracted  modules . 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												 * / 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  targetChunks  =  this . getTargetChunks ( chunks ,  compilation ,  this . chunkNames ,  this . children ,  this . async ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// iterate over all our new chunks
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												targetChunks . forEach ( ( targetChunk ,  idx )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  These  chunks  are  subject  to  get  "common"  modules  extracted  and  moved  to  the  common  chunk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													const  affectedChunks  =  this . getAffectedChunks ( compilation ,  chunks ,  targetChunk ,  targetChunks ,  idx ,  this . selectedChunks ,  this . async ,  this . children ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// bail if no chunk is affected
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													if ( ! affectedChunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// If we are async create an async chunk now
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// override the "commonChunk" with the newly created async one and use it as commonChunk from now on
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													let  asyncChunk ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if ( this . async )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														// If async chunk is one of the affected chunks, just use it
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														asyncChunk  =  affectedChunks . filter ( c  =>  c . name  ===  this . async ) [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														// Elsewise create a new one
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														if ( ! asyncChunk )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															asyncChunk  =  this . createAsyncChunk ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																compilation , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																targetChunks . length  <=  1  ||  typeof  this . async  !==  "string"  ?  this . async  : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																targetChunk . name  ?  ` ${ this . async } - ${ targetChunk . name } `  : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																true , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
																targetChunk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
															) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														targetChunk  =  asyncChunk ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 *  Check  which  modules  are  "common"  and  could  be  extracted  to  a  "common"  chunk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													 * / 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													const  extractableModules  =  this . getExtractableModules ( this . minChunks ,  affectedChunks ,  targetChunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// If the minSize option is set check if the size extracted from the chunk is reached
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// else bail out here.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// As all modules/commons are interlinked with each other, common modules would be extracted
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// if we reach this mark at a later common chunk. (quirky I guess).
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if ( this . minSize )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														const  modulesSize  =  this . calculateModulesSize ( extractableModules ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														// if too small, bail
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														if ( modulesSize  <  this . minSize ) 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
															return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// Remove modules that are moved to commons chunk from their original chunks
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// return all chunks that are affected by having modules removed - we need them later (apparently)
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													const  chunksWithExtractedModules  =  this . extractModulesAndReturnAffectedChunks ( extractableModules ,  affectedChunks ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// connect all extracted modules with the common chunk
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													this . addExtractedModulesToTargetChunk ( targetChunk ,  extractableModules ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// set filenameTemplate for chunk
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if ( this . filenameTemplate ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														targetChunk . filenameTemplate  =  this . filenameTemplate ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// if we are async connect the blocks of the "reallyUsedChunk" - the ones that had modules removed -
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// with the commonChunk and get the origins for the asyncChunk (remember "asyncChunk === commonChunk" at this moment).
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// bail out
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													if ( this . async )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														this . moveExtractedChunkBlocksToTargetChunk ( chunksWithExtractedModules ,  targetChunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
														asyncChunk . origins  =  this . extractOriginsOfChunksWithExtractedModules ( chunksWithExtractedModules ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
														return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// we are not in "async" mode
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													// connect used chunks with commonChunk - shouldnt this be reallyUsedChunks here?
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
													this . makeTargetChunkParentOfAffectedChunks ( affectedChunks ,  targetChunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:48:23 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getTargetChunks ( allChunks ,  compilation ,  chunkNames ,  children ,  asyncOption )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:00:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  asyncOrNoSelectedChunk  =  children  ||  asyncOption ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// we have specified chunk names
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:34:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( chunkNames )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// map chunks by chunkName for quick access
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:27:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  allChunksNameMap  =  allChunks . reduce ( ( map ,  chunk )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if ( chunk . name )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													map . set ( chunk . name ,  chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  map ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ,  new  Map ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Ensure we have a chunk per specified chunk name.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// Reuse existing chunks if possible
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:34:52 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  chunkNames . map ( chunkName  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:27:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if ( allChunksNameMap . has ( chunkName ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													return  allChunksNameMap . get ( chunkName ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// add the filtered chunks to the compilation
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  compilation . addChunk ( chunkName ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// we dont have named chunks specified, so we just take all of them
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( asyncOrNoSelectedChunk )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-04 16:50:46 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  allChunks . filter ( chunk  =>  ! chunk . isInitial ( ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  No  chunk  name ( s )  was  specified  nor  is  this  an  async / children  commons  chunk 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										throw  new  Error ( ` You did not specify any valid target chunk settings.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Take  a  look  at  the  "name" / "names"  or  async / children  option . ` );
  
						 
					
						
							
								
									
										
										
										
											2017-02-19 11:31:35 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getAffectedChunks ( compilation ,  allChunks ,  targetChunk ,  targetChunks ,  currentIndex ,  selectedChunks ,  asyncOption ,  children )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:00:20 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  asyncOrNoSelectedChunk  =  children  ||  asyncOption ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( Array . isArray ( selectedChunks ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  allChunks . filter ( chunk  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  notCommmonChunk  =  chunk  !==  targetChunk ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  isSelectedChunk  =  selectedChunks . indexOf ( chunk . name )  >  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  notCommmonChunk  &&  isSelectedChunk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										if ( asyncOrNoSelectedChunk )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// nothing to do here
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if ( ! targetChunk . chunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  targetChunk . chunks . filter ( ( chunk )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// we can only move modules from this chunk if the "commonChunk" is the only parent
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-20 18:42:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												return  asyncOption  ||  chunk . parents . length  ===  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 17:55:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  past  this  point  only  entry  chunks  are  allowed  to  become  commonChunks 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( targetChunk . parents . length  >  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											compilation . errors . push ( new  Error ( "CommonsChunkPlugin: While running in normal mode it's not allowed to use a non-entry chunk ("  +  targetChunk . name  +  ")" ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:55:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										/ * * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  If  we  find  a  "targetchunk"  that  is  also  a  normal  chunk  ( meaning  it  is  probably  specified  as  an  entry ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  and  the  current  target  chunk  comes  after  that  and  the  found  chunk  has  a  runtime * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  make  that  chunk  be  an  'affected'  chunk  of  the  current  target  chunk . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  To  understand  what  that  means  take  a  look  at  the  "examples/chunkhash" ,  this  basically  will 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  result  in  the  runtime  to  be  extracted  to  the  current  target  chunk . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 *  * runtime :  the  "runtime"  is  the  "webpack" - block  you  may  have  seen  in  the  bundles  that  resolves  modules  etc . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										 * / 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  allChunks . filter ( ( chunk )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											const  found  =  targetChunks . indexOf ( chunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											if ( found  >=  currentIndex )  return  false ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-04-02 10:14:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  chunk . hasRuntime ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									createAsyncChunk ( compilation ,  asyncOption ,  targetChunk )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  asyncChunk  =  compilation . addChunk ( typeof  asyncOption  ===  "string"  ?  asyncOption  :  undefined ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										asyncChunk . chunkReason  =  "async commons chunk" ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										asyncChunk . extraAsync  =  true ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										asyncChunk . addParent ( targetChunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										targetChunk . addChunk ( asyncChunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 12:59:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  asyncChunk ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									// If minChunks is a function use that
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									// otherwhise check if a module is used at least minChunks or 2 or usedChunks.length time
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getModuleFilter ( minChunks ,  targetChunk ,  usedChunksLength )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( typeof  minChunks  ===  "function" )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  minChunks ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  minCount  =  ( minChunks  ||  Math . max ( 2 ,  usedChunksLength ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  isUsedAtLeastMinTimes  =  ( module ,  count )  =>  count  >=  minCount ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  isUsedAtLeastMinTimes ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									getExtractableModules ( minChunks ,  usedChunks ,  targetChunk )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										if ( minChunks  ===  Infinity )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  [ ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// count how many chunks contain a module
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  commonModulesToCountMap  =  usedChunks . reduce ( ( map ,  chunk )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-20 20:46:21 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for ( const  module  of  chunk . modulesIterable )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  count  =  map . has ( module )  ?  map . get ( module )  :  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												map . set ( module ,  count  +  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  map ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  new  Map ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										// filter by minChunks
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  moduleFilterCount  =  this . getModuleFilter ( minChunks ,  targetChunk ,  usedChunks . length ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										// filter by condition
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										const  moduleFilterCondition  =  ( module ,  chunk )  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( ! module . chunkCondition )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												return  true ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  module . chunkCondition ( chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  Array . from ( commonModulesToCountMap ) . filter ( entry  =>  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  module  =  entry [ 0 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											const  count  =  entry [ 1 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// if the module passes both filters, keep it.
 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											return  moduleFilterCount ( module ,  count )  &&  moduleFilterCondition ( module ,  targetChunk ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										} ) . map ( entry  =>  entry [ 0 ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									calculateModulesSize ( modules )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  modules . reduce ( ( totalSize ,  module )  =>  totalSize  +  module . size ( ) ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:36:11 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									extractModulesAndReturnAffectedChunks ( reallyUsedModules ,  usedChunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:55:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										return  reallyUsedModules . reduce ( ( affectedChunksSet ,  module )  =>  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for ( const  chunk  of  usedChunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:55:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												// removeChunk returns true if the chunk was contained and succesfully removed
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												// false if the module did not have a connection to the chunk in question
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												if ( module . removeChunk ( chunk ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													affectedChunksSet . add ( chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											return  affectedChunksSet ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} ,  new  Set ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									addExtractedModulesToTargetChunk ( chunk ,  modules )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for ( const  module  of  modules )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 13:55:04 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											chunk . addModule ( module ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											module . addChunk ( chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									makeTargetChunkParentOfAffectedChunks ( usedChunks ,  commonChunk )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for ( const  chunk  of  usedChunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:11:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											// set commonChunk as new sole parent
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											chunk . parents  =  [ commonChunk ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											// add chunk to commonChunk
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											commonChunk . addChunk ( chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											for ( const  entrypoint  of  chunk . entrypoints )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:11:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												entrypoint . insertChunk ( commonChunk ,  chunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:32:31 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									moveExtractedChunkBlocksToTargetChunk ( chunks ,  targetChunk )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for ( const  chunk  of  chunks )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											if ( chunk  ===  targetChunk )  continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for ( const  block  of  chunk . blocks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-05-31 11:56:34 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												if ( block . chunks . indexOf ( targetChunk )  ===  - 1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
													block . chunks . unshift ( targetChunk ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-22 18:35:50 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												targetChunk . addBlock ( block ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:11:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-02-21 18:22:10 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
									extractOriginsOfChunksWithExtractedModules ( chunks )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:11:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										const  origins  =  [ ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2017-06-09 21:04:09 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
										for ( const  chunk  of  chunks )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											for ( const  origin  of  chunk . origins )  { 
							 
						 
					
						
							
								
									
										
										
										
											2017-02-19 14:11:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
												const  newOrigin  =  Object . create ( origin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												newOrigin . reasons  =  ( origin . reasons  ||  [ ] ) . concat ( "async commons" ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
												origins . push ( newOrigin ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
										return  origins ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2017-01-04 21:50:00 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								module . exports  =  CommonsChunkPlugin ;