我们很高兴地宣布 Oxc transform(也称为 transpile)的 alpha 版本发布。
🌐 We are excited to announce an alpha release for Oxc transform (a.k.a transpile).
此版本包含三个主要功能:
🌐 This release contains three major features:
- 将 TypeScript 转换为 ESNext。
- 将 React JSX 转换为 ESNext,并内置 React Refresh。
- 在不使用 TypeScript 编译器的情况下,TypeScript 独立声明 DTS 输出。
在这个测试阶段,我们建议尝试这些功能以加快构建速度。
🌐 In this alpha stage, we recommend to experiment with these features to speed up build times.
我们的基准测试显示:
- 转换:Oxc 比 SWC 快 3 到 5 倍,使用的内存少 20%,并且包大小更小(2 MB 对比 SWC 的 37 MB)。
- Transform:Oxc 的速度比 Babel 快 20 到 50 倍,内存使用减少 70%,体积小 19 MB,只需安装 2 个 npm 包,而 Babel 需要安装 170 个。
- React 开发 + React Refresh:Oxc 比 SWC 快 5 倍,比 Babel 快 50 倍。
- TS 独立声明
.d.ts的输出:Oxc 在典型文件上比 TSC 快 40 倍,在较大文件上快 20 倍。
使用示例
🌐 Usage Examples
oxc-transform npm 包
🌐 oxc-transform npm package
Vue.js 目前正在尝试在其构建流程中使用 oxc-transform npm 包来进行独立声明:
🌐 Vue.js is currently experimenting the oxc-transform npm package for isolated declarations in its build pipeline:
import { isolatedDeclaration } from "oxc-transform";
const dts = isolatedDeclaration(filename, ts);@lukeed 和 @maraisr 正在为他们的包 empathic 和 dldr 使用 oxc-transform,以 一步完成 .d.ts 的转换和生成。
以下示例演示了在单个转换步骤中发出 .js 和 .d.ts:
🌐 The following example demonstrates emitting .js and .d.ts in a single transformation step:
import { transform } from "oxc-transform";
const transformed = transform(filePath, sourceCode, {
typescript: {
onlyRemoveTypeImports: true,
declaration: { stripInternal: true },
},
});
await fs.writeFile("out.js", transformed.code);
await fs.writeFile("out.d.ts", transformed.declaration);unplugin-isolated-decl
vue-macros 使用 unplugin-isolated-decl 作为其 esbuild 插件的集成工具。
@sxzz 报告 他们的 .d.ts 生成时间从 76 秒减少到 16 秒。
在 Airtable 上使用 Bazel 构建
🌐 Bazel build at Airtable
@michaelm 来自 Airtable 正在将 Oxc 的独立声明 .d.ts 在其 CI 流水线中集成到他们的 Bazel 构建 中。
Rust oxc_transformer 包
🌐 Rust oxc_transformer crate
Rolldown 打包器直接使用 oxc_transformer Rust 库 directly。
🌐 The Rolldown bundler uses the oxc_transformer Rust crate directly.
基准测试结果
🌐 Benchmark Results
基准测试设置位于 oxc-project/bench-transformer,基准测试结果显示在其 GitHub Actions 中。
🌐 The benchmark setup is located at oxc-project/bench-transformer and the benchmarks are shown in its GitHub Actions.
(对于任何配置错误,欢迎指正。)
在 ubuntu-latest 上,对不同的代码行进行了测量示例:
🌐 On ubuntu-latest, an example of different lines of code are measured:
变形
🌐 Transform
| 行数 | oxc | swc | babel |
|---|---|---|---|
| ~100 | 0.14 毫秒 | 0.7 毫秒 (5倍) | 11.5 毫秒 (82倍) |
| ~1000 | 0.9 毫秒 | 5.7 毫秒 (6.3倍) | 38.7 毫秒 (43倍) |
| ~10000 | 14.9 毫秒 | 35.9 毫秒 (2.4倍) | 492 毫秒 (33倍) |
孤立声明
🌐 Isolated Declarations
| 行数 | oxc | tsc |
|---|---|---|
| ~100 | 0.1 毫秒 | 23.1 毫秒 (231倍) |
| ~1000 | 3.1 毫秒 | 26.8 毫秒 (8.6倍) |
| ~10000 | 3.5 毫秒 | 115.2 毫秒 (33倍) |
封装尺寸
🌐 Package size
Oxc 仅下载 2 个 npm 包,总共 2 MB。
🌐 Oxc downloads only 2 npm packages, a total of 2 MB.
| 软件包 | 大小 |
|---|---|
@oxc-transform/binding-darwin-arm64 | 2.0 MB |
@swc/core-darwin-arm64 | 37.5 MB |
@babel/core + @babel/preset-env + @babel/preset-react + @babel/preset-typescript | 21 MB 和 170 个软件包 |
内存使用
🌐 Memory Usage
Oxc 使用更少的内存。
🌐 Oxc uses less memory.
转换 parser.ts(10777 行)的内存使用情况 - 使用 /usr/bin/time -alh node 测量:
🌐 Memory usage transforming parser.ts (10777 lines) - measured using /usr/bin/time -alh node:
| 最大 RSS | |
|---|---|
| oxc | 51 MB |
| swc | 67 MB |
| babel | 172 MB |
下次发布
🌐 Next Release
我们的下一次发布将包括将目标降级到 ES6 和 @babel/plugin-transform-modules-commonjs。
🌐 Our next release will include target lowering to ES6 and @babel/plugin-transform-modules-commonjs.
致谢
🌐 Acknowledgements
感谢 @Dunqing 和 @overlookmotel 为此次发布所付出的所有辛勤努力。
🌐 Thank you @Dunqing and @overlookmotel for all the hard work involved in this release.
感谢 snyder.tech、schoolhouse.world、@lukeed 和 @maraisr 的慷慨 赞助。
🌐 Thank you snyder.tech, schoolhouse.world, @lukeed and @maraisr for the generous sponsorship.
