website/docs/en/api/plugin-api/stats-hooks.mdx
A HookMap that is called when generating the specified stats item.
HookMap<SyncBailHook<[Object, any, StatsFactoryContext], undefined>>object: result stats item object to which properties should be addeddata: original data of the stats itemStatsFactoryContext: generating context// Only common context fields are listed here. Different stats item types may provide additional fields.
type StatsFactoryContext = {
type: string;
compilation: Compilation;
makePathsRelative?: (value: string) => string;
[key: string]: any;
};
For the following example, the customProperty attribute is added in the finally generated stats.compilation through MyPlugin:
compilation.hooks.statsFactory.tap('MyPlugin', (statsFactory, options) => {
statsFactory.hooks.extract
.for('compilation')
.tap('MyPlugin', (object, compilation) => {
object.customProperty = MyPlugin.getCustomValue(compilation);
});
});
A HookMap that is called after generating the specified stats item.
HookMap<SyncWaterfallHook<[any, StatsFactoryContext]>>any: generated stats item resultStatsFactoryContext: generating contextA HookMap that is called when generating the printed string of the specified stats item.
HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>object: stats item objectStatsPrinterContext: printing context// Only common context fields are listed here. Different stats item types may provide additional fields.
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;
[key: string]: any;
};
A HookMap that is called after generating the printed string of the specified stats item.
HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>string: printed string of the stats itemStatsPrinterContext: printing context