Introduction
Bunup is the ⚡️ blazing-fast build tool for TypeScript and JavaScript libraries, designed for flawless developer experience and speed, powered by Bun.
💖
Bunup is the bundler in your bun ecosystem.
What Can It Bundle?
Bunup supports bundling for multiple environments — including Node.js, browsers, and a special Bun target. The bun target is specifically optimized for libraries intended to run on Bun.
It can bundle JavaScript and TypeScript files (including JSX and TSX), JSON files, TOML files, text files, and a variety of other assets.
Quick Start
Quickly scaffold a new modern TypeScript or React library with Bunup in just 10 seconds.
bunx bunup@latest --new
See the Scaffold with Bunup page for more details.
Or, initialize bunup in an existing project:
bunx bunup@latest --init
Getting Started
Get started with Bunup in seconds - install, configure, and build your TypeScript/JavaScript projects with minimal setup.
Basic Usage
Create a TypeScript file:
export function greet(name: string): string {
return `Hello, ${name}!`;
}
Bundle it with bunup:
bunx bunup src/index.ts
This will create a bundled output in the dist
directory with CommonJS format (the default).
Using with package.json
First, install bunup as a dev dependency:
bun add --dev bunup
Add a build script to your package.json
:
{
"name": "my-package",
"scripts": {
"build": "bunup src/index.ts --format esm,cjs --dts"
}
}
Then run:
bun run build
Configuration
Create a bunup.config.ts
file for more control:
import { defineConfig } from 'bunup';
export default defineConfig({
entry: ['src/index.ts'],
format: ['esm', 'cjs'],
dts: true,
});
You can also export an array of configurations:
export default defineConfig([
{
name: 'node',
entry: ['src/index.ts'],
format: ['cjs'],
target: 'node',
},
{
name: 'browser',
entry: ['src/index.ts'],
format: ['esm', 'iife'],
target: 'browser',
outDir: "dist/browser",
},
]);
Package.json Configuration
You can also include your bunup configuration directly in your package.json
file using the bunup
property:
{
"name": "my-package",
"version": "1.0.0",
"bunup": {
"entry": ["src/index.ts"],
"format": ["esm", "cjs"],
"dts": true
}
}
This approach can be useful when you prefer keeping all project configuration in a single file.
JSON Schema
Bunup provides a JSON schema at https://bunup.dev/schema.json for editor autocompletion and validation. You can enable autocomplete for the bunup
field in your package.json
by configuring VSCode:
{
"json.schemas": [
{
"fileMatch": ["package.json"],
"url": "https://bunup.dev/schema.json"
}
]
}
This provides autocompletion, validation, and documentation when editing the bunup configuration in your package.json file.
Custom Configuration Path
If you need to use a configuration file with a non-standard name or location, you can specify its path using the --config
CLI option:
bunup --config ./configs/custom.bunup.config.ts
This is particularly useful for projects with multiple build configurations or for separating build configs for different environments.
Watch Mode
Bunup can watch your files for changes and rebuild automatically:
bunup src/index.ts --watch
Or in package.json:
{
"name": "my-package",
"scripts": {
"build": "bunup src/index.ts",
"dev": "bunup src/index.ts --watch"
}
}
Then run:
bun run dev