File tree 3 files changed +33
-3
lines changed
3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -100,6 +100,15 @@ Object {
100
100
}
101
101
` ;
102
102
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
+
103
112
exports [` should used passed in publicPath 1` ] = `
104
113
Object {
105
114
" css" : Array [],
Original file line number Diff line number Diff line change @@ -143,9 +143,14 @@ export default class AddAssetHtmlPlugin {
143
143
144
144
let suffix = '' ;
145
145
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
+ }
149
154
}
150
155
151
156
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
138
138
expect ( addFileToAssetsStub ) . toHaveBeenCalledWith ( 'my-file.js' , compilation ) ;
139
139
} ) ;
140
140
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
+
141
157
test ( 'should include hash of file content if option is set' , async ( ) => {
142
158
const compilation = {
143
159
options : { output : { } } ,
You can’t perform that action at this time.
0 commit comments