StatsFactory.hooks.extract 是一个 HookMap,在生成指定的 stats 项目时触发。
HookMap<SyncBailHook<[Object, any, StatsFactoryContext], undefined>>Object:该 stats 项目的结果对象,将属性添加于此对象Class:该 stats 项目对应的原始数据StatsFactoryContext:生成上下文type StatsFactoryContext = {
type: string;
makePathsRelative?: ((arg0: string) => string) | undefined;
compilation?: Compilation | undefined;
cachedGetErrors?: ((arg0: Compilation) => JsStatsError[]) | undefined;
cachedGetWarnings?: ((arg0: Compilation) => JsStatsWarning[]) | undefined;
};如以下例子,通过 MyPlugin 在最终生成的 stats.compilation 中添加 customProperty 属性:
compilation.hooks.statsFactory.tap('MyPlugin', (statsFactory, options) => {
statsFactory.hooks.extract
.for('compilation')
.tap('MyPlugin', (object, compilation) => {
object.customProperty = MyPlugin.getCustomValue(compilation);
});
});StatsFactory.hooks.result 是一个 HookMap,在生成指定 stats 项目后触发。
HookMap<SyncWaterfallHook<[any[], StatsFactoryContext], undefined>>any[]:该 stats 项目的生成结果StatsFactoryContext:生成上下文StatsPrinter.hooks.print 是一个 HookMap,在生成指定的 stats 项目的打印字符串时触发。
HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>Object:该 stats 项目StatsPrinterContext:打印上下文type StatsPrinterContext = {
type?: string;
compilation?: StatsCompilation;
chunkGroup?: StatsChunkGroup;
asset?: StatsAsset;
module?: StatsModule;
chunk?: StatsChunk;
moduleReason?: StatsModuleReason;
bold?: (str: string) => string;
yellow?: (str: string) => string;
red?: (str: string) => string;
green?: (str: string) => string;
magenta?: (str: string) => string;
cyan?: (str: string) => string;
formatFilename?: (file: string, oversize?: boolean) => string;
formatModuleId?: (id: string) => string;
formatChunkId?:
| ((id: string, direction?: 'parent' | 'child' | 'sibling') => string)
| undefined;
formatSize?: (size: number) => string;
formatDateTime?: (dateTime: number) => string;
formatFlag?: (flag: string) => string;
formatTime?: (time: number, boldQuantity?: boolean) => string;
chunkGroupKind?: string;
};StatsPrinter.hooks.result 是一个 HookMap,在生成指定的 stats 项目的打印字符串后触发。
HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>String:该 stats 项目打印字符串StatsPrinterContext:打印上下文