UNPKG

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