Skip to content

Oxc Minifier Alpha 版


我们很高兴宣布 oxc-minify 的 Alpha 版本发布。

虽然缺少一些高级压缩技术, 但当前版本在性能和压缩大小方面已经优于 esbuild, 正如 minification-benchmarks 所示。

typescript.js 上对比广泛使用的压缩器:

产物原始大小Gzip 大小
typescript v4.9.5 (源码)10.95 MB1.88 MB
压缩器压缩后大小Gzip 压缩后大小时间
@swc/core🏆-70% 3.32 MB🏆-54% 858.29 kB5x2,179 ms
oxc-minify-69% 3.35 MB-54% 860.67 kB🏆 444 ms
terser (不压缩)-68% 3.53 MB-53% 879.30 kB14x6,433 ms
esbuild-68% 3.49 MB-51% 915.55 kB1x492 ms
terser ❌ 超时--⚠️ +10,000 ms

oxc-minify 使用示例

typescript
import { minify } from "oxc-minify";

const filename = "test.js";
const code = "const x = 'a' + 'b'; console.log(x);";
const options = {
  compress: {
    target: "esnext",
  },
  mangle: {
    toplevel: false,
  },
  codegen: {
    removeWhitespace: true,
  },
  sourcemap: true,
};
const result = minify(filename, code, options);

console.log(result.code);
console.log(result.map);

下一步发布计划

oxc-minify 正在被集成到 Rolldown 中作为其内置压缩器, 而 Rolldown 注定要 成为 Vite 的未来

因此,对我们来说至关重要的一点是:

  • 继续实现高级压缩技术,例如常量内联和死代码消除。
  • 加强和扩展我们的测试基础设施,以确保其准备好投入生产使用。

致谢

感谢 @sapphi-red 改进了压缩器, 尤其是 esbuild 所缺乏的高级符号压缩算法。