@@ -11,6 +11,7 @@ import webpack, {
11
11
version as webpackVersion ,
12
12
} from 'webpack' ;
13
13
import validateOptions from 'schema-utils' ;
14
+ import serialize from 'serialize-javascript' ;
14
15
15
16
import schema from './options.json' ;
16
17
@@ -52,7 +53,6 @@ class CompressionPlugin {
52
53
} ;
53
54
54
55
this . algorithm = this . options . algorithm ;
55
- this . compressionOptions = this . options . compressionOptions ;
56
56
57
57
if ( typeof this . algorithm === 'string' ) {
58
58
// eslint-disable-next-line global-require
@@ -66,9 +66,9 @@ class CompressionPlugin {
66
66
) ;
67
67
}
68
68
69
- this . compressionOptions = {
69
+ this . options . compressionOptions = {
70
70
...{ level : 9 } ,
71
- ...this . compressionOptions ,
71
+ ...this . options . compressionOptions ,
72
72
} ;
73
73
}
74
74
}
@@ -117,20 +117,22 @@ class CompressionPlugin {
117
117
118
118
runCompressionAlgorithm ( input ) {
119
119
return new Promise ( ( resolve , reject ) => {
120
- const { algorithm, compressionOptions } = this ;
120
+ this . algorithm (
121
+ input ,
122
+ this . options . compressionOptions ,
123
+ ( error , result ) => {
124
+ if ( error ) {
125
+ return reject ( error ) ;
126
+ }
121
127
122
- algorithm ( input , compressionOptions , ( error , result ) => {
123
- if ( error ) {
124
- return reject ( error ) ;
125
- }
128
+ if ( ! Buffer . isBuffer ( result ) ) {
129
+ // eslint-disable-next-line no-param-reassign
130
+ result = Buffer . from ( result ) ;
131
+ }
126
132
127
- if ( ! Buffer . isBuffer ( result ) ) {
128
- // eslint-disable-next-line no-param-reassign
129
- result = Buffer . from ( result ) ;
133
+ return resolve ( result ) ;
130
134
}
131
-
132
- return resolve ( result ) ;
133
- } ) ;
135
+ ) ;
134
136
} ) ;
135
137
}
136
138
@@ -204,12 +206,16 @@ class CompressionPlugin {
204
206
'compression-webpack-plugin' : require ( '../package.json' ) . version ,
205
207
algorithm : this . algorithm ,
206
208
originalAlgorithm : this . options . algorithm ,
207
- compressionOptions : this . compressionOptions ,
209
+ compressionOptions : this . options . compressionOptions ,
208
210
name,
209
211
contentHash : crypto . createHash ( 'md4' ) . update ( input ) . digest ( 'hex' ) ,
210
212
} ;
211
213
} else {
212
- cacheData . name = name ;
214
+ cacheData . name = serialize ( {
215
+ name,
216
+ algorithm : this . options . algorithm ,
217
+ compressionOptions : this . options . compressionOptions ,
218
+ } ) ;
213
219
}
214
220
215
221
let output = await cache . get ( cacheData , { RawSource } ) ;
@@ -282,7 +288,7 @@ class CompressionPlugin {
282
288
// TODO `...` required only for webpack@4
283
289
const newOriginalInfo = {
284
290
...info ,
285
- related : { [ relatedName ] : newName } ,
291
+ related : { [ relatedName ] : newName , ... info . related } ,
286
292
} ;
287
293
288
294
CompressionPlugin . updateAsset (
0 commit comments