# unbuild

> A unified JavaScript build system

Latest version **3.6.1** (published 2025-08-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install unbuild
pnpm add unbuild
yarn add unbuild
bun add unbuild
```

Provides the command `unbuild`.

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 3.6.1 |
| Published | 2025-08-15 |
| First published | 2021-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 24 |
| Unpacked size | 65.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2728 |
| Maintainers | pi0, danielroe |

## Links

- npm: https://www.npmjs.com/package/unbuild
- Repository: https://github.com/unjs/unbuild
- Homepage: https://github.com/unjs/unbuild#readme
- Issues: https://github.com/unjs/unbuild/issues
- npm.io page: https://npm.io/package/unbuild

## Dependencies (24)

- [defu](https://npm.io/package/defu.md) ^6.1.4
- [jiti](https://npm.io/package/jiti.md) ^2.5.1
- [mlly](https://npm.io/package/mlly.md) ^1.7.4
- [citty](https://npm.io/package/citty.md) ^0.1.6
- [pathe](https://npm.io/package/pathe.md) ^2.0.3
- [scule](https://npm.io/package/scule.md) ^1.3.0
- [mkdist](https://npm.io/package/mkdist.md) ^2.3.0
- [rollup](https://npm.io/package/rollup.md) ^4.46.2
- [consola](https://npm.io/package/consola.md) ^3.4.2
- [esbuild](https://npm.io/package/esbuild.md) ^0.25.9
- [untyped](https://npm.io/package/untyped.md) ^2.0.0
- [hookable](https://npm.io/package/hookable.md) ^5.5.3
- [pkg-types](https://npm.io/package/pkg-types.md) ^2.2.0
- [tinyglobby](https://npm.io/package/tinyglobby.md) ^0.2.14
- [magic-string](https://npm.io/package/magic-string.md) ^0.30.17
- [pretty-bytes](https://npm.io/package/pretty-bytes.md) ^7.0.1
- [rollup-plugin-dts](https://npm.io/package/rollup-plugin-dts.md) ^6.2.1
- [@rollup/plugin-json](https://npm.io/package/@rollup/plugin-json.md) ^6.1.0
- [@rollup/pluginutils](https://npm.io/package/@rollup/pluginutils.md) ^5.2.0
- [@rollup/plugin-alias](https://npm.io/package/@rollup/plugin-alias.md) ^5.1.1
- [@rollup/plugin-replace](https://npm.io/package/@rollup/plugin-replace.md) ^6.0.2
- [@rollup/plugin-commonjs](https://npm.io/package/@rollup/plugin-commonjs.md) ^28.0.6
- [@rollup/plugin-node-resolve](https://npm.io/package/@rollup/plugin-node-resolve.md) ^16.0.1
- [fix-dts-default-cjs-exports](https://npm.io/package/fix-dts-default-cjs-exports.md) ^1.0.1

## Recent versions

- 3.6.1 (latest) — 2025-08-15
- 3.0.0-rc.11 (rc) — 2024-10-05
- 3.6.0 — 2025-07-23
- 3.5.0 — 2025-02-26
- 3.4.2 — 2025-02-26
- 3.4.1 — 2025-02-26
- 3.4.0 — 2025-02-26
- 3.3.1 — 2025-01-13
- 3.3.0 — 2025-01-12
- 3.2.0 — 2024-12-28
- 3.1.0 — 2024-12-27
- 3.0.1 — 2024-12-13
- 3.0.0 — 2024-12-13
- 3.0.0-rc.10 — 2024-10-05
- 3.0.0-rc.9 — 2024-10-04
- … 94 more at https://npm.io/package/unbuild/versions

## README

# unbuild

<!-- automd:badges -->

[![npm version](https://img.shields.io/npm/v/unbuild)](https://npmjs.com/package/unbuild)
[![npm downloads](https://img.shields.io/npm/dm/unbuild)](https://npm.chart.dev/unbuild)

<!-- /automd -->

> A unified JavaScript build system

> [!NOTE]
> We are experimenting with [obuild](https://github.com/unjs/obuild) as the next next-gen successor based on [rolldown](https://github.com/rolldown/rolldown).
> 
> If you mainly need faster build speeds and don't mind trying beta software, give it a try!

### 📦 Optimized bundler

Robust [rollup](https://rollupjs.org) 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](https://github.com/unjs/mkdist) for generating bundleless dists with file-to-file transpilation.

### ✨ Passive watcher

Stub `dist` once using `unbuild --stub` (powered by [jiti](https://github.com/unjs/jiti)) and you can try and link your project without needing to watch and rebuild during development.

### ✍ Untype Generator

Integration with [untyped](https://github.com/unjs/untyped).

### ✔️ Secure builds

Automatically check for various build issues such as potential **missing** and **unused** [dependencies](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#dependencies) and fail CI.

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

## Usage

Create `src/index.ts`:

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

Update `package.json`:

```json
{
  "type": "module",
  "scripts": {
    "build": "unbuild",
    "prepack": "unbuild"
  },
  "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](https://github.com/unjs/template) for project setup.

Build with `unbuild`:

```sh
npx unbuild
```

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`:

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

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

See options [here](./src/types.ts).

Example:

```js
import { defineBuildConfig } from "unbuild";

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,
});
```

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

```js
import { defineBuildConfig } from "unbuild";

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,
      },
    },
  },
]);
```

## Recipes

### Decorators support

In `build.config.ts`

```ts
import { defineBuildConfig } from "unbuild";

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

### Generate sourcemaps

```ts
import { defineBuildConfig } from "unbuild";

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

## 💻 Development

- Clone this repository
- Enable [Corepack](https://github.com/nodejs/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](./LICENSE)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/unbuild?style=flat-square
[npm-version-href]: https://npmjs.com/package/unbuild
[npm-downloads-src]: https://img.shields.io/npm/dm/unbuild?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/unbuild
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/unbuild/ci.yml?style=flat-square
[github-actions-href]: https://github.com/unjs/unbuild/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/unbuild/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/unbuild

---
_Source: https://npm.io/package/unbuild · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
