1 | export = ImageMinimizerPlugin;
|
2 | /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
|
3 | /** @typedef {import("webpack").WebpackPluginInstance} WebpackPluginInstance */
|
4 | /** @typedef {import("webpack").Compiler} Compiler */
|
5 | /** @typedef {import("webpack").Compilation} Compilation */
|
6 | /** @typedef {import("webpack").WebpackError} WebpackError */
|
7 | /** @typedef {import("webpack").Asset} Asset */
|
8 | /** @typedef {import("webpack").AssetInfo} AssetInfo */
|
9 | /** @typedef {import("./utils.js").imageminMinify} ImageminMinifyFunction */
|
10 | /** @typedef {import("./utils.js").squooshMinify} SquooshMinifyFunction */
|
11 | /** @typedef {RegExp | string} Rule */
|
12 | /** @typedef {Rule[] | Rule} Rules */
|
13 | /**
|
14 | * @callback FilterFn
|
15 | * @param {Buffer} source `Buffer` of source file.
|
16 | * @param {string} sourcePath Absolute path to source.
|
17 | * @returns {boolean}
|
18 | */
|
19 | /**
|
20 | * @typedef {Object} ImageminOptions
|
21 | * @property {Array<string | [string, Record<string, any>?] | import("imagemin").Plugin>} plugins
|
22 | */
|
23 | /**
|
24 | * @typedef {Object.<string, any>} SquooshOptions
|
25 | */
|
26 | /**
|
27 | * @typedef {Object} WorkerResult
|
28 | * @property {string} filename
|
29 | * @property {Buffer} data
|
30 | * @property {Array<Error>} warnings
|
31 | * @property {Array<Error>} errors
|
32 | * @property {AssetInfo} info
|
33 | */
|
34 | /**
|
35 | * @typedef {{ [key: string]: any }} CustomOptions
|
36 | */
|
37 | /**
|
38 | * @template T
|
39 | * @typedef {T extends infer U ? U : CustomOptions} InferDefaultType
|
40 | */
|
41 | /**
|
42 | * @template T
|
43 | * @typedef {InferDefaultType<T> | undefined} BasicTransformerOptions
|
44 | */
|
45 | /**
|
46 | * @template T
|
47 | * @callback BasicTransformerImplementation
|
48 | * @param {WorkerResult} original
|
49 | * @param {BasicTransformerOptions<T>} [options]
|
50 | * @returns {Promise<WorkerResult>}
|
51 | */
|
52 | /**
|
53 | * @typedef {object} BasicTransformerHelpers
|
54 | * @property {() => {}} [setup]
|
55 | * @property {() => {}} [teardown]
|
56 | */
|
57 | /**
|
58 | * @template T
|
59 | * @typedef {BasicTransformerImplementation<T> & BasicTransformerHelpers} TransformerFunction
|
60 | */
|
61 | /**
|
62 | * @typedef {Object} PathData
|
63 | * @property {string} [filename]
|
64 | */
|
65 | /**
|
66 | * @callback FilenameFn
|
67 | * @param {PathData} pathData
|
68 | * @param {AssetInfo} [assetInfo]
|
69 | * @returns {string}
|
70 | */
|
71 | /**
|
72 | * @template T
|
73 | * @typedef {Object} Transformer
|
74 | * @property {TransformerFunction<T>} implementation
|
75 | * @property {BasicTransformerOptions<T>} [options]
|
76 | * @property {FilterFn} [filter]
|
77 | * @property {string | FilenameFn} [filename]
|
78 | * @property {string} [preset]
|
79 | */
|
80 | /**
|
81 | * @template T
|
82 | * @typedef {Omit<Transformer<T>, "preset">} Minimizer
|
83 | */
|
84 | /**
|
85 | * @template T
|
86 | * @typedef {Transformer<T>} Generator
|
87 | */
|
88 | /**
|
89 | * @template T
|
90 | * @typedef {Object} InternalWorkerOptions
|
91 | * @property {string} filename
|
92 | * @property {Buffer} input
|
93 | * @property {Transformer<T> | Transformer<T>[]} transformer
|
94 | * @property {string} [severityError]
|
95 | * @property {Function} [generateFilename]
|
96 | */
|
97 | /**
|
98 | * @template T
|
99 | * @typedef {import("./loader").LoaderOptions<T>} InternalLoaderOptions
|
100 | */
|
101 | /**
|
102 | * @template T, G
|
103 | * @typedef {Object} PluginOptions
|
104 | * @property {Rules} [test] Test to match files against.
|
105 | * @property {Rules} [include] Files to include.
|
106 | * @property {Rules} [exclude] Files to exclude.
|
107 | * @property {T extends any[] ? { [P in keyof T]: Minimizer<T[P]> } : Minimizer<T> | Minimizer<T>[]} [minimizer] Allows to setup the minimizer.
|
108 | * @property {G extends any[] ? { [P in keyof G]: Generator<G[P]> } : Generator<G>[]} [generator] Allows to set the generator.
|
109 | * @property {boolean} [loader] Automatically adding `imagemin-loader`.
|
110 | * @property {number} [concurrency] Maximum number of concurrency optimization processes in one time.
|
111 | * @property {string} [severityError] Allows to choose how errors are displayed.
|
112 | * @property {boolean} [deleteOriginalAssets] Allows to remove original assets. Useful for converting to a `webp` and remove original assets.
|
113 | */
|
114 | /**
|
115 | * @template T, [G=T]
|
116 | * @extends {WebpackPluginInstance}
|
117 | */
|
118 | declare class ImageMinimizerPlugin<T, G = T> {
|
119 | /**
|
120 | * @param {PluginOptions<T, G>} [options={}] Plugin options.
|
121 | */
|
122 | constructor(options?: PluginOptions<T, G> | undefined);
|
123 | /**
|
124 | * @private
|
125 | */
|
126 | private options;
|
127 | /**
|
128 | * @private
|
129 | * @param {Compiler} compiler
|
130 | * {Compilation} compilation
|
131 | * string, import("webpack").sources.Source>} assets
{Record< |
132 | * Promise<void>}
{ |
133 | */
|
134 | private optimize;
|
135 | /**
|
136 | * @private
|
137 | */
|
138 | private setupAll;
|
139 | /**
|
140 | * @private
|
141 | */
|
142 | private teardownAll;
|
143 | /**
|
144 | * @param {import("webpack").Compiler} compiler
|
145 | */
|
146 | apply(compiler: import("webpack").Compiler): void;
|
147 | }
|
148 | declare namespace ImageMinimizerPlugin {
|
149 | export {
|
150 | loader,
|
151 | imageminNormalizeConfig,
|
152 | imageminMinify,
|
153 | imageminGenerate,
|
154 | squooshMinify,
|
155 | squooshGenerate,
|
156 | Schema,
|
157 | WebpackPluginInstance,
|
158 | Compiler,
|
159 | Compilation,
|
160 | WebpackError,
|
161 | Asset,
|
162 | AssetInfo,
|
163 | ImageminMinifyFunction,
|
164 | SquooshMinifyFunction,
|
165 | Rule,
|
166 | Rules,
|
167 | FilterFn,
|
168 | ImageminOptions,
|
169 | SquooshOptions,
|
170 | WorkerResult,
|
171 | CustomOptions,
|
172 | InferDefaultType,
|
173 | BasicTransformerOptions,
|
174 | BasicTransformerImplementation,
|
175 | BasicTransformerHelpers,
|
176 | TransformerFunction,
|
177 | PathData,
|
178 | FilenameFn,
|
179 | Transformer,
|
180 | Minimizer,
|
181 | Generator,
|
182 | InternalWorkerOptions,
|
183 | InternalLoaderOptions,
|
184 | PluginOptions,
|
185 | };
|
186 | }
|
187 | type PluginOptions<T, G> = {
|
188 | /**
|
189 | * Test to match files against.
|
190 | */
|
191 | test?: Rules | undefined;
|
192 | /**
|
193 | * Files to include.
|
194 | */
|
195 | include?: Rules | undefined;
|
196 | /**
|
197 | * Files to exclude.
|
198 | */
|
199 | exclude?: Rules | undefined;
|
200 | /**
|
201 | * Allows to setup the minimizer.
|
202 | */
|
203 | minimizer?:
|
204 | | (T extends any[]
|
205 | ? { [P in keyof T]: Minimizer<T[P]> }
|
206 | : Minimizer<T> | Minimizer<T>[])
|
207 | | undefined;
|
208 | /**
|
209 | * Allows to set the generator.
|
210 | */
|
211 | generator?:
|
212 | | (G extends any[]
|
213 | ? { [P_1 in keyof G]: Generator<G[P_1]> }
|
214 | : Generator<G>[])
|
215 | | undefined;
|
216 | /**
|
217 | * Automatically adding `imagemin-loader`.
|
218 | */
|
219 | loader?: boolean | undefined;
|
220 | /**
|
221 | * Maximum number of concurrency optimization processes in one time.
|
222 | */
|
223 | concurrency?: number | undefined;
|
224 | /**
|
225 | * Allows to choose how errors are displayed.
|
226 | */
|
227 | severityError?: string | undefined;
|
228 | /**
|
229 | * Allows to remove original assets. Useful for converting to a `webp` and remove original assets.
|
230 | */
|
231 | deleteOriginalAssets?: boolean | undefined;
|
232 | };
|
233 | declare var loader: string;
|
234 | import { imageminNormalizeConfig } from "./utils.js";
|
235 | import { imageminMinify } from "./utils.js";
|
236 | import { imageminGenerate } from "./utils.js";
|
237 | import { squooshMinify } from "./utils.js";
|
238 | import { squooshGenerate } from "./utils.js";
|
239 | type Schema = import("schema-utils/declarations/validate").Schema;
|
240 | type WebpackPluginInstance = import("webpack").WebpackPluginInstance;
|
241 | type Compiler = import("webpack").Compiler;
|
242 | type Compilation = import("webpack").Compilation;
|
243 | type WebpackError = import("webpack").WebpackError;
|
244 | type Asset = import("webpack").Asset;
|
245 | type AssetInfo = import("webpack").AssetInfo;
|
246 | type ImageminMinifyFunction = typeof imageminMinify;
|
247 | type SquooshMinifyFunction = typeof squooshMinify;
|
248 | type Rule = RegExp | string;
|
249 | type Rules = Rule[] | Rule;
|
250 | type FilterFn = (source: Buffer, sourcePath: string) => boolean;
|
251 | type ImageminOptions = {
|
252 | plugins: Array<
|
253 | string | [string, Record<string, any>?] | import("imagemin").Plugin
|
254 | >;
|
255 | };
|
256 | type SquooshOptions = {
|
257 | [x: string]: any;
|
258 | };
|
259 | type WorkerResult = {
|
260 | filename: string;
|
261 | data: Buffer;
|
262 | warnings: Array<Error>;
|
263 | errors: Array<Error>;
|
264 | info: AssetInfo;
|
265 | };
|
266 | type CustomOptions = {
|
267 | [key: string]: any;
|
268 | };
|
269 | type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
|
270 | type BasicTransformerOptions<T> = InferDefaultType<T> | undefined;
|
271 | type BasicTransformerImplementation<T> = (
|
272 | original: WorkerResult,
|
273 | options?: BasicTransformerOptions<T>
|
274 | ) => Promise<WorkerResult>;
|
275 | type BasicTransformerHelpers = {
|
276 | setup?: (() => {}) | undefined;
|
277 | teardown?: (() => {}) | undefined;
|
278 | };
|
279 | type TransformerFunction<T> = BasicTransformerImplementation<T> &
|
280 | BasicTransformerHelpers;
|
281 | type PathData = {
|
282 | filename?: string | undefined;
|
283 | };
|
284 | type FilenameFn = (
|
285 | pathData: PathData,
|
286 | assetInfo?: import("webpack").AssetInfo | undefined
|
287 | ) => string;
|
288 | type Transformer<T> = {
|
289 | implementation: TransformerFunction<T>;
|
290 | options?: BasicTransformerOptions<T>;
|
291 | filter?: FilterFn | undefined;
|
292 | filename?: string | FilenameFn | undefined;
|
293 | preset?: string | undefined;
|
294 | };
|
295 | type Minimizer<T> = Omit<Transformer<T>, "preset">;
|
296 | type Generator<T> = Transformer<T>;
|
297 | type InternalWorkerOptions<T> = {
|
298 | filename: string;
|
299 | input: Buffer;
|
300 | transformer: Transformer<T> | Transformer<T>[];
|
301 | severityError?: string | undefined;
|
302 | generateFilename?: Function | undefined;
|
303 | };
|
304 | type InternalLoaderOptions<T> = import("./loader").LoaderOptions<T>;
|