Appearance
简介
¥Introduction
什么是打包器
¥What is a Bundler
在 JavaScript 开发中,打包器负责将小段代码(ESM 或 CommonJS 模块)编译成更大、更复杂的代码,例如库或应用。
¥In JavaScript development, a bundler is responsible for compiling small pieces of code (ESM or CommonJS modules) into something larger and more complex, such as a library or application.
对于 Web 应用,这将显著加快应用的加载和运行速度(即使使用 HTTP/2)。对于库而言,这可以避免你的使用应用再次打包源代码,还可以提高运行时执行性能。
¥For web applications, this makes your application load and run significantly faster (even with HTTP/2). For libraries, this can avoid your consuming application having to bundle the source again, and can also improve runtime execution performance.
对于那些对细节感兴趣的人,我们已经对 为什么仍然需要打包器 进行了更深入的分析。
¥For those interested in the details, we have written a deeper analysis on why bundlers are still needed.
为什么要使用 Rolldown 功能
¥Why Rolldown
Rolldown 主要设计为 Vite 中的底层打包器,目标是用一个统一的构建工具取代 esbuild 和 Rollup(目前在 Vite 中用作依赖)。以下是我们从头开始实现新打包器的原因:
¥Rolldown is primarily designed to serve as the underlying bundler in Vite, with the goal to replace esbuild and Rollup (which are currently used in Vite as dependencies) with one unified build tool. Here's why we are implementing a new bundler from the ground up:
性能:Rolldown 用 Rust 编写。它的性能与 esbuild 和 比 Rollup 快 10 到 30 倍 处于同一水平。它的 WASM 构建也是 比 esbuild 快得多(由于 Go 的 WASM 编译不够理想)。
¥Performance: Rolldown is written in Rust. It is on the same performance level with esbuild and 10~30 times faster than Rollup. Its WASM build is also significantly faster than esbuild's (due to Go's sub-optimal WASM compilation).
生态系统兼容性:Rolldown 支持与 Rollup / Vite 相同的插件 API,确保与 Vite 现有生态系统兼容。
¥Ecosystem Compatibility: Rolldown supports the same plugin API with Rollup / Vite, ensuring compatibility with Vite's existing ecosystem.
附加功能:Rolldown 提供了 Vite 所需的一些重要特性,但 esbuild 和 Rollup 不太可能实现(详情如下)。
¥Additional Features: Rolldown provides some important features needed in Vite but unlikely to be implemented by esbuild and Rollup (details below).
虽然 Rolldown 是为 Vite 设计的,但它也可以用作独立的通用打包器。在大多数情况下,它可以作为 Rollup 的替代品,在需要更好的分块控制时,也可以作为 esbuild 的替代方案。
¥Although designed for Vite, Rolldown is also fully capable of being used as a standalone, general-purpose bundler. It can serve as a drop-in replacement for Rollup in most cases, and can also be used as an esbuild alternative when better chunking control is needed.
Rolldown 的功能范围
¥Rolldown's Feature Scope
Rolldown 提供与 Rollup 高度兼容的 API(尤其是插件接口),并具有类似的 treeshaking 功能,用于优化包大小。
¥Rolldown provides largely compatible APIs (especially the plugin interface) with Rollup, and has similar treeshaking capabilities for bundle size optimization.
但是,Rolldown 的功能范围与 esbuild 更相似,它内置了这些 附加功能 功能:
¥However, Rolldown's feature scope is more similar to esbuild, offering these additional features as built-in:
平台预设
¥Platform presets
TypeScript / JSX / 语法降级转换
¥TypeScript / JSX / syntax lowering transforms
Node.js 兼容模块解析
¥Node.js compatible module resolution
ESM / CJS module interop
defineinjectCSS 打包(实验性)
¥CSS bundling (Experimental)
压缩(WIP)
¥Minification (WIP)
Rolldown 也有一些与 esbuild 中的概念相近,但在 Rollup 中不存在:
¥Rolldown also has a few concepts that have close equivalents in esbuild, but do not exist in Rollup:
模块类型(实验性)
¥Module Types (Experimental)
最后,Rolldown 提供了一些 esbuild 和 Rollup 未实现(也可能不打算实现)的功能:
¥Finally, Rolldown provides some features that esbuild and Rollup do not (and may not intend to) implement:
高级块拆分控制(实验性)
¥Advanced chunk splitting control (Experimental)
HMR 支持(开发中)
¥HMR support (WIP)
模块联合(计划中)
¥Module Federation (planned)
致谢
¥Credits
如果没有从其他打包工具(例如 esbuild、Rollup、webpack 和 Parcel)中汲取的经验教训,Rolldown 将无法存在。我们对这些重要项目的作者和维护者致以最崇高的敬意和感激。
¥Rolldown wouldn't exist without all the lessons we learned from other bundlers like esbuild, Rollup, webpack, and Parcel. We have the utmost respect and appreciation towards the authors and maintainers of these important projects.