File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -12,10 +12,28 @@ function CompressionPlugin(options) {
1212 this . asset = options . asset || "{file}.gz" ;
1313 this . algorithm = options . algorithm || "gzip" ;
1414 if ( typeof this . algorithm === "string" ) {
15- var zlib = require ( "zlib" ) ;
16- this . algorithm = zlib [ this . algorithm ] ;
17- if ( ! this . algorithm ) throw new Error ( "Algorithm not found in zlib" ) ;
18- this . algorithm = this . algorithm . bind ( zlib ) ;
15+ if ( this . algorithm === "zopfli" ) {
16+ try {
17+ var zopfli = require ( "node-zopfli" ) ;
18+ } catch ( err ) {
19+ throw new Error ( "node-zopfli not found" ) ;
20+ }
21+ this . algorithm = function ( content , fn ) {
22+ zopfli . gzip ( content , {
23+ verbose : true ,
24+ verbose_more : false ,
25+ numiterations : 15 ,
26+ blocksplitting : true ,
27+ blocksplittinglast : false ,
28+ blocksplittingmax : 15
29+ } , fn ) ;
30+ } ;
31+ } else {
32+ var zlib = require ( "zlib" ) ;
33+ this . algorithm = zlib [ this . algorithm ] ;
34+ if ( ! this . algorithm ) throw new Error ( "Algorithm not found in zlib" ) ;
35+ this . algorithm = this . algorithm . bind ( zlib ) ;
36+ }
1937 }
2038 this . regExp = options . regExp ;
2139 this . threshold = options . threshold || 0 ;
Original file line number Diff line number Diff line change 99 "dependencies" : {
1010 "async" : " 0.2.x"
1111 },
12+ "optionalDependencies" : {
13+ "node-zopfli" : " ^1.3.4"
14+ },
1215 "homepage" : " http://github.com/webpack/compression-webpack-plugin" ,
1316 "repository" : {
1417 "type" : " git" ,
You can’t perform that action at this time.
0 commit comments