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

@kinfe123/rebuild

v0.0.10-beta.4

Published

A unified JavaScript build system

Readme

rebuild

A unified JavaScript build system

[!IMPORTANT] This is a fork of unbuild that has been recently overwritten with enhanced features and improvements. The core functionality remains the same while adding new capabilities like automatic package.json exports generation.

[!NOTE] We are experimenting with obuild as the next next-gen successor based on rolldown.

If you mainly need faster build speeds and don't mind trying beta software, give it a try!

Installation

pnpm install @kinfe123/rebuild

📦 Optimized bundler

Robust rollup based bundler that supports TypeScript and generates CommonJS and module formats + type declarations.

🪄 Automated config

Automagically infer build config and entries from package.json.

📁 Bundleless build

Integration with mkdist for generating bundleless dists with file-to-file transpilation.

✨ Passive watcher

Stub dist once using rebuild --stub (powered by jiti) and you can try and link your project without needing to watch and rebuild during development.

✍ Untype Generator

Integration with untyped.

✔️ Secure builds

Automatically check for various build issues such as potential missing and unused dependencies and fail CI.

CLI output also includes output size and exports for quick inspection.

Usage

Create src/index.ts:

export const log = (...args) => {
  console.log(...args);
};

Update package.json:

{
  "type": "module",
  "scripts": {
    "build": "rebuild",
    "prepack": "rebuild"
  },
  "exports": {
    ".": {
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    }
  },
  "main": "./dist/index.cjs",
  "types": "./dist/index.d.ts",
  "files": ["dist"]
}

Note You can find a more complete example in unjs/template for project setup.

Build with rebuild:

npx rebuild

Configuration is automatically inferred from fields in package.json mapped to src/ directory. For more control, continue with next section.

Configuration

Create build.config.ts:

export default {
  entries: ["./src/index"],
};

You can either use rebuild key in package.json or build.config.{js,cjs,mjs,ts,mts,cts,json} to specify configuration.

See options here.

Example:

import { defineBuildConfig } from "rebuild";

export default defineBuildConfig({
  // If entries is not provided, will be automatically inferred from package.json
  entries: [
    // default
    "./src/index",
    // mkdist builder transpiles file-to-file keeping original sources structure
    {
      builder: "mkdist",
      input: "./src/package/components/",
      outDir: "./build/components",
    },
  ],

  // Change outDir, default is 'dist'
  outDir: "build",

  // Generates .d.ts declaration file
  declaration: true,

  // Generate package.json exports field automatically
  exportMaps: true,
});

Or with multiple builds you can declare an array of configs:

import { defineBuildConfig } from "rebuild";

export default defineBuildConfig([
  {
    // If entries is not provided, will be automatically inferred from package.json
    entries: [
      // default
      "./src/index",
      // mkdist builder transpiles file-to-file keeping original sources structure
      {
        builder: "mkdist",
        input: "./src/package/components/",
        outDir: "./build/components",
      },
    ],

    // Change outDir, default is 'dist'
    outDir: "build",

    /**
     * * `compatible` means "src/index.ts" will generate "dist/index.d.mts", "dist/index.d.cts" and "dist/index.d.ts".
     * * `node16` means "src/index.ts" will generate "dist/index.d.mts" and "dist/index.d.cts".
     * * `true` is equivalent to `compatible`.
     * * `false` will disable declaration generation.
     * * `undefined` will auto detect based on "package.json". If "package.json" has "types" field, it will be `"compatible"`, otherwise `false`.
     */
    declaration: "compatible",
  },
  {
    name: "minified",
    entries: ["./src/index"],
    outDir: "build/min",
    rollup: {
      esbuild: {
        minify: true,
      },
    },
  },
]);

Package.json Exports Generation

Rebuild can automatically generate the exports field in your package.json based on your build entries using the exportMaps option:

import { defineBuildConfig } from "rebuild";

export default defineBuildConfig({
  entries: [
    "./src/index",
    "./src/plugins/vite",
    "./src/plugins/webpack",
    "./src/utils/helper",
  ],
  declaration: true,
  exportMaps: true, // Generate exports for all entries
  rollup: {
    emitCJS: true,
  },
});

This will automatically generate exports like:

{
  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": {
        "types": "./dist/index.d.mts",
        "default": "./dist/index.mjs"
      },
      "require": {
        "types": "./dist/index.d.cts",
        "default": "./dist/index.cjs"
      }
    },
    "./plugins/*": {
      "types": "./dist/plugins/*.d.ts",
      "import": {
        "types": "./dist/plugins/*.d.mts",
        "default": "./dist/plugins/*.mjs"
      },
      "require": {
        "types": "./dist/plugins/*.d.cts",
        "default": "./dist/plugins/*.cjs"
      }
    },
    "./utils/*": {
      "types": "./dist/utils/*.d.ts",
      "import": {
        "types": "./dist/utils/*.d.mts",
        "default": "./dist/utils/*.mjs"
      },
      "require": {
        "types": "./dist/utils/*.d.cts",
        "default": "./dist/utils/*.cjs"
      }
    }
  }
}

Export Modes

The exportMaps option supports three modes:

  • exportMaps: true - Generate exports for ALL build entries
  • exportMaps: ["folder1", "folder2"] - Generate exports only for specified folders (selective mode)
  • exportMaps: false - Disable exports generation (default)

Selective Export Example:

export default defineBuildConfig({
  entries: ["./src/index", "./src/plugins/vite", "./src/utils/helper"],
  declaration: true,
  exportMaps: ["plugins"], // Only export plugins folder
});

This generates exports only for the ./plugins/* pattern, excluding the main entry and utils.

Features

  • Automatic TypeScript support - Includes .d.ts, .d.mts, and .d.cts declarations
  • Folder pattern exports - Generates ./folder/* patterns for subdirectories
  • Mixed module formats - Supports both ESM (import) and CJS (require) conditions
  • Selective exports - Choose which folders to export with array syntax
  • Package.json updates - Automatically writes the exports field to your package.json

Recipes

Decorators support

In build.config.ts

import { defineBuildConfig } from "rebuild";

export default defineBuildConfig({
  rollup: {
    esbuild: {
      tsconfigRaw: {
        compilerOptions: {
          experimentalDecorators: true,
        },
      },
    },
  },
});

Generate sourcemaps

import { defineBuildConfig } from "rebuild";

export default defineBuildConfig({
  sourcemap: true,
});

💻 Development

  • Clone this repository
  • Enable Corepack using corepack enable (use npm i -g corepack for Node.js < 16.10)
  • Install dependencies using pnpm install
  • Run interactive tests using pnpm dev

License

MIT