Skip to content

我们很高兴地宣布 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:

  1. 将 TypeScript 转换为 ESNext。
  2. 将 React JSX 转换为 ESNext,并内置 React Refresh。
  3. 在不使用 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:

javascript
import { isolatedDeclaration } from "oxc-transform";
const dts = isolatedDeclaration(filename, ts);

@lukeed@maraisr 正在为他们的包 empathicdldr 使用 oxc-transform,以 一步完成 .d.ts 的转换和生成。

以下示例演示了在单个转换步骤中发出 .js.d.ts

🌐 The following example demonstrates emitting .js and .d.ts in a single transformation step:

javascript
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

行数oxcswcbabel
~1000.14 毫秒0.7 毫秒 (5倍)11.5 毫秒 (82倍)
~10000.9 毫秒5.7 毫秒 (6.3倍)38.7 毫秒 (43倍)
~1000014.9 毫秒35.9 毫秒 (2.4倍)492 毫秒 (33倍)

孤立声明

🌐 Isolated Declarations

行数oxctsc
~1000.1 毫秒23.1 毫秒 (231倍)
~10003.1 毫秒26.8 毫秒 (8.6倍)
~100003.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-arm642.0 MB
@swc/core-darwin-arm6437.5 MB
@babel/core + @babel/preset-env + @babel/preset-react + @babel/preset-typescript21 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
oxc51 MB
swc67 MB
babel172 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.techschoolhouse.world@lukeed@maraisr 的慷慨 赞助

🌐 Thank you snyder.tech, schoolhouse.world, @lukeed and @maraisr for the generous sponsorship.