bunfig.toml is Bun’s configuration file for customizing runtime behavior, package management, and build settings.
Location
Bun searches forbunfig.toml in these locations (in order):
- Current directory:
./bunfig.toml - Parent directories (walks up)
- User home:
~/.bunfig.tomlor$BUN_CONFIG_PATH - System-wide:
/etc/bunfig.toml(Linux)
Project-specific
bunfig.toml overrides user/system configuration.Basic Structure
bunfig.toml
Runtime Configuration
Log Level
Control console output verbosity:Log level
src/bunfig.zig:109-123 - Log level parsing
Preload Scripts
Execute scripts before main entry point:Preload
- Environment setup
- Polyfills
- Global initialization
- Monkey-patching
src/bunfig.zig:125-149 - Preload parsing
Environment Variables
Configure.env file loading:
Environment configuration
Environment object
src/bunfig.zig:151-186 - Env config parsing
Package Manager
Configurebun install behavior:
Registry
Custom npm registry:Registry
Registry object
src/bunfig.zig:45-107 - Registry parsing
Scoped Registries
Different registries per scope:Scoped registries
Cache
Configure package cache:Cache configuration
Lockfile
Lockfile behavior:Lockfile
Production
Skip devDependencies:Production install
Optional Dependencies
Optional deps
Exact Versions
Exact versions
Frozen Lockfile
Frozen lockfile
Dry Run
Dry run
Development Server
Configurebun --hot:
Dev server
Test Runner
Configurebun test:
Test configuration
Build Configuration
Configurebun build:
Build config
Loader Configuration
Map file extensions to loaders:Loaders
Macro Configuration
Configure build-time macros:Macros
Define
Replace identifiers at build time:Define
Using defines
External Dependencies
Mark packages as external (not bundled):External
Compilation
Enable/disable features:Compilation
Example Configurations
Minimal Configuration
Minimal bunfig.toml
Development Setup
Development bunfig.toml
Production Setup
Production bunfig.toml
Monorepo Configuration
Monorepo bunfig.toml
Custom Registry
Custom registry
TOML Syntax
Bun uses standard TOML format:TOML syntax
Environment Variable Expansion
Reference environment variables:Environment variables
Configuration Validation
Bun validatesbunfig.toml on startup:
Validate config
Debugging Configuration
Print Loaded Config
Debug config
Check Config Location
Check config
Implementation
Configuration parsing implementation:- Parser:
src/bunfig.zig- TOML parsing and validation - Options:
src/options.zig- Configuration options - INI parser:
src/ini.zig- TOML/INI parsing utilities
Bunfig structure (src/bunfig.zig:7-18)
Common Patterns
Multi-Environment Setup
Use environment-specific configs:Project structure
package.json scripts
Workspace Configuration
Configure for monorepos:Workspace bunfig.toml (root)
Troubleshooting
Config Not Loading
- Check file location: Must be in project root or home directory
- Check file name: Must be exactly
bunfig.toml - Check TOML syntax: Use TOML validator
- Check permissions: File must be readable
Invalid Configuration
Registry Authentication
For private registries:Registry auth
Related
- Environment Variables - Configure env loading
- Loaders - File type configuration
- Package Manager - Install configuration