统计钩子

StatsFactory

StatsFactory.hooks.extract

一个 HookMap,在生成指定统计项的字符串时调用。

  • 类型: HookMap<SyncBailHook<[Object, any, StatsFactoryContext], undefined>>
  • 参数
    • Object: 结果统计项对象,其属性应被添加。
    • Class: 统计项的原始数据
    • StatsFactoryContext: 生成上下文
type StatsFactoryContext = {
  type: string;
  makePathsRelative?: ((arg0: string) => string) | undefined;
  compilation?: Compilation | undefined;
  cachedGetErrors?: ((arg0: Compilation) => JsStatsError[]) | undefined;
  cachedGetWarnings?: ((arg0: Compilation) => JsStatsWarning[]) | undefined;
};

对于以下示例,customProperty 属性将通过 MyPlugin 添加到最终生成的 stats.compilation 中。

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,在生成指定统计项后调用。

  • 类型: HookMap<SyncWaterfallHook<[any[], StatsFactoryContext], undefined>>
  • 参数
    • any[]: 生成的统计项结果
    • StatsFactoryContext: 生成上下文

StatsPrinter

StatsPrinter.hooks.print

一个 HookMap,在生成指定统计项的打印字符串时调用。

为一个 HookMap, called when generating the printed string of the specified stats item.

  • 类型: HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>
  • 参数
    • Object: 统计项对象
    • 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,在生成指定统计项的打印字符串后调用。

  • 类型: HookMap<SyncBailHook<[{}, StatsPrinterContext], string>>
  • 参数
    • String: 统计项的打印字符串
    • StatsPrinterContext: 打印上下文