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