-
Notifications
You must be signed in to change notification settings - Fork 692
Expand file tree
/
Copy pathModuleMinifierPlugin.types.ts
More file actions
227 lines (202 loc) · 5.49 KB
/
Copy pathModuleMinifierPlugin.types.ts
File metadata and controls
227 lines (202 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import type { AsyncSeriesWaterfallHook, SyncWaterfallHook } from 'tapable';
import type { Chunk, Compilation, Module, sources } from 'webpack';
import type { Comment } from 'estree';
import type { IModuleMinifier } from '@rushstack/module-minifier';
/**
* Information about where the module was rendered in the emitted asset.
* @public
*/
export interface IRenderedModulePosition {
/**
* The offset from the start of tha asset to the start of the module, in characters.
*/
charOffset: number;
/**
* The length of the rendered module, in characters.
*/
charLength: number;
}
/**
* Information about a dehydrated webpack ECMAScript asset
* @public
*/
export interface IAssetInfo {
/**
* The (minified) boilerplate code for the asset. Will contain a token to be replaced by the minified modules.
*/
source: sources.Source;
/**
* The name of the asset, used to index into compilation.assets
*/
fileName: string;
/**
* The raw chunk object from Webpack, in case information from it is necessary for reconstruction
*/
chunk: Chunk;
/**
* Information about the offsets and character lengths for each rendered module in the final asset.
*/
renderInfo: Map<string | number, IRenderedModulePosition>;
/**
* The type of the asset
* @example 'javascript'
* @example 'css'
*/
type: string;
}
/**
* Information about a minified module
* @public
*/
export interface IModuleInfo {
/**
* The (minified) code of this module. Will be a function expression.
*/
source: sources.Source;
/**
* The raw module object from Webpack, in case information from it is necessary for reconstruction
*/
module: Module;
/**
* The id of the module, from the chunk graph.
*/
id: string | number;
/**
* Whether this module was in method shorthand format
*/
isShorthand?: boolean;
}
/**
* This is the second parameter to the NormalModuleFactory `module` hook
* @internal
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface _INormalModuleFactoryModuleData {
resourceResolveData?: {
/**
* Contents of the description file (package.json) for the module
*/
descriptionFileData?: {
/**
* The name of the package
*/
name: string;
};
/**
* Absolute path of the description file (package.json) for the module
*/
descriptionFilePath?: string;
/**
* Absolute path of the directory containing the description file (package.json) for the module
*/
descriptionFileRoot?: string;
/**
* Relative path from the description file (package.json) to the module
*/
relativePath?: string;
};
}
/**
* Properties surfaced via the `factoryMeta` property on webpack modules
* @public
*/
export interface IFactoryMeta {
comments?: Comment[];
skipMinification?: boolean;
}
/**
* Statistics from the plugin. Namely module sizes.
* @public
*/
export interface IModuleMinifierPluginStats {
metadataByModule: WeakMap<Module, IModuleStats>;
metadataByAssetFileName: Map<string, IAssetStats>;
}
/**
* Module size data as a function of the target chunk.
* @public
*/
export interface IModuleStats {
hashByChunk: Map<Chunk, string>;
sizeByHash: Map<string, number>;
}
/**
* Rendered positional data
* @public
*/
export interface IAssetStats {
positionByModuleId: Map<string | number, IRenderedModulePosition>;
}
/**
* A map from file names to dehydrated assets
* @public
*/
export type IAssetMap = Map<string, IAssetInfo>;
/**
* A map from module ids to minified modules
* @public
*/
export type IModuleMap = Map<string | number, IModuleInfo>;
/**
* Options to the ModuleMinifierPlugin constructor
* @public
*/
export interface IModuleMinifierPluginOptions {
/**
* Minifier implementation to use. Required.
*/
minifier: IModuleMinifier;
/**
* Whether to enable source map processing. If not provided, will attempt to guess based on `mode` and `devtool` in the webpack config.
* Set to `false` for faster builds at the expense of debuggability.
*/
sourceMap?: boolean;
}
/**
* The set of data remaining to rehydrate in the current compilation
* @public
*/
export interface IDehydratedAssets {
/**
* The set of remaining assets to rehydrate. Each tap may remove some or all assets from this collection
*/
assets: IAssetMap;
/**
* The set of modules to use for rehydrating assets.
*/
modules: IModuleMap;
}
/**
* Argument to the postProcessCodeFragment hook for the current execution context
* @public
*/
export interface IPostProcessFragmentContext {
/**
* The current webpack compilation, for error reporting
*/
compilation: Compilation;
/**
* A name to use for logging
*/
loggingName: string;
/**
* The current module being processed, or `undefined` if not in a module (e.g. the bootstrapper)
*/
module: Module | undefined;
}
/**
* Hooks provided by the ModuleMinifierPlugin
* @public
*/
export interface IModuleMinifierPluginHooks {
/**
* Hook invoked at the start of optimizeChunkAssets to rehydrate the minified boilerplate and runtime into chunk assets.
*/
rehydrateAssets: AsyncSeriesWaterfallHook<[IDehydratedAssets, Compilation]>;
/**
* Hook invoked on code after it has been returned from the minifier.
*/
postProcessCodeFragment: SyncWaterfallHook<[sources.ReplaceSource, IPostProcessFragmentContext]>;
}