Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2c22b1c

Browse files
rufmanjoshwiens
authored andcommitted
feat: Add node-zopfli option
1 parent 3e40d37 commit 2c22b1c

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

index.js

+22-4
Original file line numberDiff line numberDiff 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;

package.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
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",

0 commit comments

Comments
 (0)