@@ -11,36 +11,38 @@ function CompressionPlugin(options) {
11
11
options = options || { } ;
12
12
this . asset = options . asset || "[path].gz[query]" ;
13
13
this . algorithm = options . algorithm || "gzip" ;
14
+ this . compressionOptions = { } ;
14
15
if ( typeof this . algorithm === "string" ) {
15
16
if ( this . algorithm === "zopfli" ) {
16
17
try {
17
18
var zopfli = require ( "node-zopfli" ) ;
18
19
} catch ( err ) {
19
20
throw new Error ( "node-zopfli not found" ) ;
20
21
}
21
- this . algorithm = function ( content , fn ) {
22
- zopfli . gzip ( content , {
23
- verbose : options . hasOwnProperty ( 'verbose' ) ? options . verbose : false ,
24
- verbose_more : options . hasOwnProperty ( 'verbose_more' ) ? options . verbose_more : false ,
25
- numiterations : options . numiterations ? options . numiterations : 15 ,
26
- blocksplitting : options . hasOwnProperty ( 'blocksplitting' ) ? options . blocksplitting : true ,
27
- blocksplittinglast : options . hasOwnProperty ( 'blocksplittinglast' ) ? options . blocksplittinglast : false ,
28
- blocksplittingmax : options . blocksplittingmax ? options . blocksplittingmax : 15
29
- } , fn ) ;
22
+ this . compressionOptions = {
23
+ verbose : options . hasOwnProperty ( 'verbose' ) ? options . verbose : false ,
24
+ verbose_more : options . hasOwnProperty ( 'verbose_more' ) ? options . verbose_more : false ,
25
+ numiterations : options . numiterations ? options . numiterations : 15 ,
26
+ blocksplitting : options . hasOwnProperty ( 'blocksplitting' ) ? options . blocksplitting : true ,
27
+ blocksplittinglast : options . hasOwnProperty ( 'blocksplittinglast' ) ? options . blocksplittinglast : false ,
28
+ blocksplittingmax : options . blocksplittingmax ? options . blocksplittingmax : 15
29
+ } ;
30
+ this . algorithm = function ( content , options , fn ) {
31
+ zopfli . gzip ( content , options , fn ) ;
30
32
} ;
31
33
} else {
32
34
var zlib = require ( "zlib" ) ;
33
35
this . algorithm = zlib [ this . algorithm ] ;
34
36
if ( ! this . algorithm ) throw new Error ( "Algorithm not found in zlib" ) ;
35
- this . algorithm = this . algorithm . bind ( zlib , {
37
+ this . compressionOptions = {
36
38
level : options . level || 9 ,
37
39
flush : options . flush ,
38
40
chunkSize : options . chunkSize ,
39
41
windowBits : options . windowBits ,
40
42
memLevel : options . memLevel ,
41
43
strategy : options . strategy ,
42
44
dictionary : options . dictionary
43
- } ) ;
45
+ } ;
44
46
}
45
47
}
46
48
this . test = options . test || options . regExp ;
@@ -65,7 +67,7 @@ CompressionPlugin.prototype.apply = function(compiler) {
65
67
content = new Buffer ( content , "utf-8" ) ;
66
68
var originalSize = content . length ;
67
69
if ( originalSize < this . threshold ) return callback ( ) ;
68
- this . algorithm ( content , function ( err , result ) {
70
+ this . algorithm ( content , this . compressionOptions , function ( err , result ) {
69
71
if ( err ) return callback ( err ) ;
70
72
if ( result . length / originalSize > this . minRatio ) return callback ( ) ;
71
73
var parse = url . parse ( file ) ;
0 commit comments