UNPKG

3.98 kBTypeScriptView Raw
1export default ImageMinimizerPlugin;
2export type WebpackPluginInstance = import('webpack').WebpackPluginInstance;
3export type Compiler = import('webpack').Compiler;
4export type Compilation = import('webpack').Compilation;
5export type Filter = (source: Buffer, sourcePath: string) => boolean;
6export type PluginOptions = {
7 /**
8 * Allows filtering of images for optimization.
9 */
10 filter?: Filter | undefined;
11 /**
12 * Test to match files against.
13 */
14 test?: string | RegExp | (string | RegExp)[] | undefined;
15 /**
16 * Files to include.
17 */
18 include?: string | RegExp | (string | RegExp)[] | undefined;
19 /**
20 * Files to exclude.
21 */
22 exclude?: string | RegExp | (string | RegExp)[] | undefined;
23 /**
24 * Allows to choose how errors are displayed.
25 */
26 severityError?: string | boolean | undefined;
27 /**
28 * Options for `imagemin`.
29 */
30 minimizerOptions?: Object | undefined;
31 /**
32 * Automatically adding `imagemin-loader`.
33 */
34 loader?: boolean | undefined;
35 /**
36 * Maximum number of concurrency optimization processes in one time.
37 */
38 maxConcurrency?: number | undefined;
39 /**
40 * Allows to set the filename for the generated asset. Useful for converting to a `webp`.
41 */
42 filename?: string | undefined;
43 /**
44 * Allows to remove original assets. Useful for converting to a `webp` and remove original assets.
45 */
46 deleteOriginalAssets?: boolean | undefined;
47};
48/** @typedef {import("webpack").WebpackPluginInstance} WebpackPluginInstance */
49/** @typedef {import("webpack").Compiler} Compiler */
50/** @typedef {import("webpack").Compilation} Compilation */
51/**
52 * @callback Filter
53 * @param {Buffer} source `Buffer` of source file.
54 * @param {string} sourcePath Absolute path to source.
55 * @returns {boolean}
56 */
57/**
58 * @typedef {Object} PluginOptions
59 * @property {Filter} [filter=() => true] Allows filtering of images for optimization.
60 * @property {string|RegExp|Array<string|RegExp>} [test=/\.(jpe?g|png|gif|tif|webp|svg|avif)$/i] Test to match files against.
61 * @property {string|RegExp|Array<string|RegExp>} [include] Files to include.
62 * @property {string|RegExp|Array<string|RegExp>} [exclude] Files to exclude.
63 * @property {boolean|string} [severityError='auto'] Allows to choose how errors are displayed.
64 * @property {Object} [minimizerOptions={plugins: []}] Options for `imagemin`.
65 * @property {boolean} [loader=true] Automatically adding `imagemin-loader`.
66 * @property {number} [maxConcurrency=Math.max(1, os.cpus().length - 1)] Maximum number of concurrency optimization processes in one time.
67 * @property {string} [filename='[path][name][ext]'] Allows to set the filename for the generated asset. Useful for converting to a `webp`.
68 * @property {boolean} [deleteOriginalAssets=false] Allows to remove original assets. Useful for converting to a `webp` and remove original assets.
69 */
70/**
71 * @extends {WebpackPluginInstance}
72 */
73declare class ImageMinimizerPlugin {
74 /**
75 * @param {PluginOptions} [options={}] Plugin options.
76 */
77 constructor(options?: PluginOptions | undefined);
78 options: {
79 severityError: string | boolean | undefined;
80 filter: Filter;
81 exclude: string | RegExp | (string | RegExp)[] | undefined;
82 minimizerOptions:
83 | Object
84 | {
85 plugins: never[];
86 };
87 include: string | RegExp | (string | RegExp)[] | undefined;
88 loader: boolean;
89 maxConcurrency: number | undefined;
90 test: string | RegExp | (string | RegExp)[];
91 filename: string;
92 deleteOriginalAssets: boolean;
93 };
94 /**
95 * @private
96 * @param {Compiler} compiler
97 * @param {Compilation} compilation
98 * @param assets
99 * @param moduleAssets
100 * @returns {Promise<void>}
101 */
102 private optimize;
103 /**
104 * @param {import("webpack").Compiler} compiler
105 */
106 apply(compiler: import('webpack').Compiler): void;
107}
108declare namespace ImageMinimizerPlugin {
109 const loader: string;
110 const normalizeConfig: typeof import('./utils/normalize-config').default;
111}