Unplugin Build Time Statistics

0.3.0 · active · verified Tue Apr 21

unplugin-time-stat is a utility that provides unified build time stat reporting across various JavaScript bundlers, including Vite, Webpack, Rspack, Rollup, and esbuild, by leveraging the `unplugin` ecosystem. It addresses the common challenge of inconsistent build performance reporting mechanisms across different build tools, offering a single interface to monitor and report build durations. The current stable version is `0.3.0`. The project has seen regular, feature-driven releases, indicating active development. A key differentiator is its ability to integrate custom hooks, allowing developers to programmatically capture build metrics and integrate them with external services or custom reporting tools, beyond just console output. This makes it a versatile tool for performance monitoring in diverse build environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to integrate unplugin-time-stat into a Vite project with a custom hook to process build time metrics.

import { defineConfig } from 'vite'
import TimeStat from 'unplugin-time-stat/vite'

function metrics(buildTime, raw) {
  // raw contains { start: Date, end: Date, buildTime: string }
  const duration = raw.end.getTime() - raw.start.getTime();
  console.log(`[Custom Metrics] Build finished in ${duration}ms`);
  // Example: send data to an external monitoring service
  // sendToDatadog('build_time', duration);
  
  // Optionally return a string to be displayed in the console
  return `Custom Report: ${duration}ms`;
}

export default defineConfig({
  plugins: [
    TimeStat({
      hook: metrics,
      // Optional: disable default console output if you only want custom handling
      // outputConsole: false 
    })
  ]
})

view raw JSON →