bunli build command compiles and bundles your CLI for production. It supports standalone executable compilation, multi-platform builds, minification, and more.
Usage
Basic Examples
Options
| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
--entry | -e | string | auto-detect | Entry file (defaults to auto-detect) |
--outdir | -o | string | ./dist | Output directory |
--outfile | - | string | - | Output filename (for single executable) |
--minify | -m | boolean | true | Minify output |
--sourcemap | -s | boolean | false | Generate sourcemaps |
--bytecode | - | boolean | false | Enable bytecode compilation (experimental) |
--runtime | -r | 'bun' | 'node' | bun | Runtime target (for non-compiled builds) |
--targets | -t | string | - | Target platforms for compilation (e.g., darwin-arm64,linux-x64) |
--watch | -w | boolean | false | Watch for changes |
Build Modes
Bunli supports two build modes:- Bundle Mode (default) - Bundles your CLI as ESM modules
- Compile Mode - Creates standalone executables using
--targets
Bundle Mode
Bundle mode creates optimized ESM bundles:Bundle Implementation
- Uses Bun’s bundler
- Outputs ESM format
- Adds shebang for executable
- Makes files executable with
chmod +x - Includes codegen plugin
Compile Mode
Compile mode creates standalone executables that don’t require a runtime:Supported Platforms
darwin-arm64- macOS Apple Silicondarwin-x64- macOS Intellinux-arm64- Linux ARM64linux-x64- Linux x64windows-x64- Windows x64native- Current platformall- All supported platforms
Compilation Implementation
- Creates true standalone executables
- No runtime required
- Platform-specific binaries
- Organizes by platform subdirectories when building multiple targets
- Adds
.exeextension for Windows
Type Generation
The build command automatically generates TypeScript types before building:Build Configuration
Configure builds inbunli.config.ts:
Output Structure
Bundle Mode Output
Compile Mode - Single Platform
Compile Mode - Multiple Platforms
Compression
When building for multiple platforms, enable compression to create.tar.gz archives:
External Packages
Mark packages as external to exclude them from the bundle:Bytecode Compilation
Enable experimental bytecode compilation:- Experimental feature
- May improve startup time
- Adds
--bytecodeflag tobun build --compile
Minification
Minification is enabled by default. Disable it:- Reduces bundle size
- Removes whitespace and shortens names
- Applies to both bundle and compile modes
Source Maps
Generate source maps for debugging:Output Size
The build command reports output size:Build Cleanup
The output directory is cleaned before each build:Advanced Usage
Multiple Entry Points
Bundle mode supports multiple entry points:Custom Output File
Watch Mode
Rebuild on file changes:Troubleshooting
Entry File Not Found
Specify the entry explicitly:Platform-Specific Issues
Cross-compilation limitations:- Can only target platforms supported by Bun
- Some native modules may not work in compiled builds
- Use
externalto exclude problematic dependencies
Build Failures
Check:- All imports resolve correctly
- No circular dependencies
- External packages are properly configured
- TypeScript compilation succeeds
See Also
- Development Mode - Develop with hot reload
- Releasing - Build and publish releases
- Configuration - Build configuration options