A unified JavaScript build system
unbuild is a unified JavaScript build system developed by the UnJS team that simplifies the process of building modern npm packages. It automatically generates multiple output formats (CommonJS, ES Modules, and TypeScript type definitions) from a single source, eliminating the need for complex build configurations. The tool is designed to work out-of-the-box by reading your package.json and intelligently determining how to bundle your code.
Unlike traditional build tools that require extensive configuration files, unbuild follows a convention-over-configuration approach. It automatically detects your project structure, determines entry points, and produces optimized bundles for different module systems. This makes it particularly valuable for library authors who need to support both legacy CommonJS consumers and modern ESM environments without maintaining separate build pipelines.
The package is part of the UnJS ecosystem, which focuses on creating universal JavaScript tools that work across different runtimes (Node.js, browsers, Deno, etc.). unbuild leverages modern bundling technology under the hood while abstracting away the complexity, making it an excellent choice for developers who want to focus on writing code rather than configuring build tools. With nearly 200,000 weekly downloads, it has become a popular choice in the JavaScript ecosystem for library development.
unbuild is particularly suited for TypeScript projects, as it handles type definition generation automatically. It also supports features like passive watcher mode for development, stub builds for faster iteration, and automatic external dependency detection to keep your bundles lean.
import { defineBuildConfig } from 'unbuild';
export default defineBuildConfig({
entries: [
'./src/index',
'./src/cli',
],
declaration: true,
clean: true,
rollup: {
emitCJS: true,
esbuild: {
minify: true,
},
},
externals: [
'fsevents',
],
});
// package.json configuration (alternative to build.config.ts)
// {
// "type": "module",
// "exports": {
// ".": {
// "import": "./dist/index.mjs",
// "require": "./dist/index.cjs"
// }
// },
// "main": "./dist/index.cjs",
// "module": "./dist/index.mjs",
// "types": "./dist/index.d.ts",
// "scripts": {
// "build": "unbuild",
// "dev": "unbuild --stub"
// }
// }Library Development: Building npm packages that need to support both CommonJS and ESM consumers. unbuild automatically generates both formats from a single TypeScript or JavaScript source, ensuring compatibility across different module systems without maintaining duplicate configurations.
Monorepo Package Building: Creating multiple packages within a monorepo where each package needs consistent build outputs. unbuild's minimal configuration requirements make it easy to standardize the build process across dozens of packages without copy-pasting complex build scripts.
TypeScript Library Publishing: Publishing TypeScript libraries with proper type definitions. unbuild automatically generates .d.ts files alongside your JavaScript bundles, ensuring TypeScript consumers get full type safety without manual type generation setup.
CLI Tool Development: Building command-line tools that need to be executable across different Node.js environments. unbuild can handle entry point detection and produce properly bundled executables with all dependencies included.
Framework Plugin Development: Creating plugins for frameworks like Vite, Nuxt, or other modern tools that expect specific module formats. unbuild ensures your plugin works regardless of the consumer's module system while maintaining a simple development workflow.
An extremely fast JavaScript and CSS bundler and minifier.
Next-generation ES module bundler
Bundle your TypeScript library with no config, powered by esbuild
Native-ESM powered web dev build tool
npm install unbuildpnpm add unbuildbun add unbuild