1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import { Server } from 'http';
|
14 | import { WebpackPluginInstance, Compiler, StatsOptions, Stats as WebpackStats } from 'webpack';
|
15 |
|
16 | export namespace BundleAnalyzerPlugin {
|
17 |
|
18 |
|
19 | namespace Stats {
|
20 | type Preset = boolean | 'errors-only' | 'errors-warnings' | 'minimal' | 'none' | 'normal' | 'verbose';
|
21 |
|
22 | type ToJsonOptionsObject = StatsOptions;
|
23 |
|
24 | type ToJsonOptions = Preset | ToJsonOptionsObject;
|
25 |
|
26 | type StatsExcludeFilter =
|
27 | | string
|
28 | | string[]
|
29 | | RegExp
|
30 | | RegExp[]
|
31 | | ((assetName: string) => boolean)
|
32 | | Array<(assetName: string) => boolean>;
|
33 | }
|
34 |
|
35 | type ExcludeAssetsPatternFn = (assetName: string) => boolean;
|
36 | type ExcludeAssetsPattern = string | RegExp | ExcludeAssetsPatternFn;
|
37 |
|
38 | interface Options {
|
39 | |
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | analyzerMode?: 'server' | 'static' | 'json' | 'disabled' | undefined;
|
48 |
|
49 | |
50 |
|
51 |
|
52 |
|
53 | analyzerHost?: string | undefined;
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 | analyzerPort?: number | 'auto' | undefined;
|
60 |
|
61 | |
62 |
|
63 |
|
64 |
|
65 |
|
66 | reportFilename?: string | undefined;
|
67 |
|
68 | |
69 |
|
70 |
|
71 |
|
72 | reportTitle?: string | (() => string) | undefined;
|
73 |
|
74 | /**
|
75 | * Module sizes to show in report by default.
|
76 | * Should be one of "stat", "parsed" or "gzip".
|
77 | * @default 'parsed'
|
78 | */
|
79 | defaultSizes?: 'parsed' | 'stat' | 'gzip' | undefined;
|
80 |
|
81 | /**
|
82 | * Automatically open report in default browser.
|
83 | * @default true
|
84 | */
|
85 | openAnalyzer?: boolean | undefined;
|
86 |
|
87 | /**
|
88 | * If true, Webpack Stats JSON file will be generated in bundles output directory.
|
89 | * @default false
|
90 | */
|
91 | generateStatsFile?: boolean | undefined;
|
92 |
|
93 | /**
|
94 | * Name of Webpack Stats JSON file that will be generated if generateStatsFile is true.
|
95 | * Relative to bundles output directory.
|
96 | * @default 'stats.json'
|
97 | */
|
98 | statsFilename?: string | undefined;
|
99 |
|
100 | /**
|
101 | * Options for stats.toJson() method.
|
102 | * For example you can exclude sources of your modules from stats file with "source: false" option.
|
103 | * @default null
|
104 | */
|
105 | statsOptions?: null | Stats.ToJsonOptions | undefined;
|
106 |
|
107 | /**
|
108 | * Patterns that will be used to match against asset names to exclude them from the report.
|
109 | * If pattern is a string it will be converted to RegExp via `new RegExp(str)`.
|
110 | * If pattern is a function it should have the following signature `(assetName: string) => boolean`
|
111 | * and should return true to exclude matching asset.
|
112 | * If multiple patterns are provided asset should match at least one of them to be excluded.
|
113 | * @default null
|
114 | */
|
115 | excludeAssets?: null | ExcludeAssetsPattern | ExcludeAssetsPattern[] | undefined;
|
116 |
|
117 | /**
|
118 | * Log level. Can be "info", "warn", "error" or "silent".
|
119 | * @default 'info'
|
120 | */
|
121 | logLevel?: 'info' | 'warn' | 'error' | 'silent' | undefined;
|
122 | }
|
123 |
|
124 | interface JsonReportItem {
|
125 | label: string;
|
126 | /** in bytes */
|
127 | gzipSize: number;
|
128 | concatenated?: boolean | undefined;
|
129 | /** in bytes */
|
130 | statSize: number;
|
131 | /** in bytes */
|
132 | parsedSize: number;
|
133 |
|
134 | groups?: JsonReportItem[] | undefined;
|
135 | path?: string | undefined;
|
136 | inaccurateSizes?: boolean | undefined;
|
137 | id?: number | null | undefined;
|
138 | isAsset?: boolean | undefined;
|
139 | }
|
140 |
|
141 | /** The json report that will be produced if `analyzerMode: 'json'` */
|
142 | type JsonReport = JsonReportItem[];
|
143 | }
|
144 |
|
145 | export class BundleAnalyzerPlugin implements WebpackPluginInstance {
|
146 | opts: BundleAnalyzerPlugin.Options;
|
147 | compiler?: Compiler;
|
148 | server: null | Server;
|
149 |
|
150 | constructor(options?: BundleAnalyzerPlugin.Options);
|
151 |
|
152 | apply(compiler: Compiler): void;
|
153 | /** @async */
|
154 | startAnalyzerServer: (stats: WebpackStats) => Promise<void>;
|
155 | /** @async */
|
156 | generateJSONReport: (stats: WebpackStats) => Promise<void>;
|
157 | generateStatsFile: (stats: WebpackStats) => Promise<void>;
|
158 | /** @async */
|
159 | generateStaticReport: (stats: WebpackStats) => Promise<void>;
|
160 | getBundleDirFromCompiler: () => null | string;
|
161 | }
|
162 |
|
\ | No newline at end of file |