Bundlib

0.21.9 · active · verified Tue Apr 21

Bundlib is an automatic library bundler built on top of Rollup.js, designed to streamline the process of packaging JavaScript and TypeScript libraries. The current stable version is 0.21.9, with active development indicated by frequent patch releases (0.21.9, 0.21.8, 0.21.7, etc.) that introduce new features like parallel builds and improved CLI commands, alongside bug fixes. It aims to simplify Rollup configuration for common library bundling scenarios, offering both automatic configuration derived from `package.json` and advanced programmatic or file-based configuration via `defineConfig`. A key differentiator is its focus on opinionated defaults to reduce setup complexity, while still allowing fine-grained control for various build types (ESM, CJS, UMD, types). Users should note that while powerful, the project is explicitly stated to be "under development," suggesting potential for evolving APIs or unresolved edge cases. It ships with TypeScript types and requires Node.js >=18.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining a multi-format library configuration using `defineConfig` in a `bundlib.config.ts` file, and shows how to invoke the build via the CLI in `package.json`.

/* bundlib.config.ts */
import { defineConfig } from 'bundlib';

export default defineConfig({
  input: 'src/index.ts', // Your main entry point
  output: [
    { format: 'es', file: 'dist/index.mjs', sourcemap: true },
    { format: 'cjs', file: 'dist/index.cjs', sourcemap: true },
    { format: 'umd', file: 'dist/index.umd.js', name: 'MyLibrary', sourcemap: true }
  ],
  // Optional: Define external dependencies to prevent bundling them
  external: ['lodash'],
  // Optional: Configure TypeScript for type declarations
  project: 'tsconfig.json',
  // Optional: Enable minification for production builds
  min: process.env.NODE_ENV === 'production'
});

/* package.json */
// Add a script to your package.json
// "scripts": {
//   "build": "bundlib build",
//   "watch": "bundlib watch"
// }

// To run the build:
// npm install --save-dev bundlib rollup typescript
// npm run build

view raw JSON →