Oxfmt
安装
bash
pnpm add -D @uniboot/oxfmt-config oxfmtoxfmt 本体由项目安装;@uniboot/oxfmt-config 仅提供团队基线与 defineConfig 工厂。
使用
@uniboot/oxfmt-config 导出与 oxfmt 自带 defineConfig 兼容的 defineConfig,以及预合并好的 oxfmtConfig 基线:
ts
// oxfmt.config.ts(或 .mjs)—— 视当前 oxfmt 版本支持的配置形态
import { defineConfig } from '@uniboot/oxfmt-config'
export default defineConfig({
// 本地覆盖
})defineConfig(config) 会把团队基线与传入的 config 做浅合并后再交给 oxfmt 自身的 defineConfig。
团队基线(来自源码)
| 选项 | 默认值 |
|---|---|
printWidth | 80 |
proseWrap | 'never' |
semi | true |
singleQuote | true |
sortPackageJson | false |
trailingComma | 'all' |
overrides | 对 *.json / *.json5 / *.jsonc / *.code-workspace 强制 trailingComma: 'none' |
完整内容以源码 uniboot-configs/packages/lint-configs/oxfmt-config/src/index.ts 为准。
仅支持 JSON 配置时
若你使用的 oxfmt 版本仅读取 .oxfmtrc.json(或不支持从 npm 包 extends 链式继承),可在构建脚本里把 defineConfig 的产物落盘成 JSON:
js
// scripts/gen-oxfmtrc.mjs
import { writeFileSync } from 'node:fs'
import { defineConfig } from '@uniboot/oxfmt-config'
const config = defineConfig({
// 本地覆盖
})
writeFileSync('.oxfmtrc.json', JSON.stringify(config, null, 2))具体配置文件名以 Oxfmt 配置文档 为准。
类型与导出
ts
import { defineConfig, oxfmtConfig } from '@uniboot/oxfmt-config'
import type { OxfmtConfig } from '@uniboot/oxfmt-config'