Stats 钩子
StatsFactory
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
StatsFactory.hooks.result 是一个 HookMap,在生成指定 stats 项目后触发。
- 类型:
HookMap<SyncWaterfallHook<[any[], StatsFactoryContext], undefined>>
- 参数:
any[]:该 stats 项目的生成结果
StatsFactoryContext:生成上下文
StatsPrinter
StatsPrinter.hooks.print
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
StatsPrinter.hooks.result 是一个 HookMap,在生成指定的 stats 项目的打印字符串后触发。
- 类型:
HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>
- 参数:
String:该 stats 项目打印字符串
StatsPrinterContext:打印上下文