compression-webpack-plugin: Update options

- Add `include`/`exclude`
- Remove `regExp` which was undocumented (possibly always wrong?)
- Add `deleteOriginalAssets`
- Prefer `ReadonlyArray` for string/regex options
This commit is contained in:
Rhys van der Waerden 2018-11-19 12:08:39 +11:00
parent 3fc7e12463
commit d747999875
2 changed files with 17 additions and 7 deletions

View File

@ -3,15 +3,22 @@ import CompressionPlugin = require('compression-webpack-plugin');
new CompressionPlugin();
new CompressionPlugin({
include: ["a"] as ReadonlyArray<string>,
exclude: [/a/g] as ReadonlyArray<RegExp>,
test: "a",
});
const config: Configuration = {
plugins: [
new CompressionPlugin({
filename: "[path].gz[query]",
algorithm: "gzip",
cache: true,
filename: "[path].gz[query]",
minRatio: 0.8,
test: /\.js$|\.html$/,
threshold: 10240,
minRatio: 0.8
deleteOriginalAssets: true
})
]
};

View File

@ -17,16 +17,19 @@ declare namespace CompressionPlugin {
type AlgorithmCallback = (error: Error | null, result: Buffer) => void;
type Algorithm<O> = (source: string, options: O, callback: AlgorithmCallback) => void;
// NOTE: These are the compression algorithms exported by zlib.
// NOTE: These are the async compression algorithms on the zlib object.
type ZlibAlgorithm = 'deflate' | 'deflateRaw' | 'gzip';
type Pattern = string | RegExp | ReadonlyArray<RegExp> | ReadonlyArray<string>;
interface BaseOptions {
filename?: string;
cache?: boolean | string;
test?: RegExp | RegExp[];
regExp?: RegExp | RegExp[];
threshold?: number;
deleteOriginalAssets?: boolean;
exclude?: Pattern;
filename?: string;
include?: Pattern;
minRatio?: number;
test?: Pattern;
threshold?: number;
}
interface ZlibOptions extends BaseOptions {