Skip to main content
bunfig.toml is Bun’s configuration file for customizing runtime behavior, package management, and build settings.

Location

Bun searches for bunfig.toml in these locations (in order):
  1. Current directory: ./bunfig.toml
  2. Parent directories (walks up)
  3. User home: ~/.bunfig.toml or $BUN_CONFIG_PATH
  4. 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
Implementation: src/bunfig.zig:109-123 - Log level parsing

Preload Scripts

Execute scripts before main entry point:
Preload
Use cases:
  • Environment setup
  • Polyfills
  • Global initialization
  • Monkey-patching
Implementation: src/bunfig.zig:125-149 - Preload parsing

Environment Variables

Configure .env file loading:
Environment configuration
Environment object
Implementation: src/bunfig.zig:151-186 - Env config parsing

Package Manager

Configure bun install behavior:

Registry

Custom npm registry:
Registry
Registry object
Implementation: 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

Configure bun --hot:
Dev server

Test Runner

Configure bun test:
Test configuration

Build Configuration

Configure bun build:
Build config

Loader Configuration

Map file extensions to loaders:
Loaders
See Loaders documentation for available loaders.

Macro Configuration

Configure build-time macros:
Macros

Define

Replace identifiers at build time:
Define
Usage in code:
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 validates bunfig.toml on startup:
Validate config

Debugging Configuration

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

  1. Check file location: Must be in project root or home directory
  2. Check file name: Must be exactly bunfig.toml
  3. Check TOML syntax: Use TOML validator
  4. Check permissions: File must be readable

Invalid Configuration

Solution: Check TOML syntax and field types.

Registry Authentication

For private registries:
Registry auth