define-config-ts
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

define-config-ts

npm version npm downloads bundle JSDocs License

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.

Sponsors

License

MIT License © YunYouJun

Readme

Keywords

none

Package Sidebar

Install

npm i define-config-ts

Weekly Downloads

104

Version

0.0.3

License

MIT

Unpacked Size

7.84 kB

Total Files

5

Last publish

Collaborators

  • yunyoujun