lilconfig

中文文档
3.1.4发布于 2026/10/17MITTypeScriptCommonJS零依赖近 30 天下载 3.2亿

A zero-dependency alternative to cosmiconfig

原始使用文档
文档目录8 节
  1. Installation
  2. Usage
  3. ESM
  4. Difference to cosmiconfig
  5. Option difference between the two.
  6. Loaders examples
  7. Yaml loader
  8. Version correlation

Lilconfig ⚙️

npm version install size Coverage Status

A zero-dependency alternative to cosmiconfig with the same API.

Installation

npm install lilconfig

Usage

import {lilconfig, lilconfigSync} from 'lilconfig';

// all keys are optional
const options = {
    stopDir: '/Users/you/some/dir',
    searchPlaces: ['package.json', 'myapp.conf.js'],
    ignoreEmptySearchPlaces: false
}

lilconfig(
    'myapp',
    options // optional
).search() // Promise<LilconfigResult>

lilconfigSync(
    'myapp',
    options // optional
).load(pathToConfig) // LilconfigResult

/**
 * LilconfigResult
 * {
 *   config: any; // your config
 *   filepath: string;
 * }
 */

ESM

ESM configs can be loaded with async API only. Specifically js files in projects with "type": "module" in package.json or mjs files.

Difference to cosmiconfig

Lilconfig does not intend to be 100% compatible with cosmiconfig but tries to mimic it where possible. The key difference is no support for YAML files out of the box(lilconfig attempts to parse files with no extension as JSON instead of YAML). You can still add the support for YAML files by providing a loader, see an example below.

Option difference between the two.

cosmiconfig optionlilconfig
cache✅
loaders✅
ignoreEmptySearchPlaces✅
packageProp✅
searchPlaces✅
stopDir✅
transform✅

Loaders examples

Yaml loader

If you need the YAML support, you can provide your own loader

import {lilconfig} from 'lilconfig';
import yaml from 'yaml';

function loadYaml(filepath, content) {
    return yaml.parse(content);
}

const options = {
    loaders: {
        '.yaml': loadYaml,
        '.yml': loadYaml,
        // loader for files with no extension
        noExt: loadYaml
    }
};

lilconfig('myapp', options)
    .search()
    .then(result => {
        result // {config, filepath}
    });

Version correlation

  • lilconfig v1 → cosmiconfig v6
  • lilconfig v2 → cosmiconfig v7
  • lilconfig v3 → cosmiconfig v8

版本与发布记录

lilconfig 共发布 18 个版本,首次发布于 2020/02/10;过去 12 个月发布了 1 个版本。

版本发布日期距今
3.1.4latest2026/10/1720 天前
3.1.32024/12/031.9 年前
3.1.22024/06/102 年前
3.1.12024/02/182 年前
3.1.02024/02/152 年前
3.0.02023/11/192 年前

关于 lilconfig 的常见问题

lilconfig 是什么?

A zero-dependency alternative to cosmiconfig

如何安装 lilconfig?

在项目目录运行 npm install lilconfig,或使用 pnpm add / yarn add / bun add。

lilconfig 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

lilconfig 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

lilconfig 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=14。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

lilconfig 可以商用吗?

lilconfig 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

lilconfig 的下载量有多少?

根据 npm 官方下载统计,lilconfig 在 2026/10/05 – 2026/11/03 这 30 天内被下载 317,089,897 次,日均约 10,569,663 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

lilconfig 还在维护吗?

最新版本 3.1.4 发布于 2026/10/17(20 天前);至今共发布 18 个版本,其中过去 12 个月发布了 1 个;首次发布于 2020/02/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。