Oxfmt
Oxfmt (/oʊ-ɛks-fɔːr-mæt/) 是一个针对 JavaScript 生态系统的高性能格式化工具。
🌐 Oxfmt (/oʊ-ɛks-fɔːr-mæt/) is a high-performance formatter for the JavaScript ecosystem.
支持的语言
🌐 Supported languages
JavaScript, JSX, TypeScript, TSX, JSON, JSONC, JSON5, YAML, TOML, HTML, Angular, Vue, CSS, SCSS, Less, Markdown, MDX, GraphQL, Ember, Handlebars
为规模而建
🌐 Built for scale
Oxfmt 面向大型代码库和持续集成环境,强调高吞吐量和可预测的性能。
🌐 Oxfmt targets large codebases and CI environments, with an emphasis on high throughput and predictable performance.
它建立在 Oxc 编译器栈之上,并避免了现有格式化器实现中常见的架构瓶颈。
🌐 It is built on the Oxc compiler stack and avoids architectural bottlenecks common in existing formatter implementations.
我们的基准测试显示,Oxfmt 比 Prettier 快约 30 倍,比 Biome 快 2 倍。
🌐 Our benchmarks show Oxfmt to be approximately 30x faster than Prettier and 2x faster than Biome.
自带电池
🌐 Batteries included
Oxfmt 包含了内置功能,通常需要外部 Prettier 插件:
🌐 Oxfmt includes built-in features that typically require external Prettier plugins:
- 导入排序
- Tailwind CSS 类排序
- package.json 字段排序
- 嵌入格式(CSS-in-JS、GraphQL 等)
兼容 Prettier
🌐 Prettier-compatible
Oxfmt 可以集成到现有的基于 Prettier 的工作流中。
🌐 Oxfmt integrates into existing Prettier-based workflows.
oxfmt CLI 默认的行为类似于 Prettier,允许在对脚本和工具进行最小修改的情况下采用它。
🌐 The oxfmt CLI behaves similarly to Prettier by default, allowing adoption with minimal changes to scripts and tooling.
Oxfmt 的格式与 Prettier 的 JavaScript 格式一致。从最近版本的 Prettier 迁移时,不应出现格式差异;任何差异都被视为错误。
🌐 Oxfmt matches Prettier’s JavaScript formatting. When migrating from recent versions of Prettier, formatting differences should not occur; any differences are considered bugs.
Oxfmt 目前大约通过了 Prettier 的 95% JavaScript 和 TypeScript 测试套件。剩下的情况属于小众场景,我们会与 Prettier 团队合作,随着时间推移统一格式化规范。
🌐 Oxfmt currently passes approximately 95% of Prettier's JavaScript and TypeScript test suite. The remaining cases are niche scenarios, and we work with the Prettier team to converge on formatting over time.
无需额外依赖或配置。
🌐 No additional dependencies or configuration needed.
入门
🌐 Getting started
将 oxfmt 安装为开发依赖:
🌐 Install oxfmt as a dev dependency:
pnpm add -D oxfmt向 package.json 添加脚本:
🌐 Add scripts to package.json:
{
"scripts": {
"fmt": "oxfmt",
"fmt:check": "oxfmt --check"
}
}格式化文件:
🌐 Format files:
pnpm run fmt在不写入文件的情况下检查格式:
🌐 Check formatting without writing files:
pnpm run fmt:check下一步:
🌐 Next steps:
参考文献
🌐 References
