UNPKG

9.4 kBTypeScriptView Raw
1// Type definitions for webpack-bundle-analyzer 4.4
2// Project: https://github.com/webpack-contrib/webpack-bundle-analyzer
3// Definitions by: Michael Strobel <https://github.com/kryops>
4// Vladimir Grenaderov <https://github.com/VladimirGrenaderov>
5// Max Boguslavskiy <https://github.com/maxbogus>
6// Piotr Błażejewicz <https://github.com/peterblazejewicz>
7// Kyle Hensel <https://github.com/k-yle>
8// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9// TypeScript Version: 3.7
10
11/// <reference types="node" />
12
13import { WebpackPluginInstance, Compiler } from 'webpack';
14
15export namespace BundleAnalyzerPlugin {
16 // Copied from @types/webpack@4 as webpack@5 only has `any` defined at the moment.
17 // See https://github.com/webpack/webpack/issues/11630
18 namespace Stats {
19 type Preset
20 = boolean
21 | 'errors-only'
22 | 'errors-warnings'
23 | 'minimal'
24 | 'none'
25 | 'normal'
26 | 'verbose';
27
28 interface ToJsonOptionsObject {
29 /** fallback value for stats options when an option is not defined (has precedence over local webpack defaults) */
30 all?: boolean | undefined;
31 /** Add asset Information */
32 assets?: boolean | undefined;
33 /** Sort assets by a field */
34 assetsSort?: string | undefined;
35 /** Add built at time information */
36 builtAt?: boolean | undefined;
37 /** Add information about cached (not built) modules */
38 cached?: boolean | undefined;
39 /** Show cached assets (setting this to `false` only shows emitted files) */
40 cachedAssets?: boolean | undefined;
41 /** Add children information */
42 children?: boolean | undefined;
43 /** Add information about the `namedChunkGroups` */
44 chunkGroups?: boolean | undefined;
45 /** Add built modules information to chunk information */
46 chunkModules?: boolean | undefined;
47 /** Add the origins of chunks and chunk merging info */
48 chunkOrigins?: boolean | undefined;
49 /** Add chunk information (setting this to `false` allows for a less verbose output) */
50 chunks?: boolean | undefined;
51 /** Sort the chunks by a field */
52 chunksSort?: string | undefined;
53 /** Context directory for request shortening */
54 context?: string | undefined;
55 /** Display the distance from the entry point for each module */
56 depth?: boolean | undefined;
57 /** Display the entry points with the corresponding bundles */
58 entrypoints?: boolean | undefined;
59 /** Add --env information */
60 env?: boolean | undefined;
61 /** Add errors */
62 errors?: boolean | undefined;
63 /** Add details to errors (like resolving log) */
64 errorDetails?: boolean | undefined;
65 /** Exclude assets from being displayed in stats */
66 excludeAssets?: StatsExcludeFilter | undefined;
67 /** Exclude modules from being displayed in stats */
68 excludeModules?: StatsExcludeFilter | undefined;
69 /** See excludeModules */
70 exclude?: StatsExcludeFilter | undefined;
71 /** Add the hash of the compilation */
72 hash?: boolean | undefined;
73 /** Set the maximum number of modules to be shown */
74 maxModules?: number | undefined;
75 /** Add built modules information */
76 modules?: boolean | undefined;
77 /** Sort the modules by a field */
78 modulesSort?: string | undefined;
79 /** Show dependencies and origin of warnings/errors */
80 moduleTrace?: boolean | undefined;
81 /** Add public path information */
82 publicPath?: boolean | undefined;
83 /** Add information about the reasons why modules are included */
84 reasons?: boolean | undefined;
85 /** Add the source code of modules */
86 source?: boolean | undefined;
87 /** Add timing information */
88 timings?: boolean | undefined;
89 /** Add webpack version information */
90 version?: boolean | undefined;
91 /** Add warnings */
92 warnings?: boolean | undefined;
93 /** Show which exports of a module are used */
94 usedExports?: boolean | undefined;
95 /** Filter warnings to be shown */
96 warningsFilter?: string | RegExp | Array<string | RegExp> | ((warning: string) => boolean) | undefined;
97 /** Show performance hint when file size exceeds `performance.maxAssetSize` */
98 performance?: boolean | undefined;
99 /** Show the exports of the modules */
100 providedExports?: boolean | undefined;
101 }
102
103 type ToJsonOptions = Preset | ToJsonOptionsObject;
104
105 type StatsExcludeFilter = string | string[] | RegExp | RegExp[] | ((assetName: string) => boolean) | Array<(assetName: string) => boolean>;
106 }
107
108 type ExcludeAssetsPatternFn = (assetName: string) => boolean;
109 type ExcludeAssetsPattern = string | RegExp | ExcludeAssetsPatternFn;
110
111 interface Options {
112 /**
113 * Can be "server", "static" or "disabled".
114 * Defaults to "server".
115 * In "server" mode analyzer will start HTTP server to show bundle report.
116 * In "static" mode single HTML file with bundle report will be generated.
117 * In "json" mode single JSON file with bundle report will be generated
118 * In "disabled" mode you can use this plugin to just generate Webpack Stats JSON file by setting "generateStatsFile" to true.
119 */
120 analyzerMode?: 'server' | 'static' | 'json' | 'disabled' | undefined;
121
122 /**
123 * Host that will be used in `server` mode to start HTTP server.
124 * @default '127.0.0.1'
125 */
126 analyzerHost?: string | undefined;
127
128 /**
129 * Port that will be used in `server` mode to start HTTP server.
130 * @default 8888
131 */
132 analyzerPort?: number | 'auto' | undefined;
133
134 /**
135 * Path to bundle report file that will be generated in "static" mode.
136 * Relative to bundles output directory.
137 * @default 'report.html'
138 */
139 reportFilename?: string | undefined;
140
141 /**
142 * Content of the HTML title element; or a function of the form () => string that provides the content.
143 * @default function that returns pretty printed current date and time.
144 */
145 reportTitle?: string | (() => string) | undefined;
146
147 /**
148 * Module sizes to show in report by default.
149 * Should be one of "stat", "parsed" or "gzip".
150 * @default 'parsed'
151 */
152 defaultSizes?: 'parsed' | 'stat' | 'gzip' | undefined;
153
154 /**
155 * Automatically open report in default browser.
156 * @default true
157 */
158 openAnalyzer?: boolean | undefined;
159
160 /**
161 * If true, Webpack Stats JSON file will be generated in bundles output directory.
162 * @default false
163 */
164 generateStatsFile?: boolean | undefined;
165
166 /**
167 * Name of Webpack Stats JSON file that will be generated if generateStatsFile is true.
168 * Relative to bundles output directory.
169 * @default 'stats.json'
170 */
171 statsFilename?: string | undefined;
172
173 /**
174 * Options for stats.toJson() method.
175 * For example you can exclude sources of your modules from stats file with "source: false" option.
176 * @default null
177 */
178 statsOptions?: null | Stats.ToJsonOptionsObject | undefined;
179
180 /**
181 * Patterns that will be used to match against asset names to exclude them from the report.
182 * If pattern is a string it will be converted to RegExp via `new RegExp(str)`.
183 * If pattern is a function it should have the following signature `(assetName: string) => boolean`
184 * and should return true to exclude matching asset.
185 * If multiple patterns are provided asset should match at least one of them to be excluded.
186 * @default null
187 */
188 excludeAssets?: null | ExcludeAssetsPattern | ExcludeAssetsPattern[] | undefined;
189
190 /**
191 * Log level. Can be "info", "warn", "error" or "silent".
192 * @default 'info'
193 */
194 logLevel?: 'info' | 'warn' | 'error' | 'silent' | undefined;
195 }
196
197 interface JsonReportItem {
198 label: string;
199 /** in bytes */
200 gzipSize: number;
201 concatenated?: boolean | undefined;
202 /** in bytes */
203 statSize: number;
204 /** in bytes */
205 parsedSize: number;
206
207 groups?: JsonReportItem[] | undefined;
208 path?: string | undefined;
209 inaccurateSizes?: boolean | undefined;
210 id?: number | null | undefined;
211 isAsset?: boolean | undefined;
212 }
213
214 /** The json report that will be produced if `analyzerMode: 'json'` */
215 type JsonReport = JsonReportItem[];
216}
217
218export class BundleAnalyzerPlugin implements WebpackPluginInstance {
219 constructor(options?: BundleAnalyzerPlugin.Options);
220
221 apply(compiler: Compiler): void;
222}
223
\No newline at end of file