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

@milencode/bundlewatch-next-plugin

v1.4.0

Published

Bundle Watch plugin for Next.js with per-route analysis.

Downloads

4

Readme

@bundlewatch/next-plugin

Bundle Watch plugin for Next.js with per-route analysis.

Features

  • 🎯 Per-Route Analysis - Track each page/route separately
  • 📊 App Router Support - Works with Next.js 13+ App Router
  • 📄 Pages Router Support - Works with traditional Pages Router
  • 🔍 Route-level Budgets - Set size limits per route
  • 📈 Historical Tracking - See how routes evolve over time
  • 🚀 Edge/Server Bundles - Track both client and server bundles

Installation

pnpm add -D @bundlewatch/next-plugin

Usage

Next.js 13+ (App Router)

// next.config.js
import { withBundleWatch } from '@bundlewatch/next-plugin';

const nextConfig = {
  // your config
};

export default withBundleWatch(nextConfig, {
  enabled: true,
  printReport: true,
  saveToGit: process.env.CI === 'true',
  perRoute: true, // Enable per-route analysis
});

Next.js 12 (Pages Router)

// next.config.js
const { withBundleWatch } = require('@bundlewatch/next-plugin');

module.exports = withBundleWatch({
  // your config
}, {
  enabled: true,
  printReport: true,
  perRoute: true,
});

Configuration

interface NextBundleWatchOptions {
  /** Enable/disable the plugin */
  enabled?: boolean;
  
  /** Print report to console after build */
  printReport?: boolean;
  
  /** Save metrics to git storage */
  saveToGit?: boolean;
  
  /** Enable per-route analysis */
  perRoute?: boolean;
  
  /** Compare against target branch */
  compareAgainst?: string;
  
  /** Fail build if size increases beyond threshold */
  failOnSizeIncrease?: boolean;
  
  /** Size increase threshold (percentage) */
  sizeIncreaseThreshold?: number;
  
  /** Route-specific budgets */
  budgets?: {
    [route: string]: {
      maxSize?: number;
      maxGzipSize?: number;
    };
  };
}

Per-Route Analysis

The plugin automatically detects and analyzes each route:

📊 Bundle Watch Report - Per Route
══════════════════════════════════════════════════

/ (Home)
  Client:  125 KB (45 KB gzipped)
  Server:  89 KB
  
/about
  Client:  98 KB (38 KB gzipped)
  Server:  45 KB
  
/blog/[slug]
  Client:  156 KB (52 KB gzipped)
  Server:  67 KB

══════════════════════════════════════════════════

Route Budgets

Set size limits per route:

withBundleWatch(nextConfig, {
  budgets: {
    '/': {
      maxSize: 200 * 1024, // 200 KB
      maxGzipSize: 70 * 1024, // 70 KB
    },
    '/blog/*': {
      maxSize: 250 * 1024,
    },
  },
  failOnSizeIncrease: true,
});

Dashboard Integration

Generate interactive dashboard with per-route views:

# After build
npm run build

# Generate dashboard
npx bundlewatch export .next --output ./bundle-report

The dashboard will show:

  • Route-by-route breakdown
  • Shared chunks vs route-specific
  • Historical trends per route
  • Bundle composition

App Router vs Pages Router

App Router (Next.js 13+)

  • Analyzes route segments
  • Tracks Server Components separately
  • Shows layout vs page bundles
  • Edge function detection

Pages Router (Next.js 12)

  • Analyzes each page
  • Tracks API routes separately
  • Shows getServerSideProps impact
  • Custom _app/_document analysis

CI/CD Integration

# .github/workflows/nextjs.yml
- name: Build Next.js app
  run: npm run build
  env:
    CI: true

- name: Generate dashboard
  run: npx bundlewatch export .next

- name: Deploy dashboard
  uses: peaceiris/actions-gh-pages@v3
  with:
    github_token: ${{ secrets.GITHUB_TOKEN }}
    publish_dir: ./bundle-report

Advanced Usage

Custom Output Directory

withBundleWatch(nextConfig, {
  outputDir: '.next', // Custom Next.js output dir
});

Server Components Analysis

withBundleWatch(nextConfig, {
  analyzeServer: true, // Include server components
  analyzeEdge: true,   // Include edge functions
});

Examples

See working examples:

License

MIT