UNPKG

6.01 kBTypeScriptView Raw
1export = TerserPlugin;
2/**
3 * @template [T=TerserOptions]
4 */
5declare class TerserPlugin<T = import("terser").MinifyOptions> {
6 /**
7 * @private
8 * @param {any} input
9 * @returns {boolean}
10 */
11 private static isSourceMap;
12 /**
13 * @private
14 * @param {unknown} warning
15 * @param {string} file
16 * @returns {Error}
17 */
18 private static buildWarning;
19 /**
20 * @private
21 * @param {any} error
22 * @param {string} file
23 * @param {TraceMap} [sourceMap]
24 * @param {Compilation["requestShortener"]} [requestShortener]
25 * @returns {Error}
26 */
27 private static buildError;
28 /**
29 * @private
30 * @param {Parallel} parallel
31 * @returns {number}
32 */
33 private static getAvailableNumberOfCores;
34 /**
35 * @private
36 * @param {any} environment
37 * @returns {TerserECMA}
38 */
39 private static getEcmaVersion;
40 /**
41 * @param {BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>} [options]
42 */
43 constructor(
44 options?:
45 | (BasePluginOptions & DefinedDefaultMinimizerAndOptions<T>)
46 | undefined
47 );
48 /**
49 * @private
50 * @type {InternalPluginOptions<T>}
51 */
52 private options;
53 /**
54 * @private
55 * @param {Compiler} compiler
56 * @param {Compilation} compilation
57 * @param {Record<string, import("webpack").sources.Source>} assets
58 * @param {{availableNumberOfCores: number}} optimizeOptions
59 * @returns {Promise<void>}
60 */
61 private optimize;
62 /**
63 * @param {Compiler} compiler
64 * @returns {void}
65 */
66 apply(compiler: Compiler): void;
67}
68declare namespace TerserPlugin {
69 export {
70 terserMinify,
71 uglifyJsMinify,
72 swcMinify,
73 esbuildMinify,
74 Schema,
75 Compiler,
76 Compilation,
77 WebpackError,
78 Asset,
79 TerserECMA,
80 TerserOptions,
81 JestWorker,
82 SourceMapInput,
83 TraceMap,
84 Rule,
85 Rules,
86 ExtractCommentsFunction,
87 ExtractCommentsCondition,
88 ExtractCommentsFilename,
89 ExtractCommentsBanner,
90 ExtractCommentsObject,
91 ExtractCommentsOptions,
92 MinimizedResult,
93 Input,
94 CustomOptions,
95 InferDefaultType,
96 PredefinedOptions,
97 MinimizerOptions,
98 BasicMinimizerImplementation,
99 MinimizeFunctionHelpers,
100 MinimizerImplementation,
101 InternalOptions,
102 MinimizerWorker,
103 Parallel,
104 BasePluginOptions,
105 DefinedDefaultMinimizerAndOptions,
106 InternalPluginOptions,
107 };
108}
109type Compiler = import("webpack").Compiler;
110type BasePluginOptions = {
111 test?: Rules | undefined;
112 include?: Rules | undefined;
113 exclude?: Rules | undefined;
114 extractComments?: ExtractCommentsOptions | undefined;
115 parallel?: Parallel;
116};
117type DefinedDefaultMinimizerAndOptions<T> = T extends TerserOptions
118 ? {
119 minify?: MinimizerImplementation<T> | undefined;
120 terserOptions?: MinimizerOptions<T> | undefined;
121 }
122 : {
123 minify: MinimizerImplementation<T>;
124 terserOptions?: MinimizerOptions<T> | undefined;
125 };
126import { terserMinify } from "./utils";
127import { uglifyJsMinify } from "./utils";
128import { swcMinify } from "./utils";
129import { esbuildMinify } from "./utils";
130type Schema = import("schema-utils/declarations/validate").Schema;
131type Compilation = import("webpack").Compilation;
132type WebpackError = import("webpack").WebpackError;
133type Asset = import("webpack").Asset;
134type TerserECMA = import("./utils.js").TerserECMA;
135type TerserOptions = import("./utils.js").TerserOptions;
136type JestWorker = import("jest-worker").Worker;
137type SourceMapInput = import("@jridgewell/trace-mapping").SourceMapInput;
138type TraceMap = import("@jridgewell/trace-mapping").TraceMap;
139type Rule = RegExp | string;
140type Rules = Rule[] | Rule;
141type ExtractCommentsFunction = (
142 astNode: any,
143 comment: {
144 value: string;
145 type: "comment1" | "comment2" | "comment3" | "comment4";
146 pos: number;
147 line: number;
148 col: number;
149 }
150) => boolean;
151type ExtractCommentsCondition =
152 | boolean
153 | "all"
154 | "some"
155 | RegExp
156 | ExtractCommentsFunction;
157type ExtractCommentsFilename = string | ((fileData: any) => string);
158type ExtractCommentsBanner =
159 | string
160 | boolean
161 | ((commentsFile: string) => string);
162type ExtractCommentsObject = {
163 condition?: ExtractCommentsCondition | undefined;
164 filename?: ExtractCommentsFilename | undefined;
165 banner?: ExtractCommentsBanner | undefined;
166};
167type ExtractCommentsOptions = ExtractCommentsCondition | ExtractCommentsObject;
168type MinimizedResult = {
169 code: string;
170 map?: import("@jridgewell/trace-mapping").SourceMapInput | undefined;
171 errors?: (string | Error)[] | undefined;
172 warnings?: (string | Error)[] | undefined;
173 extractedComments?: string[] | undefined;
174};
175type Input = {
176 [file: string]: string;
177};
178type CustomOptions = {
179 [key: string]: any;
180};
181type InferDefaultType<T> = T extends infer U ? U : CustomOptions;
182type PredefinedOptions = {
183 module?: boolean | undefined;
184 ecma?: import("terser").ECMA | undefined;
185};
186type MinimizerOptions<T> = PredefinedOptions & InferDefaultType<T>;
187type BasicMinimizerImplementation<T> = (
188 input: Input,
189 sourceMap: SourceMapInput | undefined,
190 minifyOptions: MinimizerOptions<T>,
191 extractComments: ExtractCommentsOptions | undefined
192) => Promise<MinimizedResult>;
193type MinimizeFunctionHelpers = {
194 getMinimizerVersion?: (() => string | undefined) | undefined;
195};
196type MinimizerImplementation<T> = BasicMinimizerImplementation<T> &
197 MinimizeFunctionHelpers;
198type InternalOptions<T> = {
199 name: string;
200 input: string;
201 inputSourceMap: SourceMapInput | undefined;
202 extractComments: ExtractCommentsOptions | undefined;
203 minimizer: {
204 implementation: MinimizerImplementation<T>;
205 options: MinimizerOptions<T>;
206 };
207};
208type MinimizerWorker<T> = import("jest-worker").Worker & {
209 transform: (options: string) => MinimizedResult;
210 minify: (options: InternalOptions<T>) => MinimizedResult;
211};
212type Parallel = undefined | boolean | number;
213type InternalPluginOptions<T> = BasePluginOptions & {
214 minimizer: {
215 implementation: MinimizerImplementation<T>;
216 options: MinimizerOptions<T>;
217 };
218};
219import { minify } from "./minify";