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