@@ -11,30 +11,29 @@ function CompressionPlugin(options) {
1111 options = options || { } ;
1212 this . asset = options . asset || "[path].gz[query]" ;
1313 this . algorithm = options . algorithm || "gzip" ;
14- this . compressionOptions = { } ;
1514 if ( typeof this . algorithm === "string" ) {
1615 if ( this . algorithm === "zopfli" ) {
1716 try {
1817 var zopfli = require ( "node-zopfli" ) ;
1918 } catch ( err ) {
2019 throw new Error ( "node-zopfli not found" ) ;
2120 }
22- this . compressionOptions = {
21+ var compressionOptions = {
2322 verbose : options . hasOwnProperty ( 'verbose' ) ? options . verbose : false ,
2423 verbose_more : options . hasOwnProperty ( 'verbose_more' ) ? options . verbose_more : false ,
2524 numiterations : options . numiterations ? options . numiterations : 15 ,
2625 blocksplitting : options . hasOwnProperty ( 'blocksplitting' ) ? options . blocksplitting : true ,
2726 blocksplittinglast : options . hasOwnProperty ( 'blocksplittinglast' ) ? options . blocksplittinglast : false ,
2827 blocksplittingmax : options . blocksplittingmax ? options . blocksplittingmax : 15
2928 } ;
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 ) ;
3231 } ;
3332 } else {
3433 var zlib = require ( "zlib" ) ;
35- this . algorithm = zlib [ this . algorithm ] ;
34+ var algorithm = zlib [ this . algorithm ] ;
3635 if ( ! this . algorithm ) throw new Error ( "Algorithm not found in zlib" ) ;
37- this . compressionOptions = {
36+ var compressionOptions = {
3837 level : options . level || 9 ,
3938 flush : options . flush ,
4039 chunkSize : options . chunkSize ,
@@ -43,6 +42,9 @@ function CompressionPlugin(options) {
4342 strategy : options . strategy ,
4443 dictionary : options . dictionary
4544 } ;
45+ this . algorithm = function ( content , fn ) {
46+ algorithm ( content , compressionOptions , fn ) ;
47+ } ;
4648 }
4749 }
4850 this . test = options . test || options . regExp ;
@@ -68,7 +70,7 @@ CompressionPlugin.prototype.apply = function(compiler) {
6870 content = new Buffer ( content , "utf-8" ) ;
6971 var originalSize = content . length ;
7072 if ( originalSize < this . threshold ) return callback ( ) ;
71- this . algorithm ( content , this . compressionOptions , function ( err , result ) {
73+ this . algorithm ( content , function ( err , result ) {
7274 if ( err ) return callback ( err ) ;
7375 if ( result . length / originalSize > this . minRatio ) return callback ( ) ;
7476 var parse = url . parse ( file ) ;
0 commit comments