mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Merge pull request #30642 from rhys-vdw/update-compression-webpack-plugin-to-2.0.0
[compression-webpack-plugin] Update to 2.0.0
This commit is contained in:
@@ -1,15 +1,76 @@
|
||||
import { Configuration } from 'webpack';
|
||||
import CompressionPlugin = require('compression-webpack-plugin');
|
||||
|
||||
const c: Configuration = {
|
||||
new CompressionPlugin();
|
||||
|
||||
new CompressionPlugin({
|
||||
include: ["a"] as ReadonlyArray<string>,
|
||||
exclude: [/a/g] as ReadonlyArray<RegExp>,
|
||||
test: "a",
|
||||
});
|
||||
|
||||
const config: Configuration = {
|
||||
plugins: [
|
||||
new CompressionPlugin({
|
||||
asset: "[path].gz[query]",
|
||||
algorithm: "gzip",
|
||||
cache: true,
|
||||
filename: "[path].gz[query]",
|
||||
minRatio: 0.8,
|
||||
test: /\.js$|\.html$/,
|
||||
threshold: 10240,
|
||||
minRatio: 0.8
|
||||
deleteOriginalAssets: true
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
const configDefaultAlgo = new CompressionPlugin({
|
||||
compressionOptions: { level: 7 }
|
||||
});
|
||||
|
||||
// $ExpectError
|
||||
new CompressionPlugin({ asset: "[path].gz[query]" });
|
||||
|
||||
const zlib: Configuration = {
|
||||
plugins: [
|
||||
new CompressionPlugin({
|
||||
algorithm: "deflate",
|
||||
compressionOptions: {
|
||||
flush: 5,
|
||||
windowBits: 20,
|
||||
level: 7
|
||||
}
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
const badZlib: Configuration = {
|
||||
plugins: [
|
||||
// $ExpectError
|
||||
new CompressionPlugin({
|
||||
algorithm: "deflate",
|
||||
compressionOptions: 5
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
function customAlgorithm(input: string, options: number, callback: (err: Error, result: Buffer) => void) {
|
||||
}
|
||||
|
||||
const custom: Configuration = {
|
||||
plugins: [
|
||||
new CompressionPlugin({
|
||||
algorithm: customAlgorithm,
|
||||
compressionOptions: 5
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
const badCustom: Configuration = {
|
||||
plugins: [
|
||||
// $ExpectError
|
||||
new CompressionPlugin({
|
||||
algorithm: customAlgorithm,
|
||||
compressionOptions: { flush: 5 }
|
||||
})
|
||||
]
|
||||
};
|
||||
|
||||
+32
-27
@@ -1,42 +1,47 @@
|
||||
// Type definitions for compression-webpack-plugin 0.4
|
||||
// Type definitions for compression-webpack-plugin 2.0
|
||||
// Project: https://github.com/webpack-contrib/compression-webpack-plugin
|
||||
// Definitions by: Anton Kandybo <https://github.com/dublicator>
|
||||
// Rhys van der Waerden <https://github.com/rhys-vdw>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
// TypeScript Version: 2.4
|
||||
|
||||
import { Plugin } from 'webpack';
|
||||
import { ZlibOptions as ZlibCompressionOptions } from 'zlib';
|
||||
|
||||
export = CompressionPlugin;
|
||||
|
||||
declare class CompressionPlugin extends Plugin {
|
||||
constructor(options?: CompressionPlugin.Options);
|
||||
declare class CompressionPlugin<O = any> extends Plugin {
|
||||
constructor(options?: CompressionPlugin.Options<O>);
|
||||
}
|
||||
|
||||
declare namespace CompressionPlugin {
|
||||
interface Options {
|
||||
asset?: string;
|
||||
algorithm?: string;
|
||||
type AlgorithmCallback = (error: Error | null, result: Buffer) => void;
|
||||
type Algorithm<O> = (source: string, options: O, callback: AlgorithmCallback) => void;
|
||||
|
||||
// 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 {
|
||||
cache?: boolean | string;
|
||||
test?: RegExp | RegExp[];
|
||||
regExp?: RegExp | RegExp[];
|
||||
threshold?: number;
|
||||
deleteOriginalAssets?: boolean;
|
||||
exclude?: Pattern;
|
||||
filename?: string;
|
||||
include?: Pattern;
|
||||
minRatio?: number;
|
||||
|
||||
// zopfli options
|
||||
verbose?: boolean;
|
||||
verbose_more?: boolean;
|
||||
numiterations?: number;
|
||||
blocksplitting?: boolean;
|
||||
blocksplittinglast?: boolean;
|
||||
blocksplittingmax?: number;
|
||||
|
||||
// zlib options
|
||||
level?: number;
|
||||
flush?: number;
|
||||
chunkSize?: number;
|
||||
windowBits?: number;
|
||||
memLevel?: number;
|
||||
strategy?: number;
|
||||
dictionary?: any;
|
||||
test?: Pattern;
|
||||
threshold?: number;
|
||||
}
|
||||
|
||||
interface ZlibOptions extends BaseOptions {
|
||||
algorithm?: ZlibAlgorithm;
|
||||
compressionOptions?: ZlibCompressionOptions;
|
||||
}
|
||||
|
||||
interface CustomOptions<O> extends BaseOptions {
|
||||
algorithm: Algorithm<O>;
|
||||
compressionOptions?: O;
|
||||
}
|
||||
|
||||
type Options<O> = ZlibOptions | CustomOptions<O>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user