Introduction
bunfig
is a smart configuration loader designed specifically for Bun projects. It provides a simple, type-safe way to manage configuration files in your Bun applications with zero dependencies.
Key Features
- Smart Configuration Loading: Automatically finds and loads configuration files from multiple possible locations and formats
- Type Safety: Full TypeScript support with automatic type generation for your config files
- Zero Dependencies: Built to be lightweight and fast, perfect for Bun projects
- Flexible Format Support: Supports
.ts
,.js
,.mjs
,.cjs
, and.json
configuration files - Deep Merging: Intelligently merges default configurations with file-based configs
- Multiple Search Patterns: Supports various config file naming conventions
- Type Generation: Automatically generates TypeScript types for your config files
Why bunfig?
When building Bun applications, you often need a way to manage configuration that is:
- Type-safe
- Easy to use
- Flexible enough to support different environments
- Fast and lightweight
bunfig solves these problems by providing a zero-dependency configuration loader that works seamlessly with Bun and TypeScript. Think of it as unconfig
, but optimized specifically for Bun projects.
Key Benefits
- Simple API: Load your configuration with a single function call
- Type Safety: Get full TypeScript support and automatic type generation
- Zero Dependencies: Keep your project lean and fast
- Flexible: Support multiple config file formats and locations
- Bun-Optimized: Built specifically for the Bun runtime
Quick Example
import { config } from 'bunfig'
interface AppConfig {
port: number
database: {
url: string
pool: number
}
}
const cfg = await config<AppConfig>({
name: 'my-app',
defaultConfig: {
port: 3000,
database: {
url: 'localhost',
pool: 5,
},
},
})
Testing
bun test
Changelog
Please see our releases page for more information on what has changed recently.
Contributing
Please review the Contributing Guide for details.
Stargazers
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Postcardware
Two things are true: Stacks OSS will always stay open-source, and we do love to receive postcards from wherever Stacks is used! 🌍 We also publish them on our website. And thank you, Spatie
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094
Sponsors
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙