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

npm-auto-bundler

v0.1.1

Published

Zero-config, production-ready bundler for modern NPM packages

Downloads

7

Readme

npm-auto-bundler

🚀 Zero-config, production-ready bundler for modern NPM packages

Automatically bundle your TypeScript/JavaScript packages with ESM, CJS, and TypeScript declarations. Perfect for library authors who want to focus on code, not build configuration.

✨ Features

  • Zero Configuration - Works out of the box with sensible defaults
  • Multi-format Output - ESM, CJS, and TypeScript declarations
  • Smart Analysis - Auto-detects TypeScript, JSX, entry points, and dependencies
  • Plugin System - Extensible with custom hooks and plugins
  • Bundle Analysis - Built-in size analysis and health checks
  • Package.json Updates - Automatically updates main, module, types, and exports fields
  • Presets - Pre-configured setups for React, Vue, Node.js, and more
  • CLI Interface - Easy command-line usage
  • GitHub Actions Ready - Includes CI/CD workflows

🚀 Quick Start

Installation

npm install npm-auto-bundler

Basic Usage

# Bundle your package
npx npm-auto-bundler

# Or use the CLI
npm-auto-bundler

Programmatic Usage

import { NpmAutoBundler } from 'npm-auto-bundler';

const bundler = new NpmAutoBundler();
const result = await bundler.build({
  analyze: true,
  formats: ['esm', 'cjs'],
  minify: true
});

console.log('Bundle size:', result.stats.totalSize);

📦 What It Does

  1. Analyzes your project structure and dependencies
  2. Bundles your code to ESM and CJS formats
  3. Generates TypeScript declarations
  4. Updates package.json with correct entry points
  5. Provides bundle analysis and optimization tips

🎯 Supported Formats

  • ESM (ES Modules) - Modern JavaScript modules
  • CJS (CommonJS) - Node.js compatibility
  • TypeScript Declarations - .d.ts files for type safety

⚙️ Configuration

CLI Options

npm-auto-bundler [options]

Options:
  -e, --entry <path>        Entry point file
  -o, --out-dir <dir>       Output directory (default: dist)
  -f, --formats <formats>   Output formats: esm,cjs (default: auto-detect)
  -m, --minify              Minify output (default: true)
  -s, --sourcemap           Generate source maps (default: true)
  -a, --analyze             Show bundle analysis (default: true)
  -p, --preset <name>       Use preset: react,vue,node,universal,typescript,minimal
  -e, --external <pkg>      Mark package as external
  --no-update-package-json  Skip package.json updates
  --backup                  Create backup before updating package.json
  --dry-run                 Show what would be updated without making changes
  -h, --help                Show help

Programmatic Options

interface BuildOptions {
  entry?: string;                    // Entry point
  outDir?: string;                   // Output directory
  formats?: ('esm' | 'cjs')[];       // Output formats
  minify?: boolean;                  // Minify output
  sourcemap?: boolean;               // Generate source maps
  analyze?: boolean;                 // Show analysis
  preset?: string;                   // Use preset
  external?: string[];               // External dependencies
  updatePackageJson?: boolean;       // Update package.json
  backupPackageJson?: boolean;       // Create backup
  dryRun?: boolean;                  // Dry run mode
}

🎨 Presets

React

npm-auto-bundler --preset react
  • ESM + CJS formats
  • React and React-DOM as externals
  • JSX support enabled
  • Bundle analysis enabled

Vue

npm-auto-bundler --preset vue
  • ESM + CJS formats
  • Vue as external
  • Bundle analysis enabled

Node.js

npm-auto-bundler --preset node
  • CJS format only
  • Node.js built-ins as externals
  • No minification
  • No bundle analysis

Universal

npm-auto-bundler --preset universal
  • ESM + CJS formats
  • Optimized for both browser and Node.js
  • Bundle analysis enabled

TypeScript

npm-auto-bundler --preset typescript
  • ESM + CJS formats
  • TypeScript declarations
  • Bundle analysis enabled

Minimal

npm-auto-bundler --preset minimal
  • ESM format only
  • No minification
  • No source maps
  • No analysis

🔌 Plugin System

Built-in Plugins

  • Bundle Analyzer - Provides bundle size analysis
  • Progress Indicator - Shows bundling progress

Custom Plugins

import { PluginManager } from 'npm-auto-bundler';

const pluginManager = new PluginManager();

pluginManager.register({
  name: 'my-plugin',
  version: '1.0.0',
  hooks: {
    beforeBuild: (options) => {
      // Modify build options
      return { ...options, customOption: true };
    },
    afterBuild: (results, stats) => {
      // Post-build processing
      console.log('Build completed!');
    }
  }
});

📊 Bundle Analysis

The bundler provides detailed analysis including:

  • Total bundle size
  • Format breakdown (ESM vs CJS)
  • Dependency analysis
  • Optimization suggestions
  • Health score

Example output:

📊 Bundle Analysis Report
==================================================

Total Size: 45.2 KB

Format Breakdown:
  ESM: 22.1 KB
  CJS: 23.1 KB

Top Dependencies:
  lodash: 15.2 KB
  react: 8.1 KB

Health Score: 95/100

Recommendations:
  💡 Consider code splitting for large dependencies
  💡 Excellent tree-shaking efficiency

🔧 Advanced Usage

Custom Entry Points

const bundler = new NpmAutoBundler();
await bundler.build({
  entry: 'src/main.ts',
  outDir: 'build',
  formats: ['esm']
});

External Dependencies

await bundler.build({
  external: ['react', 'lodash'],
  formats: ['esm', 'cjs']
});

Package.json Updates

The bundler automatically updates your package.json:

{
  "main": "dist/index.js",
  "module": "dist/index.mjs",
  "types": "dist/index.d.ts",
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.js",
      "types": "./dist/index.d.ts"
    }
  },
  "files": ["dist"]
}

🧪 Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

📈 GitHub Actions

Include this workflow for automated bundling:

name: Bundle Package
on: [push, pull_request]
jobs:
  bundle:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
      - run: npm ci
      - run: npx npm-auto-bundler
      - run: npm test

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run the test suite
  6. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🆘 Support

🚀 Roadmap

  • [ ] Webpack support
  • [ ] Rollup support
  • [ ] CSS bundling
  • [ ] Asset optimization
  • [ ] Development server
  • [ ] Hot module replacement

Made with ❤️ for the JavaScript community