mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
Expand allowed types for result callback to be compatible with patched version: https://github.com/webpack-contrib/compression-webpack-plugin/compare/v5.0.1...v5.0.2 https://github.com/webpack-contrib/compression-webpack-plugin/pull/190 https://github.com/gfx/universal-zopfli-js/blob/master/src/index.ts#L87 /cc @vitoyucepi Thanks! Fixes: #47230
105 lines
3.1 KiB
TypeScript
105 lines
3.1 KiB
TypeScript
// Type definitions for compression-webpack-plugin 4.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>
|
|
// Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
|
|
import { Plugin } from 'webpack';
|
|
import { ZlibOptions as ZlibCompressionOptions } from 'zlib';
|
|
|
|
export = CompressionPlugin;
|
|
|
|
/**
|
|
* Prepare compressed versions of assets to serve them with Content-Encoding.
|
|
*/
|
|
declare class CompressionPlugin<O = any> extends Plugin {
|
|
static isWebpack4(): boolean;
|
|
constructor(options?: CompressionPlugin.Options<O>);
|
|
}
|
|
|
|
declare namespace CompressionPlugin {
|
|
type AlgorithmCallback = (error: Error | null, result: Uint8Array) => 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' | 'brotliCompress';
|
|
|
|
/** Filtering rule as regex or string */
|
|
type Rule = string | RegExp;
|
|
|
|
/** Filtering rules. */
|
|
type Rules = Rule | ReadonlyArray<Rule>;
|
|
|
|
interface FileInfo {
|
|
/** original asset filename */
|
|
file: string;
|
|
/** path of the original asset */
|
|
path: string;
|
|
/** query */
|
|
query: string;
|
|
}
|
|
|
|
type FilenameFunction = (info: FileInfo) => string;
|
|
|
|
interface BaseOptions {
|
|
/**
|
|
* Enable file caching
|
|
* ⚠ Ignored in webpack 5! Please use webpack.js.org/configuration/other-options/#cache.
|
|
* @default true
|
|
*/
|
|
cache?: boolean | string;
|
|
/**
|
|
* @default false
|
|
*/
|
|
deleteOriginalAssets?: boolean;
|
|
/**
|
|
* Exclude all assets matching any of these conditions
|
|
*/
|
|
exclude?: Rules;
|
|
/**
|
|
* The target asset filename.
|
|
* @default '[path].gz[query]'
|
|
*/
|
|
filename?: string | FilenameFunction;
|
|
/**
|
|
* Include all assets matching any of these conditions
|
|
*/
|
|
include?: Rules;
|
|
/**
|
|
* Only assets that compress better than this ratio are processed (minRatio = Compressed Size / Original Size)
|
|
* @default 0.8
|
|
*/
|
|
minRatio?: number;
|
|
/**
|
|
* Include all assets that pass test assertion
|
|
*/
|
|
test?: Rules;
|
|
/**
|
|
* Only assets bigger than this size are processed (in bytes)
|
|
* @default 0
|
|
*/
|
|
threshold?: number;
|
|
}
|
|
|
|
interface ZlibOptions extends BaseOptions {
|
|
/**
|
|
* The compression algorithm/function
|
|
* @default 'gzip'
|
|
*/
|
|
algorithm?: ZlibAlgorithm;
|
|
/**
|
|
* Compression options for algorithm
|
|
* @default { level: 9 }
|
|
*/
|
|
compressionOptions?: ZlibCompressionOptions;
|
|
}
|
|
|
|
interface CustomOptions<O> extends BaseOptions {
|
|
algorithm: Algorithm<O>;
|
|
compressionOptions?: O;
|
|
}
|
|
|
|
type Options<O> = ZlibOptions | CustomOptions<O>;
|
|
}
|