npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

define-config-ts

v0.2.0

Published

Define and load *.config.ts

Readme

define-config-ts

English | 简体中文

npm version npm downloads bundle JSDocs License

极简 *.config.ts 加载器 — 在现代 Node.js 上零额外依赖。

快速开始

pnpm add define-config-ts
import { loadConfig } from 'define-config-ts'

const { config, configFile } = await loadConfig({
  cwd: process.cwd(),
  name: 'your-lib', // 加载 your-lib.config.ts
})

为什么不用 c12 / unconfig

c12unconfig 功能很强,支持多种格式(tsmtsctsjsmjscjsjson 等)以及复杂的配置合并。

但有时候你只需要加载 *.config.ts。在 valaxy 中做过的简单 benchmark:

| 工具 | 加载时间 | | --- | --- | | unconfig | ~2-3 s | | c12 | ~0.2 s | | define-config-ts | ~0.6 ms |

如果你需要更广泛的格式支持或配置合并,请使用 c12unconfig。 如果你只想要一个极简、快速的 *.config.ts 加载器 — 就是它了。

特性

  • Fresh reload 友好:当 moduleCachefalse(默认值)且存在 jiti 时,重复加载可以在 dev/HMR 流程中拿到变更后的配置。
  • 原生兼容:在现代 Node.js 的原生 TypeScript 加载可用时,无需额外依赖即可工作;若未安装 jiti,会回退到原生 import()。注意:没有 jiti 时 Node 内置模块缓存生效,moduleCache: false 无法强制重新加载。
  • 类型安全:通过 defineDefineConfig<T>() 创建带类型提示的 defineConfig 辅助函数。

兼容性

| Node.js | 加载策略 | 额外依赖 | | --- | --- | --- | | >= 22.6(原生 TS 支持) | 优先使用 jiti 以支持 fresh reload;未安装时回退到原生 import() | 无(推荐:pnpm add jiti) | | 18.x / 20.x | jiti | pnpm add jiti |

提示:在现代 Node.js 上安装 jiti 可启用 moduleCache: false(默认值),使重复加载始终拿到最新配置——这在 HMR / dev-server 场景中至关重要。

旧版 Node.js 请同时安装 jiti

pnpm add define-config-ts jiti

使用

加载配置

import { loadConfig } from 'define-config-ts'

const { config, configFile } = await loadConfig({
  cwd: process.cwd(),
  name: 'your-lib', // 加载 your-lib.config.ts
})

用户侧配置文件

import { defineConfig } from 'your-lib'

export default defineConfig({
  // your config
})

创建带类型的 defineConfig

import { defineDefineConfig } from 'define-config-ts'

export interface LibConfig {
  features: { [key: string]: any }
}

export const defineConfig = defineDefineConfig<LibConfig>()

Sponsors

License

MIT License © YunYouJun