UNPKG

6.89 kBTypeScriptView Raw
1export = HtmlMinimizerPlugin;
2/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
3/** @typedef {import("webpack").Compiler} Compiler */
4/** @typedef {import("webpack").Compilation} Compilation */
5/** @typedef {import("webpack").WebpackError} WebpackError */
6/** @typedef {import("webpack").Asset} Asset */
7/** @typedef {import("jest-worker").Worker} JestWorker */
8/** @typedef {import("./utils.js").HtmlMinifierTerserOptions} HtmlMinifierTerserOptions */
9/** @typedef {RegExp | string} Rule */
10/** @typedef {Rule[] | Rule} Rules */
11/**
12 * @typedef {Object} MinimizedResult
13 * @property {string} code
14 * @property {Array<unknown>} [errors]
15 * @property {Array<unknown>} [warnings]
16 */
17/**
18 * @typedef {{ [file: string]: string }} Input
19 */
20/**
21 * @typedef {{ [key: string]: any }} CustomOptions
22 */
23/**
24 * @template T
25 * @typedef {T extends infer U ? U : CustomOptions} InferDefaultType
26 */
27/**
28 * @template T
29 * @typedef {InferDefaultType<T> | undefined} MinimizerOptions
30 */
31/**
32 * @template T
33 * @callback MinimizerImplementation
34 * @param {Input} input
35 * @param {MinimizerOptions<T>} [minimizerOptions]
36 * @returns {Promise<MinimizedResult>}
37 */
38/**
39 * @template T
40 * @typedef {Object} Minimizer
41 * @property {MinimizerImplementation<T>} implementation
42 * @property {MinimizerOptions<T> | undefined} [options]
43 */
44/**
45 * @template T
46 * @typedef {Object} InternalOptions
47 * @property {string} name
48 * @property {string} input
49 * @property {T extends any[] ? { [P in keyof T]: Minimizer<T[P]>; } : Minimizer<T>} minimizer
50 */
51/**
52 * @typedef InternalResult
53 * @property {string} code
54 * @property {Array<any>} warnings
55 * @property {Array<any>} errors
56 */
57/**
58 * @template T
59 * @typedef {JestWorker & { transform: (options: string) => InternalResult, minify: (options: InternalOptions<T>) => InternalResult }} MinimizerWorker
60 */
61/**
62 * @typedef {undefined | boolean | number} Parallel
63 */
64/**
65 * @typedef {Object} BasePluginOptions
66 * @property {Rules} [test]
67 * @property {Rules} [include]
68 * @property {Rules} [exclude]
69 * @property {Parallel} [parallel]
70 */
71/**
72 * @template T
73 * @typedef {BasePluginOptions & { minimizer: T extends any[] ? { [P in keyof T]: Minimizer<T[P]> } : Minimizer<T> }} InternalPluginOptions
74 */
75/**
76 * @template T
77 * @typedef {T extends HtmlMinifierTerserOptions
78 * ? { minify?: MinimizerImplementation<T> | undefined, minimizerOptions?: MinimizerOptions<T> | undefined }
79 * : T extends any[]
80 * ? { minify: { [P in keyof T]: MinimizerImplementation<T[P]>; }, minimizerOptions?: { [P in keyof T]?: MinimizerOptions<T[P]> | undefined; } | undefined }
81 * : { minify: MinimizerImplementation<T>, minimizerOptions?: MinimizerOptions<T> | undefined }} DefinedDefaultMinimizerAndOptions
82 */
83/**
84 * @template [T=HtmlMinifierTerserOptions]
85 */
86declare class HtmlMinimizerPlugin<T = import("html-minifier-terser").Options> {
87 /**
88 * @private
89 * @param {any} warning
90 * @param {string} file
91 * @returns {Error}
92 */
93 private static buildWarning;
94 /**
95 * @private
96 * @param {any} error
97 * @param {string} file
98 * @returns {Error}
99 */
100 private static buildError;
101 /**
102 * @private
103 * @param {Parallel} parallel
104 * @returns {number}
105 */
106 private static getAvailableNumberOfCores;
107 /**
108 * @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>} [options]
109 */
110 constructor(
111 options?:
112 | (BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>)
113 | undefined
114 );
115 /**
116 * @private
117 * @type {InternalPluginOptions<T>}
118 */
119 private options;
120 /**
121 * @private
122 * @param {Compiler} compiler
123 * @param {Compilation} compilation
124 * @param {Record<string, import("webpack").sources.Source>} assets
125 * @param {{availableNumberOfCores: number}} optimizeOptions
126 * @returns {Promise<void>}
127 */
128 private optimize;
129 /**
130 * @param {Compiler} compiler
131 * @returns {void}
132 */
133 apply(compiler: Compiler): void;
134}
135declare namespace HtmlMinimizerPlugin {
136 export {
137 htmlMinifierTerser,
138 Schema,
139 Compiler,
140 Compilation,
141 WebpackError,
142 Asset,
143 JestWorker,
144 HtmlMinifierTerserOptions,
145 Rule,
146 Rules,
147 MinimizedResult,
148 Input,
149 CustomOptions,
150 InferDefaultType,
151 MinimizerOptions,
152 MinimizerImplementation,
153 Minimizer,
154 InternalOptions,
155 InternalResult,
156 MinimizerWorker,
157 Parallel,
158 BasePluginOptions,
159 InternalPluginOptions,
160 DefinedDefaultMinimizerAndOptions,
161 };
162}
163type Compiler = import("webpack").Compiler;
164type BasePluginOptions = {
165 test?: Rules | undefined;
166 include?: Rules | undefined;
167 exclude?: Rules | undefined;
168 parallel?: Parallel;
169};
170type DefinedDefaultMinimizerAndOptions<T> =
171 T extends import("html-minifier-terser").Options
172 ? {
173 minify?: MinimizerImplementation<T> | undefined;
174 minimizerOptions?: MinimizerOptions<T> | undefined;
175 }
176 : T extends any[]
177 ? {
178 minify: { [P in keyof T]: MinimizerImplementation<T[P]> };
179 minimizerOptions?:
180 | { [P_1 in keyof T]?: MinimizerOptions<T[P_1]> }
181 | undefined;
182 }
183 : {
184 minify: MinimizerImplementation<T>;
185 minimizerOptions?: MinimizerOptions<T> | undefined;
186 };
187import { htmlMinifierTerser } from "./utils";
188type Schema = import("schema-utils/declarations/validate").Schema;
189type Compilation = import("webpack").Compilation;
190type WebpackError = import("webpack").WebpackError;
191type Asset = import("webpack").Asset;
192type JestWorker = import("jest-worker").Worker;
193type HtmlMinifierTerserOptions = import("./utils.js").HtmlMinifierTerserOptions;
194type Rule = RegExp | string;
195type Rules = Rule[] | Rule;
196type MinimizedResult = {
197 code: string;
198 errors?: unknown[] | undefined;
199 warnings?: unknown[] | undefined;
200};
201type Input = {
202 [file: string]: string;
203};
204type CustomOptions = {
205 [key: string]: any;
206};
207type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
208type MinimizerOptions<T> = InferDefaultType<T> | undefined;
209type MinimizerImplementation<T> = (
210 input: Input,
211 minimizerOptions?: MinimizerOptions<T>
212) => Promise<MinimizedResult>;
213type Minimizer<T> = {
214 implementation: MinimizerImplementation<T>;
215 options?: MinimizerOptions<T> | undefined;
216};
217type InternalOptions<T> = {
218 name: string;
219 input: string;
220 minimizer: T extends any[]
221 ? { [P in keyof T]: Minimizer<T[P]> }
222 : Minimizer<T>;
223};
224type InternalResult = {
225 code: string;
226 warnings: Array<any>;
227 errors: Array<any>;
228};
229type MinimizerWorker<T> = Worker & {
230 transform: (options: string) => InternalResult;
231 minify: (options: InternalOptions<T>) => InternalResult;
232};
233type Parallel = undefined | boolean | number;
234type InternalPluginOptions<T> = BasePluginOptions & {
235 minimizer: T extends any[]
236 ? { [P in keyof T]: Minimizer<T[P]> }
237 : Minimizer<T>;
238};
239import { minify } from "./minify";
240import { Worker } from "jest-worker";