Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

lbundle

AbdUlHamedMaree115MIT1.5.5TypeScript support: included

Small zero-configuration bundler build on top of Rollup.js and SWC for NPM libraries

lbundle, bundle, bundler, compile, compiler, rollup, rollupjs, swc, rust

readme

lbundle

GitHub Actions Workflow Status NPM Version NPM Downloads NPM License JSR Version GitHub Repo stars

Small zero-configuration bundler build on top of Rollup.js and SWC for NPM libraries

🚀 Motivation

There is always this repeated pattern for creating a library while following best practices that you need to maintain across all of your libraries, but then I thought maybe creating a library for bundling libraries is a good idea.

💾 install

NPM registry

# npm
npm i -D lbundle

# yarn
yarn add -D lbundle

# pnpm
pnpm i -D lbundle

# bun
bun i -D lbundle

JSR registry

# deno
deno add -D @mrii/lbundle

# jsr
npx jsr add -D @mrii/lbundle

🔧 Usage

package.json

This bundler heavily relay on your package.json best practices.

{
  "source": "./src/index.ts", // your source code entry
  "main": "./dist/index.js", // cjs entry
  "module": "./dist/index.mjs", // esm entry

  "types": "./dist/index.d.ts", // declaration entry

  "unpkg": "./dist/index.umd.js", // umd entry
  // "unpkg": "./dist/index.amd.js", // or as amd
  // "unpkg": "./dist/index.iife.js", // or as iife

  "bin:source": "./src/cli.ts", // your source code bin entry
  "bin": "./dist/cli.js", // bin entry

  "sideEffects": false, // enable tree shaking for your library code, also useful for users bundlers

  // the bundler will check for for different extension to bundle different formats
  "exports": {
    ".": {
      "default": "./dist/index.js",
      "node": "./dist/index.js",
      "require": "./dist/index.js",
      "import": "./dist/index.mjs",
      "types": "./dist/index.d.ts"
    },
    "./index.css": "./dist/index.css",
    "./package.json": "./package.json"
  }
}

CLI

Just call lbundle binary

lbundle

And That's it, it will generate the bundle for you at the target directory.

✨ Features

  • 🤩 all in 1: supports bundling your library and binary into all known formats (esm, cjs, umd, amd and iife), and generate declarations files as well.
  • 🚀 fast: it uses rust to compile source code into target env.
  • 🍙 bun: can be used with bunx --bun lbundle to speed up the bundling even more.
  • 🌲 tree shaking: it will preserve your file structure (for cjs and esm formats) so bundlers can exclude unused code easily.
  • 🎮 typescript: it supports bundling typescript code out of the box (make sure have typescript installed).
  • 🎯 JSX: supports JSX transformation out of the box (make sure have react and react-dom installed).
  • 💅 styles: it support all kind of style files:
    • css, pcss, sss: out of the box.
    • scss, sass: just install sass.
    • less: just install less.
    • styl, stylus: just install stylus.
  • 🍇 CSS modules: all styles files support CSS modules by just appending .module. before the file extension.
  • 🗺️ path alias: supports TS path and baseUrl transformation.
  • 📤 auto externals: look for your dependencies and peerDependencies and exclude them from the bundle.
  • 🪛 json: supports importing json files in your code.
  • 📦 polyfills: supports adding polyfills to the bundle if you're using latest ES features (make sure to have core-js installed)

🛣️ Roadmap

  • <input checked="" disabled="" type="checkbox"> bundling into UMD and AMD formats.
  • <input checked="" disabled="" type="checkbox"> reading exports field and generate extra output according to it.
  • <input disabled="" type="checkbox"> vue jsx transformation.
  • <input disabled="" type="checkbox"> extending SWC and Rollup config.
  • <input disabled="" type="checkbox"> useful logs.
  • <input disabled="" type="checkbox"> schema validation and useful errors.
  • <input disabled="" type="checkbox"> bundle info.
  • <input disabled="" type="checkbox"> watch mode.
  • <input disabled="" type="checkbox"> more options.
    • <input disabled="" type="checkbox"> single entry instead of preserved modules.
    • <input disabled="" type="checkbox"> JSX transformation options.
    • ...
  • <input disabled="" type="checkbox"> tests (partially done).
  • <input checked="" disabled="" type="checkbox"> CI.
  • <input checked="" disabled="" type="checkbox"> changelog.
  • <input disabled="" type="checkbox"> contributors.

🧰 API

// esm
import { lbundle } from 'lbundle';

// cjs
const { lbundle } = require('lbundle');

// deno
import { lbundle } from '@mrii/lbundle';

await lbundle({
  /* options */
});

🔍 Options

key cli default description version
cwd ---cwd, -c "." root dir path of your lib 1.0.0

changelog

1.5.5 (2025-05-12)

Bug Fixes

  • wrong css file placement (0d336f1)

1.5.4 (2025-04-22)

Bug Fixes

1.5.3 (2025-04-22)

Bug Fixes

  • better handle for css file name (f9faa42)

1.5.2 (2025-04-22)

Bug Fixes

  • add support for scss files export field (9f374b4)

1.5.1 (2025-04-22)

Bug Fixes

1.5.0 (2025-04-22)

Features

  • support scss imports without ~ (a4de0dc)

1.4.1 (2025-04-22)

Bug Fixes

  • importing scss/sass files (e996baa)
  • replacing unmaintained postcss package (2dc1db9)

1.4.0 (2025-03-19)

Features

  • support universal styles imports (10bed37)

1.3.5 (2025-03-12)

Bug Fixes

  • postcss: supports exports field in CSS files (17dbff1)

1.3.4 (2025-03-06)

Bug Fixes

1.3.3 (2025-03-05)

Bug Fixes

1.3.2 (2025-02-10)

Bug Fixes

  • lib: default export with cjs bundle (c0aeceb)

1.3.1 (2024-05-10)

Bug Fixes

  • package.json exports field order (e4c342f)

1.3.0 (2024-05-05)

Features

1.2.0 (2024-05-05)

Bug Fixes

Features

  • support amd, umd and iife formats and read exports field (dc33e63)

1.1.2 (2024-05-03)

Bug Fixes

1.1.1 (2024-05-03)

Bug Fixes