0.5.1 • Published 10 months ago

esconf v0.5.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

esconf

配置文件加载工具

API 设计参考自 antfu/unconfig

esconf 在使用时更像 unocss 需要 core + presets 形式组合

esconf/preset-mini 最小预设内置解析器一览

  • .mts .ts .cts .mjs .js .cjs 基于 jiti@2 导入
  • .json .jsonc .json5 .yaml .yml .toml 基于 confbox 导入
  • .${name}rc ${homedir}/.${name}rc 基于 rc9 导入

注意: 预设 js,ts 解析只包含 es module 的解析

npm version npm downloads bundle size license

安装

# ✨ Auto-detect
npx nypm install esconf

# npm
npm install esconf

# yarn
yarn add esconf

# pnpm
pnpm install esconf

# bun
bun install esconf

# deno
deno install esconf

简单使用

import { loadConfig,presetMini } from 'esconf'
import { tsParser } from 'esconf/preset-mini'

const config = await loadConfig({
    presets:[
      presetMini({
        // 配置如下会解析 vite.config.{cts,ts,mts} vite.{toml,....}
        name:'vite',
        configName:'config',
        // 设置 ts 文件解析规则
        ts:{
          loader:'tsx'
        },
        // 关闭js 文件解析
        js: false,
        // ....
      })
      ],
    // 数组越靠前配置文件的优先级越高
    // layers 的优先级比 presets 高
    layers: [
      {
        // load from vrx.config.{mts,ts}
        files: ['vrx.config'],
        extensions: ['mts', 'ts'],
        parser: tsParser(),
      },
    ],
    // 配置默认值
    default: { defaultValue: 'value' },
    cwd: process.cwd(),
    // 如果某个 layer 命名了,可以用 layer 的名称在运行时排除
    excludeLayer: ['preset-mini:toml'],
    // 如果 excludeLayer 的 类型时 funcition ,则可以根据 layer 配置的特征自行决定运行时是否排除
    excludeLayer: (layer) => layer.extensions.includes('yaml')
  })

鸣谢

贡献者

Published under the MIT license. Made by @Colourlessglow and community 💛


🤖 auto updated with automd

0.5.1

10 months ago

0.5.0

10 months ago

0.4.0

11 months ago

0.3.2

12 months ago

0.3.1

12 months ago

0.3.3

12 months ago

0.2.0

12 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago