UNPKG

6.25 kBTypeScriptView Raw
1/// <reference types="node" />
2export = CompressionPlugin;
3/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
4/** @typedef {import("webpack").Compiler} Compiler */
5/** @typedef {import("webpack").WebpackPluginInstance} WebpackPluginInstance */
6/** @typedef {import("webpack").Compilation} Compilation */
7/** @typedef {import("webpack").sources.Source} Source */
8/** @typedef {import("webpack").Asset} Asset */
9/** @typedef {import("webpack").WebpackError} WebpackError */
10/**
11 * @template T
12 * @typedef {T | { valueOf(): T }} WithImplicitCoercion
13 */
14/** @typedef {RegExp | string} Rule */
15/** @typedef {Rule[] | Rule} Rules */
16/**
17 * @typedef {{ [key: string]: any }} CustomOptions
18 */
19/**
20 * @template T
21 * @typedef {T extends infer U ? U : CustomOptions} InferDefaultType
22 */
23/**
24 * @template T
25 * @typedef {InferDefaultType<T>} CompressionOptions
26 */
27/**
28 * @template T
29 * @callback AlgorithmFunction
30 * @param {Buffer} input
31 * @param {CompressionOptions<T>} options
32 * @param {(error: Error | null | undefined, result: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer> | Uint8Array | ReadonlyArray<number> | WithImplicitCoercion<Uint8Array | ReadonlyArray<number> | string> | WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: 'string'): string }) => void} callback
33 */
34/**
35 * @typedef {{[key: string]: any}} PathData
36 */
37/**
38 * @typedef {string | ((fileData: PathData) => string)} Filename
39 */
40/**
41 * @typedef {boolean | "keep-source-map" | ((name: string) => boolean)} DeleteOriginalAssets
42 */
43/**
44 * @template T
45 * @typedef {Object} BasePluginOptions
46 * @property {Rules} [test]
47 * @property {Rules} [include]
48 * @property {Rules} [exclude]
49 * @property {number} [threshold]
50 * @property {number} [minRatio]
51 * @property {DeleteOriginalAssets} [deleteOriginalAssets]
52 * @property {Filename} [filename]
53 */
54/**
55 * @typedef {import("zlib").ZlibOptions} ZlibOptions
56 */
57/**
58 * @template T
59 * @typedef {T extends ZlibOptions ? { algorithm?: string | AlgorithmFunction<T> | undefined, compressionOptions?: CompressionOptions<T> | undefined } : { algorithm: string | AlgorithmFunction<T>, compressionOptions?: CompressionOptions<T> | undefined }} DefinedDefaultAlgorithmAndOptions
60 */
61/**
62 * @template T
63 * @typedef {BasePluginOptions<T> & { algorithm: string | AlgorithmFunction<T>, compressionOptions: CompressionOptions<T>, threshold: number, minRatio: number, deleteOriginalAssets: DeleteOriginalAssets, filename: Filename }} InternalPluginOptions
64 */
65/**
66 * @template [T=ZlibOptions]
67 * @implements WebpackPluginInstance
68 */
69declare class CompressionPlugin<T = import("zlib").ZlibOptions>
70 implements WebpackPluginInstance
71{
72 /**
73 * @param {BasePluginOptions<T> & DefinedDefaultAlgorithmAndOptions<T>} [options]
74 */
75 constructor(
76 options?:
77 | (BasePluginOptions<T> & DefinedDefaultAlgorithmAndOptions<T>)
78 | undefined,
79 );
80 /**
81 * @private
82 * @type {InternalPluginOptions<T>}
83 */
84 private options;
85 /**
86 * @private
87 * @type {AlgorithmFunction<T>}
88 */
89 private algorithm;
90 /**
91 * @private
92 * @param {Buffer} input
93 * @returns {Promise<Buffer>}
94 */
95 private runCompressionAlgorithm;
96 /**
97 * @private
98 * @param {Compiler} compiler
99 * @param {Compilation} compilation
100 * @param {Record<string, Source>} assets
101 * @returns {Promise<void>}
102 */
103 private compress;
104 /**
105 * @param {Compiler} compiler
106 * @returns {void}
107 */
108 apply(compiler: Compiler): void;
109}
110declare namespace CompressionPlugin {
111 export {
112 Schema,
113 Compiler,
114 WebpackPluginInstance,
115 Compilation,
116 Source,
117 Asset,
118 WebpackError,
119 WithImplicitCoercion,
120 Rule,
121 Rules,
122 CustomOptions,
123 InferDefaultType,
124 CompressionOptions,
125 AlgorithmFunction,
126 PathData,
127 Filename,
128 DeleteOriginalAssets,
129 BasePluginOptions,
130 ZlibOptions,
131 DefinedDefaultAlgorithmAndOptions,
132 InternalPluginOptions,
133 };
134}
135type WebpackPluginInstance = import("webpack").WebpackPluginInstance;
136type Schema = import("schema-utils/declarations/validate").Schema;
137type Compiler = import("webpack").Compiler;
138type Compilation = import("webpack").Compilation;
139type Source = import("webpack").sources.Source;
140type Asset = import("webpack").Asset;
141type WebpackError = import("webpack").WebpackError;
142type WithImplicitCoercion<T> =
143 | T
144 | {
145 valueOf(): T;
146 };
147type Rule = RegExp | string;
148type Rules = Rule[] | Rule;
149type CustomOptions = {
150 [key: string]: any;
151};
152type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
153type CompressionOptions<T> = InferDefaultType<T>;
154type AlgorithmFunction<T> = (
155 input: Buffer,
156 options: CompressionOptions<T>,
157 callback: (
158 error: Error | null | undefined,
159 result:
160 | string
161 | ArrayBuffer
162 | SharedArrayBuffer
163 | Uint8Array
164 | readonly number[]
165 | {
166 valueOf(): ArrayBuffer | SharedArrayBuffer;
167 }
168 | {
169 valueOf(): string | Uint8Array | readonly number[];
170 }
171 | {
172 valueOf(): string;
173 }
174 | {
175 [Symbol.toPrimitive](hint: "string"): string;
176 },
177 ) => void,
178) => any;
179type PathData = {
180 [key: string]: any;
181};
182type Filename = string | ((fileData: PathData) => string);
183type DeleteOriginalAssets =
184 | boolean
185 | "keep-source-map"
186 | ((name: string) => boolean);
187type BasePluginOptions<T> = {
188 test?: Rules | undefined;
189 include?: Rules | undefined;
190 exclude?: Rules | undefined;
191 threshold?: number | undefined;
192 minRatio?: number | undefined;
193 deleteOriginalAssets?: DeleteOriginalAssets | undefined;
194 filename?: Filename | undefined;
195};
196type ZlibOptions = import("zlib").ZlibOptions;
197type DefinedDefaultAlgorithmAndOptions<T> = T extends ZlibOptions
198 ? {
199 algorithm?: string | AlgorithmFunction<T> | undefined;
200 compressionOptions?: CompressionOptions<T> | undefined;
201 }
202 : {
203 algorithm: string | AlgorithmFunction<T>;
204 compressionOptions?: CompressionOptions<T> | undefined;
205 };
206type InternalPluginOptions<T> = BasePluginOptions<T> & {
207 algorithm: string | AlgorithmFunction<T>;
208 compressionOptions: CompressionOptions<T>;
209 threshold: number;
210 minRatio: number;
211 deleteOriginalAssets: DeleteOriginalAssets;
212 filename: Filename;
213};
214
\No newline at end of file