統計資料 Hooks

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,在生成指定統計項目的列印字串時調用。

  • 類型: 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: 列印環境