1. Introduction
-
Rspack is a high-performance build tool developed by the Byte
ByteDance Web Infra
team based on the RustWeb
language . -
Rust is an efficient, reliable, general-purpose high-level language. Its high efficiency is not limited to development efficiency, execution efficiency is also commendable, and it is one of the few languages that takes both development efficiency and execution efficiency into account.
-
Rspack
Currently supportsReact
,Vue
,Svelte
,Solid
,NestJS
,Angular
preliminary support, and many capabilities are missing, others includeStorybook
,Modern.js
,Modern.js Doc
and so on.
2. Features
-
advantage
-
Startup speed: Based on
Rust
the implementation, the build speed is extremely fast. -
HMR
(Hot update): The built-in incremental compilation mechanismHMR
is extremely fast and fully capable of developing large-scale projects. -
Compatible
webpack
ecology:webpack
Compatible with the architecture and ecology of , no need to build the ecology from scratch. -
Built-in common build capabilities: provide out-of-the-box support for
TypeScript
,JSX
,CSS
,CSS Modules
, etc.Sass
-
Default production optimization: By default, various optimization strategies are built in, such as
Tree Shaking
, ,代码压缩
and so on. -
Build
Performance: Achieved5~10
a 100% improvement in compilation performance. -
…
-
-
shortcoming
-
Loader
The support is limited.Plugin
At present, it mainly depends on the built-in. The use of advanced points is more troublesome or the support is limited. The configuration after the built-in is relatively simple. -
It is more suitable for huge projects, so that the running speed and
Build
speed can be maintained at 1 timeswebpack
that of5-10
, and the improvement for small and medium projects is limited. -
Only
nodejs 14
the above project migrations are supported. -
…
-
3. Performance comparison
-
Tool comparison
-
Benefits after Byte Internal Project Migration
4. Architecture design
-
Mainly around
4
the aspect, with a structure diagram-
The core architecture was born out of
Wabpack5
Because
Wabpack
it has been tested for many years, its overall structure stability is very high. -
Native
Language- based high-concurrency frameworkRust
It is a language itselfNative
. Compared withJS
this dynamic language, it can be highly optimized and has a higher performance bottleneck. AlthoughJS
the languageV8
is already good in some optimizations, its shortcoming comes from the support for multi-threading, and the benefits brought by implementing multi-threading are much lowerRust
. -
Based on
Rust
theBabel
substituteSWC
Webpack
Most of the ecology is based onLoader
andPlugin
extensions. The main point isLoader
that traditional tools are usedBabel Loader
to do it, butBabel Loader
it is relatively slow, soRust
it is usedSWC
instead.SWC
Compared withBabel
the performance improvement brought by , it has made a relatively high contribution, so the use ofRspack
can be avoided during development.Babel Loader
-
Efficient communication based
NAPI-RS
onRust
andJS
核心用
Rust
写的,但是插件扩展是JS
写的,一方面有些开发者还得学习Rust
才能做插件开发,上手成本比较高,另一方面是JS
本身有个动态化特性,能直接在用户侧去编写并被加载执行,由于Rust
是一门Native
语言,做动态化是远不如JS
的,即使使用Rust
开发了一个插件,编译后的产物也是一个Native Code
,Native Code
跟操作系统
、CPU
等是强相关的,比如在Windows
上编译出来的插件在Mac
上是跑不起来的,如果想做这种Native
插件的动态分发或加载是比较困难的,需要熟悉整套跨平台编程的知识,每一个插件可能需要编译出来很多个平台的产物,然后再分发到不同平台上去,这个门槛比较高且稳定性也不容易控制。
-
5. Migration Principles
-
One principle is to give priority to the use of built-in capabilities, which can ensure optimal performance. For example, do not use
Babel Loader
related capabilities. Commonly used capabilities areBabel
basically built-in. If you must use them, you need to control the impact to a small range. If you use them on a large scale, the possibleRspack
performance degradation will be more obvious. -
css
Related,webpack
it is generally usedstyle-loader、css-loader
for processing, but it is implementedRspack
using and is enabled by default, so it is recommended to use the built-in capabilities instead of using these .SWC
experiments.css
css
Loader
-
The resource module recommends to use
Asset Modules
for processing,webpack5
and also usesAsset Modules
to replace the previousfile-loader、url-loader、raw-loader
etc. -
html
The generation is also a built-inRust
version of the plug-in, but the function may be slightly weaker. Ifhtml
you have relatively high customization requirements at the level, you can use it@rspack/plugin-html
. This is aJS
version, the performance will beRust
slower than the version, but the extension is higher.
QA
-
Vite
Which isRspack
better?This depends on the scenario.
Vite
The development experience and ecology of small and medium-sized scenarios are better. For example, with someSSR
support,Rspack
it is currently more suitable for heavy-duty applications (such as internal companies庞大的B端应用
), and can compile faster5-10
by 3 times. -
Is migration recommended at this stage
Rspack
?This depends on whether some advanced functions or plug-ins are used. It may not be supported at this stage. You need to check the support status. In other words, if there is no
webpack
deep customization or manipulation of , it should not be a big problem and you can try it.