define-config-ts
v0.1.3
Published
Define and load *.config.ts
Readme
define-config-ts
Only load *.config.ts.
There is no dependency other than jiti.
Usage
pnpm add define-config-ts// Your custom lib config.ts
import { defineConfig } from 'your-lib'
export default defineConfig({
// your config
})Load config in your lib:
import { loadConfig } from 'define-config-ts'
const { config, configFile } = await loadConfig({
cwd: process.cwd(),
// load `wow.config.ts`
name: 'your-lib',
})Define defineLibConfig
import { defineDefineConfig } from 'define-config-ts'
export interface LibConfig {
/**
* enable feature
*/
features: {
[key: string]: any
}
}
export const defineLibConfig = defineDefineConfig<LibConfig>()Difference with c12 / unconfig
They are all powerful configuration loading tools and support multiple formats, like ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json', '']. Or merge config.
Under certain circumstances(in valaxy), I created a benchmark.
unconfig load config need 2-3s, c12 only need 0.2s, and custom loadConfig by jiti directly is 0.0006s 0.6ms.
I only want to load *.config.ts and do not wish to support other formats and complex merging features.
So I created this package define-config-ts.
When you want more compatibility and functionality, then you can use c12 or unconfig.
If you want a minimalist library for loading *.config.ts, consider define-config-ts.
