File tree 2 files changed +25
-4
lines changed
2 files changed +25
-4
lines changed Original file line number Diff line number Diff line change @@ -12,10 +12,28 @@ function CompressionPlugin(options) {
12
12
this . asset = options . asset || "{file}.gz" ;
13
13
this . algorithm = options . algorithm || "gzip" ;
14
14
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
+ }
19
37
}
20
38
this . regExp = options . regExp ;
21
39
this . threshold = options . threshold || 0 ;
Original file line number Diff line number Diff line change 9
9
"dependencies" : {
10
10
"async" : " 0.2.x"
11
11
},
12
+ "optionalDependencies" : {
13
+ "node-zopfli" : " ^1.3.4"
14
+ },
12
15
"homepage" : " http://github.com/webpack/compression-webpack-plugin" ,
13
16
"repository" : {
14
17
"type" : " git" ,
You can’t perform that action at this time.
0 commit comments