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

Commit 328048a

Browse files
authored
refactor: Drops optional Zopfli dependency (#65)
- Zopfli has been broken out to it's own repo. BREAKING CHANGE: The optional dependency for Zopfli was causing issues in consumers CI / CD chains, this option has now been removed. MIGRATION: Zopfli is now in it's own plugin the options have remained the same. For those using the Zopfli option in `compression-webpack-plugin` swap it out for `https://github.com/webpack-contrib/zopfli-webpack-plugin`
1 parent c5f7a0f commit 328048a

File tree

1 file changed

+14
-33
lines changed

1 file changed

+14
-33
lines changed

src/index.js

+14-33
Original file line numberDiff line numberDiff line change
@@ -14,41 +14,22 @@ class CompressionPlugin {
1414
this.compressionOptions = {};
1515

1616
if (typeof this.algorithm === 'string') {
17-
if (this.algorithm === 'zopfli') {
18-
try {
19-
const zopfli = require('node-zopfli'); // eslint-disable-line no-unused-vars
20-
} catch (err) {
21-
throw new Error('node-zopfli not found');
22-
}
23-
this.compressionOptions = {
24-
verbose: hasOwnProperty.call(options, 'verbose') ? options.verbose : false,
25-
verbose_more: hasOwnProperty.call(options, 'verbose_more') ? options.verbose_more : false,
26-
numiterations: options.numiterations ? options.numiterations : 15,
27-
blocksplitting: hasOwnProperty.call(options, 'blocksplitting') ? options.blocksplitting : true,
28-
blocksplittinglast: hasOwnProperty.call(options, 'blocksplittinglast') ? options.blocksplittinglast : false,
29-
blocksplittingmax: options.blocksplittingmax ? options.blocksplittingmax : 15,
30-
};
31-
this.algorithm = (content, options, fn) => {
32-
zopfli.gzip(content, options, fn);
33-
};
34-
} else {
35-
const zlib = require('zlib');
36-
this.algorithm = zlib[this.algorithm];
17+
const zlib = require('zlib');
18+
this.algorithm = zlib[this.algorithm];
3719

38-
if (!this.algorithm) {
39-
throw new Error('Algorithm not found in zlib');
40-
}
41-
42-
this.compressionOptions = {
43-
level: options.level || 9,
44-
flush: options.flush,
45-
chunkSize: options.chunkSize,
46-
windowBits: options.windowBits,
47-
memLevel: options.memLevel,
48-
strategy: options.strategy,
49-
dictionary: options.dictionary,
50-
};
20+
if (!this.algorithm) {
21+
throw new Error('Algorithm not found in zlib');
5122
}
23+
24+
this.compressionOptions = {
25+
level: options.level || 9,
26+
flush: options.flush,
27+
chunkSize: options.chunkSize,
28+
windowBits: options.windowBits,
29+
memLevel: options.memLevel,
30+
strategy: options.strategy,
31+
dictionary: options.dictionary,
32+
};
5233
}
5334
this.test = options.test || options.regExp;
5435
this.threshold = options.threshold || 0;

0 commit comments

Comments
 (0)