Skip to content

Commit

Permalink
feat: add asset size info to generated report
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalmaciejewski committed Apr 14, 2022
1 parent 9fc242f commit 0f57834
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
10 changes: 7 additions & 3 deletions src/BuildTimeReport.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import webpack from 'webpack';
import { BuildTimeReporterStats, Step, StepStats } from './types';
import { AssetStats, BuildTimeReporterStats, Step, StepStats } from './types';

export class BuildTimeReport {
private readonly steps = new Map<Step, { timeStart: number; timeEnd: number }>();
private timeStart = 0;
private timeEnd = 0;
private assets: string[] = [];
private assets: AssetStats[] = [];
private chunks: string[] = [];
private modules: string[] = [];
private hash?: string;
Expand Down Expand Up @@ -41,7 +41,10 @@ export class BuildTimeReport {
this.assets = [];
Object.entries(assets).forEach(([assetName, asset]) => {
if (asset.emitted) {
this.assets.push(assetName);
this.assets.push({
name: assetName,
size: asset.info.size!,
});
}
});
}
Expand Down Expand Up @@ -73,6 +76,7 @@ export class BuildTimeReport {
initialResource: this.initialResource,
rebuild: this.rebuild,
nodeEnv: process.env.NODE_ENV as string,
assets: this.assets,
};
}

Expand Down
9 changes: 7 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export interface BuildTimeReporterWebpackPluginOptions {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
report: (stats: BuildTimeReporterStats) => Promise<any>;
report: (stats: BuildTimeReporterStats) => Promise<unknown>;
}

export interface StepStats {
Expand All @@ -9,6 +8,11 @@ export interface StepStats {
duration: number;
}

export interface AssetStats {
name: string;
size: number;
}

export type Step = 'build' | 'optimize' | 'emit';

export interface BuildTimeReporterStats {
Expand All @@ -23,4 +27,5 @@ export interface BuildTimeReporterStats {
initialResource?: string;
rebuild: boolean;
nodeEnv: string;
assets: AssetStats[];
}

0 comments on commit 0f57834

Please sign in to comment.