Rspack 实战:兼容 Webpack 的高性能 Rust 构建工具

Rspack in Practice: A Webpack-Compatible High-Performance Rust Bundler

| iDev Engineering | 2026-09-02T01:02:44

Rspack 以 Rust 重写 Webpack 核心,构建速度提升 5-10 倍且保持 API 兼容。本文分享我们将中型项目从 Webpack 迁移到 Rspack 的完整经验。

Rspack rewrites Webpack's core in Rust, achieving 5-10x faster builds while maintaining API compatibility. We share our complete experience migrating a mid-size project from Webpack to Rspack.

Rspack 定位与优势Rspack 是由字节跳动开源的基于 Rust 的 Web 构建工具,它的核心设计理念是与 Webpack 生态保持高度兼容的同时提供数量级的性能提升。与 Vite、Turbopack 等工具不同,Rspack 选择了与 Webpack 生态深度兼容的路线,让存量 Webpack 项目能够以最低成本完成迁移。迁移实践记录我们将一个包含 1200 个模块、使用了 15 个 Webpack Loader 和 8 个 Plugin 的中型前端项目从 Webpack 5 迁移到了 Rspack。整个迁移过程历时 3 天,主要工作包括:将 webpack.config.js 重命名为 rspack.config.js 并调整少量不兼容配置、替换 2 个不兼容的社区 Plugin、以及更新 CI 流水线中的构建命令。最终结果令人满意:开发模式冷启动时间从 38 秒降低到 4.2 秒,生产构建时间从 2 分 15 秒降低到 28 秒。兼容性细节Rspack 对 Webpack 核心 API 的兼容度超过 90%,包括 Module Federation、Tree Shaking、Code Splitting 和 HMR 等核心功能。但仍有部分边缘场景需要注意:自定义 Resolver 插件可能需要调整、部分 Stats 输出格式有差异、以及 Worker 语法的支持尚未完全对齐。性能调优技巧基于我们的实践经验,以下配置可进一步优化 Rspack 性能:启用持久化缓存可让二次构建提速 60%;合理设置 experiments.incrementalRebuild 可显著改善 HMR 体验;使用内置的 SWC Loader 替代 babel-loader 可额外获得 30% 的编译加速。


Rspack Positioning and AdvantagesRspack is a Rust-based web build tool open-sourced by ByteDance. Its core design philosophy maintains high compatibility with the Webpack ecosystem while delivering order-of-magnitude performance improvements. Unlike Vite and Turbopack, Rspack chose deep Webpack ecosystem compatibility, allowing existing Webpack projects to migrate with minimal cost.Migration ExperienceWe migrated a mid-size frontend project with 1,200 modules, 15 Webpack Loaders, and 8 Plugins from Webpack 5 to Rspack. The entire migration took three days, primarily involving renaming webpack.config.js to rspack.config.js with minor incompatibility fixes, replacing 2 incompatible community plugins, and updating CI pipeline build commands. Results were impressive: dev cold start dropped from 38 seconds to 4.2 seconds, and production build time fell from 2 minutes 15 seconds to 28 seconds.Compatibility DetailsRspack achieves over 90% compatibility with Webpack's core APIs, including Module Federation, Tree Shaking, Code Splitting, and HMR. However, some edge cases need attention: custom Resolver plugins may require adjustments, some Stats output formats differ, and Worker syntax support is not yet fully aligned.Performance Tuning TipsBased on our experience, several configurations can further optimize Rspack performance: enabling persistent caching speeds up secondary builds by 60%; properly configuring experiments.incrementalRebuild significantly improves HMR experience; using the built-in SWC Loader instead of babel-loader provides an additional 30% compilation speedup.

← Back to News