File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,15 @@ Object {
100100} 
101101` 
102102
103+ exports [` should use the hash from HtmlWebpackPlugin if option is set 1` =  ` 
104+ Object {  
105+   " css" Array  [], 
106+   " js" Array  [ 
107+     " my-file.js?testHash"  
108+   ], 
109+ } 
110+ ` 
111+ 
103112exports [` should used passed in publicPath 1` =  ` 
104113Object {  
105114  " css" Array  [], 
Original file line number Diff line number Diff line change @@ -143,9 +143,14 @@ export default class AddAssetHtmlPlugin {
143143
144144    let  suffix  =  '' ; 
145145    if  ( hash )  { 
146-       const  md5  =  crypto . createHash ( 'md5' ) ; 
147-       md5 . update ( compilation . assets [ addedFilename ] . source ( ) ) ; 
148-       suffix  =  `?${ md5 . digest ( 'hex' ) . substr ( 0 ,  20 ) }  ; 
146+       // if the hash is set by html-webpack-plugin use that hash, else generate a new one 
147+       if  ( compilation . hash )  { 
148+         suffix  =  `?${ compilation . hash }  ; 
149+       }  else  { 
150+         const  md5  =  crypto . createHash ( 'md5' ) ; 
151+         md5 . update ( compilation . assets [ addedFilename ] . source ( ) ) ; 
152+         suffix  =  `?${ md5 . digest ( 'hex' ) . substr ( 0 ,  20 ) }  ; 
153+       } 
149154    } 
150155
151156    const  resolvedPublicPath  = 
Original file line number Diff line number Diff line change @@ -138,6 +138,22 @@ test('should skip adding sourcemap and gzipped files to compilation if set to fa
138138  expect ( addFileToAssetsStub ) . toHaveBeenCalledWith ( 'my-file.js' ,  compilation ) ; 
139139} ) ; 
140140
141+ test ( 'should use the hash from HtmlWebpackPlugin if option is set' ,  async  ( )  =>  { 
142+   const  compilation  =  { 
143+     hash : 'testHash' , 
144+     options : {  output : { }  } , 
145+     assets : { 
146+       'my-file.js' : {  source : ( )  =>  'some source code is cool to have;'  } , 
147+     } , 
148+   } ; 
149+   const  pluginData  =  Object . assign ( {  assets : {  js : [ ] ,  css : [ ]  }  } ,  pluginMock ) ; 
150+   const  plugin  =  new  AddAssetHtmlPlugin ( {  filepath : 'my-file.js' ,  hash : true  } ) ; 
151+ 
152+   await  plugin . addAllAssetsToCompilation ( compilation ,  pluginData ) ; 
153+ 
154+   expect ( pluginData . assets ) . toMatchSnapshot ( ) ; 
155+ } ) ; 
156+ 
141157test ( 'should include hash of file content if option is set' ,  async  ( )  =>  { 
142158  const  compilation  =  { 
143159    options : {  output : { }  } , 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments