npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vite-bundle-stats-metrics

v1.0.11

Published

A Vite plugin to generate bundle stats metrics.

Downloads

9

Readme

📊 Vite Bundle Stats Metrics Plugin

A Vite plugin that provides detailed bundle size statistics for your project. It generates a report in JSON, CSV, or TXT format and can optionally display the results in the console.

🚀 Features

  • 📂 Generates bundle size report after build
  • 📝 Supports JSON, CSV, and TXT output formats
  • 📊 Logs summary or detailed stats in the console
  • ⚠️ Supports warnings for large bundle sizes
  • ✅ Works only in production mode to avoid development clutter

📦 Installation

Install via npm:

npm install vite-bundle-stats-metrics --save-dev

Or using yarn:

yarn add vite-bundle-stats-metrics --dev

🛠 Usage

In your vite.config.ts, import and add the plugin:

import { defineConfig, PluginOption } from 'vite';
import bundleStatsMetrics from 'vite-bundle-stats-metrics';

export default defineConfig({
  plugins: [
    bundleStatsMetrics({
      outputFile: 'dist/bundle-stats',
      format: 'json', // Available options: 'json' | 'txt' | 'csv'
      logToConsole: 'summary', // 'summary' | 'detailed' | false
      warnThreshold: 500 // KiB - Logs a warning if exceeded
    })  as PluginOption
  ]
});

⚙️ Options

| Option | Type | Default | Description | |---------------|-----------------------------------|--------------------------|-------------| | outputFile | string | 'bundle-stats.json' | Path for the output file. The extension changes based on format. | | format | 'json' | 'txt' | 'csv' | 'json' | Format of the output file. | | logToConsole| boolean | 'summary' | 'detailed' | false | Logs bundle stats in console as a summary or detailed report. | | warnThreshold | number | undefined | Logs a warning if the bundle size exceeds this threshold in KiB. |


🛠 Why This Plugin is Useful

📊 Insights from the Output

  1. Identify the Largest File in Your Bundle

    • Example: "largestChunk": { "name": "Largest file size", "extension": "js", "value": 198.01, "unit": "KiB" }
    • Helps optimize large JavaScript or CSS files to improve performance.
  2. Understand Asset Size Distribution

    • Example: "assets": { "value": 367.66, "name": "Assets size", "extension": "", "unit": "KiB" }
    • Gives insight into how much total space is taken by assets.
  3. Analyze File Type Breakdown

    • Example: "extensions": { "css": { "name": ".css files size", "extension": "css", "value": 169.65, "unit": "KiB" }, "js": { "name": ".js files size", "extension": "js", "value": 198.01, "unit": "KiB" } }
    • Helps pinpoint if JavaScript, CSS, or other files are bloating the bundle.
  4. Monitor Bundle Size for Performance Optimization

    • Example: "bundle": { "value": 367.66, "name": "Bundle size including assets", "extension": "", "unit": "KiB" }
    • Useful for tracking bundle size growth over time.
  5. Track Build Time for Performance Analysis

    • Example: "buildTime": { "value": 2.179, "name": "Build time", "extension": "", "unit": "seconds" }
    • Helps developers identify slow builds and improve build performance.

📝 Example Output

JSON Output (bundle-stats.json)

{
  "largestChunk": { "name": "Largest file size", "extension": "js", "value": 198.01, "unit": "KiB" },
  "assets": { "value": 367.66, "name": "Assets size", "extension": "", "unit": "KiB" },
  "extensions": {
    "css": { "name": ".css files size", "extension": "css", "value": 169.65, "unit": "KiB" },
    "js": { "name": ".js files size", "extension": "js", "value": 198.01, "unit": "KiB" }
  },
  "bundle": { "value": 367.66, "name": "Bundle size including assets", "extension": "", "unit": "KiB" },
  "buildTime": { "value": 2.179, "name": "Build time", "extension": "", "unit": "seconds" }
}

Console Output (Summary)

📊 Bundle Size: 367.66 KiB

Console Output (Detailed)

📊 Bundle Stats:
{
  largestChunk: { name: 'Largest file size', extension: 'js', value: 198.01, unit: 'KiB' },
  assets: { value: 367.66, name: 'Assets size', extension: '', unit: 'KiB' },
  extensions: {
    css: { name: '.css files size', extension: 'css', value: 169.65, unit: 'KiB' },
    js: { name: '.js files size', extension: 'js', value: 198.01, unit: 'KiB' }
  },
  bundle: { value: 367.66, name: 'Bundle size including assets', extension: '', unit: 'KiB' },
  buildTime: { value: 2.179, name: 'Build time', extension: '', unit: 'seconds' }
}

🛠 Development & Contributions

Want to contribute? Feel free to open an issue or submit a pull request! 🚀


📜 License

This project is licensed under the MIT License.


💡 Enjoying this plugin? Consider starring it on GitHub! 🌟