Elegant ProgressBar and Profiler for Webpack and Rspack
—
WebpackBar provides a flexible reporter system with built-in reporters and support for custom reporters. Reporters control how build progress and completion information is displayed.
All reporters implement the Reporter interface with optional lifecycle methods.
import type webpack from "webpack";
interface Reporter {
/**
* Called when (re)compile is started
*/
start?(context: WebpackBar): void;
/**
* Called when a file changed on watch mode
*/
change?(context: WebpackBar, payload: { path: string; shortPath: string; time: number }): void;
/**
* Called after each progress update
*/
update?(context: WebpackBar): void;
/**
* Called when compile finished
*/
done?(context: WebpackBar, payload: { stats: webpack.Stats }): void;
/**
* Called when build progress updated
*/
progress?(context: WebpackBar): void;
/**
* Called when all compiles finished
*/
allDone?(context: WebpackBar): void;
/**
* Called before all compiles finished
*/
beforeAllDone?(context: WebpackBar): void;
/**
* Called after all compiles finished
*/
afterAllDone?(context: WebpackBar): void;
}WebpackBar includes several built-in reporters for different use cases.
Simple log-based reporter for minimal environments and CI systems.
class SimpleReporter implements Reporter {
start(context: WebpackBar): void;
change(context: WebpackBar, payload: { path: string; shortPath: string; time: number }): void;
done(context: WebpackBar): void;
}Features:
Usage:
new WebpackBar({
reporters: ['basic']
});Advanced progress bar reporter with real-time visual updates.
class FancyReporter implements Reporter {
progress(context: WebpackBar): void;
done(context: WebpackBar): void;
allDone(): void;
}Features:
Usage:
new WebpackBar({
reporters: ['fancy']
});Performance profiling reporter for build analysis and optimization.
class ProfileReporter implements Reporter {
progress(context: WebpackBar): void;
done(context: WebpackBar): void;
allDone(context: WebpackBar): void;
}Features:
Usage:
new WebpackBar({
profile: true // Automatically adds profile reporter
});
// Or explicitly
new WebpackBar({
reporters: ['profile']
});Statistical analysis reporter for detailed build metrics.
class StatsReporter implements Reporter {
// Implementation details in src/reporters/stats.ts
}Usage:
new WebpackBar({
reporters: ['stats']
});Create custom reporters by implementing the Reporter interface.
Simple Custom Reporter:
class CustomReporter {
start(context) {
console.log(`🚀 Starting ${context.state.name} build...`);
}
progress(context) {
const { progress, message } = context.state;
if (progress % 10 === 0) { // Log every 10%
console.log(`⚡ ${context.state.name}: ${progress}% - ${message}`);
}
}
done(context) {
const { hasErrors, message, name } = context.state;
const emoji = hasErrors ? '❌' : '✅';
console.log(`${emoji} ${name}: ${message}`);
}
}
// Usage
new WebpackBar({
reporter: CustomReporter
});Advanced Custom Reporter with Options:
class AdvancedReporter {
constructor(options = {}) {
this.options = {
logLevel: 'info',
showTimestamps: false,
...options
};
}
start(context) {
if (this.options.logLevel === 'verbose') {
const timestamp = this.options.showTimestamps ? new Date().toISOString() : '';
console.log(`${timestamp} Build started: ${context.state.name}`);
}
}
done(context) {
const { stats } = context.state;
if (this.options.logLevel === 'verbose' && stats) {
console.log(`Build time: ${stats.compilation.endTime - stats.compilation.startTime}ms`);
console.log(`Modules: ${stats.compilation.modules.size}`);
}
}
}
// Usage
new WebpackBar({
reporter: [AdvancedReporter, {
logLevel: 'verbose',
showTimestamps: true
}]
});type ReporterOpts = {
reporter: Reporter | string;
options?: any
};
type ReporterInput = string | [Reporter | string, any?] | ReporterOpts;Configuration Examples:
// String-based reporter
new WebpackBar({
reporters: ['basic', 'fancy']
});
// Array format with options
new WebpackBar({
reporters: [
'basic',
['profile', { detailed: true }]
]
});
// Object format
new WebpackBar({
reporters: [
{ reporter: 'basic' },
{ reporter: CustomReporter, options: { verbose: true } }
]
});
// Mixed formats
new WebpackBar({
reporters: [
'basic',
['fancy', { throttle: 100 }],
{ reporter: CustomReporter, options: { logFile: 'build.log' } }
]
});All reporter methods receive a WebpackBar context object providing access to build state and utilities.
import type webpack from "webpack";
declare class WebpackBar {
// State properties
readonly hasRunning: boolean; // Whether any compilation is running
readonly hasErrors: boolean; // Whether any compilation has errors
readonly statesArray: State[]; // Array of all compilation states
readonly states: { [key: string]: State }; // Global states object
readonly state: State; // Current state for this plugin instance
constructor(options?: WebpackBarOptions);
apply(compiler: webpack.Compiler): void;
updateProgress(percent?: number, message?: string, details?: string[]): void;
}Install with Tessl CLI
npx tessl i tessl/npm-webpackbar