Smart Config Loader
- JSON, CJS, Typescript and ESM config loader with unjs/jiti
- RC config support with unjs/rc9
- Multiple sources merged with unjs/defu
-
.env
support with dotenv
Install package:
# npm
npm install c11
# yarn
yarn install c11
# pnpm
pnpm install c11
Import:
// ESM
import { loadConfig } from 'c11'
// CommonJS
const { loadConfig } = require('c11')
Load configuration:
const { config } = await loadConfig({})
c11 merged config sources with unjs/defu by below order:
- config overrides passed by options
- config file in CWD
- RC file in CWD
- global RC file in user's home directory
- default config passed by options
Resolve configuration from this working directory. Default is process.cwd()
Configuration base name. Default is config
.
Configuration file name without extension . Default is generated from name
(name=foo => foo.config
).
Set to false
to avoid loading config file.
RC Config file name. Default is generated from name
(name=foo => .foorc
).
Set to false
to disable loading RC config.
Load RC config from the user's home directory. Only enabled when rcFile
is provided. Set to false
to disable this functionality.
Loads .env
file if enabled. It is disabled by default.
Specify default configuration. It has the lowest priority.
Specify override configuration. It has the highest priority.
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
yarn install
- Run interactive tests using
yarn dev
Made with 💛 Published under MIT License.