Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/rspack_fs/src/native_fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
};
#[derive(Debug)]
struct NativeFileSystemOptions {
// enable yarn pnp feature
// enable Yarn PnP feature
pnp: bool,
}
#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/config/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ const getResolveDefaults = ({

const resolveOptions: ResolveOptions = {
// enable pnp only in pnp environment, see https://yarnpkg.com/advanced/pnpapi#processversionspnp
// IGNORE(resolve.pnp): Rspack use `resolve.enable` to enable yarn pnp feature
// IGNORE(resolve.pnp): Rspack use `resolve.enable` to enable Yarn PnP feature
pnp: !!process.versions.pnp,
modules: ["node_modules"],
conditionNames: conditions,
Expand Down
2 changes: 1 addition & 1 deletion packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ export type ResolveOptions = {

/** Customize the Resolve configuration based on the module type. */
byDependency?: Record<string, ResolveOptions>;
/** enable yarn pnp */
/** enable Yarn PnP */
pnp?: boolean;
};

Expand Down
167 changes: 167 additions & 0 deletions website/docs/en/blog/announcing-1-2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
date: 2025-1-21 16:00:00
sidebar: false
---

# Announcing Rspack 1.2

> January 21, 2025

![Rspack 1.2](https://assets.rspack.dev/rspack/rspack-banner-v1-2.png)

> Posted by [@jerrykingxyz](https://github.com/jerrykingxyz), [@chenjiahan](https://github.com/chenjiahan), [@JSerFeng](https://github.com/JSerFeng), [@ahabhgk](https://github.com/ahabhgk)

---

Rspack v1.2 has been released!

Notable changes:

- New features
- [Persistent cache](#persistent-cache): An experimental feature that improves hot start performance by up to **250%**.
- [Yarn pnp](#yarn-pnp)
- Performance improvements
- [Faster code splitting](#faster-code-splitting): An experimental flag that significantly improve the code splitting performance.
- [Watch scope change](#watch-scope-change)
- [Reduced memory usage](#reduced-memory-usage)
- [Smaller minification size](#smaller-minification-size)
- [Faster side effects optimization](#faster-side-effects-optimization)

## New features

### Persistent cache

Rspack v1.2 introduced an experimental cache configuration that supports persistent caching, which can significantly improve hot startup speed.

```js title=rspack.config.js
module.exports = {
cache: true,
experiments: {
cache: {
type: 'persistent',
},
},
};
```

When a build hits the cache, it can bring up to 250% performance improvement in real projects.

| Project type | Number of modules | Normal dev | Cold dev | Hot dev |
| -------------------------- | ----------------- | ---------- | ------------ | ------------- |
| Initial project | 26 | 146 ms | 149 ms (+2%) | 134 ms (-8%) |
| Project with 10000 modules | 10040 | 2.43 s | 2.43 s (+0%) | 1.16 s (-52%) |
| Project with Less files | 1898 | 3.47 s | 3.55 s (+2%) | 0.92 s (-73%) |
| Large real project | 45968 | 93.3 s | 91.9 s (-1%) | 26 s (-72%) |

Note that persistent cache is still in an experimental stage and currently only supports the make stage of the build process (including module resolution, transformation, etc.). We will continue to optimize it in the future to further improve cache performance and coverage.

If you encounter any issues while using persistent cache, please feel free to report them via GitHub Issues.

> See [experiments.cache](/config/experiments#experimentscache) for more details.

### Yarn PnP

Rspack has added support for [Yarn PnP](https://yarnpkg.com/features/pnp), which is enabled by default based on `process.versions.pnp` (that is, when the application is running in a Yarn pnp environment), and can also be forced to enable by configuring `resolve.pnp` to `true`.

```js title="rspack.config.js"
module.exports = {
resolve: {
pnp: true,
},
};
```

Special thanks to [@arcanis](https://x.com/arcanis), the lead maintainer for Yarn, for implementing PnP resolution in the Rspack resolver.

> See [resolve.pnp](/config/resolve#resolvepnp) for more details.

## Performance improvements

### Faster code splitting

In previous versions of Rspack, the code splitting would take up a lot of time under HMR. In Rspack v1.2, we implemented a new code splitting algorithm that supports multithreading and more efficient incremental rebuilds. If your code base contains a lot of dynamic imports, and code splitting will take a lot of time. Enabling this new feature can significantly improve the performance of code splitting.

```js title="rspack.config.js"
module.exports = {
experiments: {
parallelCodeSplitting: true,
},
};
```

> See [experiments.parallelCodeSplitting](/config/experiments#experimentsparallelcodesplitting) for more details.

### Watch scope change

Rspack v1.2 no longer watching the `node_modules` directory by default. This can greatly reduce the number of files to watch and improve performance.

According to our [benchmark repo](https://github.com/rspack-contrib/build-tools-performance), this change will:

- Reduce memory usage by 120MB
- Increase dev startup speed by 40%
- Increase HMR speed by 20~30%

This change will not affect symlinked resources in monorepo, as symlinked resources are resolved to their real path by default.

If you prefer to keep the previous behavior, you can set:

```js title="rspack.config.js"
module.exports = {
watchOptions: {
ignored: [],
},
};
```

> See [watchOptions.ignored](/config/watch#watchoptionsignored) for more details.

### Reduced memory usage

We have optimized the data structure used to store strings during the [rspack-sources](https://github.com/web-infra-dev/rspack-sources) computation process. Throughout the computation, all string data points to the string heap memory of the root node, effectively avoiding the generation of new string allocations during the computation.

> See [perf: reduce memory consumption of CachedSource](https://github.com/web-infra-dev/rspack/pull/8666) for more details.

### Smaller minification size

Rspack v1.2 set default SWC minimizer `passes` to `2` to reduce bundle size by 1%-7%.

```js
new rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
compress: {
// Defaults to 1 in previous versions
passes: 2,
},
},
});
```

[passes](https://swc.rs/docs/configuration/minification#jscminifycompress) is the the maximum number of times to run compress. In some cases, more than one pass leads to further compressed code. Given Rspack's inherent speed, we've determined that using `2` passes by default strikes an optimal balance between build performance and bundle size.

> See [feat: set default SWC minimizer passes to 2 to reduce bundle size](https://github.com/web-infra-dev/rspack/pull/8853) for more details.

### Faster side effects optimization

The implementation of side effects optimization has been refactored to be simpler and more parallelism-friendly. It can take full advantage of parallelism to improve performance. In tested projects, there is typically a 2x-3x performance improvement at this stage.

> See [perf: parallelize side effects optimization](https://github.com/web-infra-dev/rspack/pull/8781) for more details.

## Upgrade guide

### Upgrade SWC plugins

In Rspack v1.2, the Rust crate `swc_core` has been upgraded to `10.1.0`. Users of the SWC Wasm plugin need to ensure version consistency with `swc_core` being used, otherwise, it may lead to unforeseen issues.

For more details, see [SWC documentation](https://swc.rs/docs/plugin/selecting-swc-core).

### Disable WarnCaseSensitiveModulesPlugin by default

The [WarnCaseSensitiveModulesPlugin](/plugins/webpack/warn-case-sensitive-modules-plugin) is used to check the paths of modules and issue warnings for modules that conflict when their paths are all in lowercase. Rspack used to enable it by default, but since it is only a "linter" plugin and it has additional performance overhead especially in development mode. So now it is disabled by default.

If you prefer to keep the previous behavior, you can set:

```js title="rspack.config.js"
module.exports = {
plugins: [new rspack.WarnCaseSensitiveModulesPlugin()],
};
```
6 changes: 6 additions & 0 deletions website/docs/en/blog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ sidebar: false

Check here for the latest articles and release announcements about Rspack.

## [Announcing Rspack 1.2](/blog/announcing-1-2)

> January 21, 2025

Rspack 1.2 has been released, introducing experimental persistent caching, a faster code splitting algorithm, and Yarn PnP support.

## [Build systems and bundlers](https://github.com/orgs/web-infra-dev/discussions/24)

> January 7, 2025
Expand Down
167 changes: 167 additions & 0 deletions website/docs/zh/blog/announcing-1-2.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
---
date: 2025-1-21 16:00:00
sidebar: false
---

# Rspack 1.2 发布公告

> 2025 年 1 月 21 日

![Rspack 1.2](https://assets.rspack.dev/rspack/rspack-banner-v1-2.png)

> 由 [@jerrykingxyz](https://github.com/jerrykingxyz),[@chenjiahan](https://github.com/chenjiahan),[@JSerFeng](https://github.com/JSerFeng), [@ahabhgk](https://github.com/ahabhgk) 发布

---

Rspack v1.2 已经正式发布!

值得关注的变更如下:

- 新功能
- [支持持久化缓存](#支持持久化缓存):实验性功能,让热启动性能提升高达 **250%**
- [支持 Yarn PnP](#支持-yarn-pnp)
- 性能优化
- [更快的 code splitting](#更快的-code-splitting):实验性开关,显著提升 code splitting 性能
- [Watch 范围变化](#watch-范围变化)
- [减少内存使用](#减少内存使用)
- [更小的压缩体积](#更小的压缩体积)
- [更快的副作用优化](#更快的副作用优化)

## 新功能

### 支持持久化缓存

在 Rspack v1.2 中,我们实验性的支持了持久化缓存,其会将构建中的缓存信息写入到存储介质中,加速下次 Rspack 的启动速度。

```js title=rspack.config.js
module.exports = {
cache: true,
experiments: {
cache: {
type: 'persistent',
},
},
};
```

当构建命中缓存时,它可以在真实项目中带来高达 250% 的性能提升。

| 项目类型 | 模块数量 | Normal dev | Cold dev | Hot dev |
| ------------------------ | -------- | ---------- | ------------ | ------------- |
| 初始项目 | 26 | 146 ms | 149 ms (+2%) | 134 ms (-8%) |
| 包含 10000 个模块的项目 | 10040 | 2.43 s | 2.43 s (+0%) | 1.16 s (-52%) |
| 包含 Less 文件的中型项目 | 1898 | 3.47 s | 3.55 s (+2%) | 0.92 s (-73%) |
| 大型真实项目 | 45968 | 93.3 s | 91.9 s (-1%) | 26 s (-72%) |

需要注意的是,持久化缓存目前仍处于实验阶段,当前仅支持构建过程中的 make 阶段(包括模块解析、转换等流程)。未来我们将持续优化,进一步提升缓存的性能和覆盖范围。

如果你在使用持久化缓存时遇到任何问题,欢迎通过 GitHub Issues 反馈。

> 详情请参考 [experiments.cache](/config/experiments#experimentscache)。

### 支持 Yarn PnP

Rspack 迎来了对 [Yarn PnP](https://yarnpkg.com/features/pnp) 的支持,其默认根据 `process.versions.pnp`(即应用在 Yarn PnP 环境中运行时)来进行开启,也可以将 `resolve.pnp` 配置为 `true` 来强制开启。

```js title="rspack.config.js"
module.exports = {
resolve: {
pnp: true,
},
};
```

在此特别感谢 [@arcanis](https://x.com/arcanis)(Yarn 的维护者),为 Rspack 的 resolver 实现了 PnP 解析。

> 详情请参考 [resolve.pnp](/config/resolve#resolvepnp)。

## 性能优化

### 更快的 code splitting

在之前的 Rspack 版本中,code splitting 算法在 HMR 下会占用大量的耗时,在 Rspack v1.2 中,我们实现了全新的 code splitting 算法,它支持多线程,增量构建效率更高。如果你的代码库包含大量动态导入,code splitting 可能会花费大量时间,开启这项新功能可以显著提高 code splitting 的性能。

```js title="rspack.config.js"
module.exports = {
experiments: {
parallelCodeSplitting: true,
},
};
```

> 详情请参考 [experiments.parallelCodeSplitting](/config/experiments#experimentsparallelcodesplitting)。

### Watch 范围变化

Rspack v1.2 将不再监听 `node_modules` 和 `.git` 目录下的文件变动,这将显著减少监听的文件数目并带来性能提升。

通过 [benchmark 仓库](https://github.com/rspack-contrib/build-tools-performance) 中的数据,这项调整将:

- 减少内存占用 120MB
- 提升 Dev 启动速度 40%
- 提升 HMR 速度 20~30%

这个变更不会影响 monorepo 中的符号链接资源,因为 Rspack 默认将符号链接资源解析为它的真实路径。

如果你倾向于保持之前的行为,可以设置 :

```js title="rspack.config.js"
module.exports = {
watchOptions: {
ignored: [],
},
};
```

> 详情请参考 [watchOptions.ignored](/config/watch#watchoptionsignored)。

### 减少内存使用

我们优化了在 [rspack-sources](https://github.com/web-infra-dev/rspack-sources) 计算过程中用于存储字符串的数据结构。在整个计算过程中,所有字符串数据都指向根节点的字符串堆内存,有效避免了计算过程中产生新的字符串分配。

> 详见:[perf: reduce memory consumption of CachedSource](https://github.com/web-infra-dev/rspack/pull/8666)。

### 更小的压缩体积

Rspack v1.2 将 SWC 压缩器的默认 `passes` 设置为 `2`,以减少 1%-7% 的打包体积。

```js
new rspack.SwcJsMinimizerRspackPlugin({
minimizerOptions: {
compress: {
// 在之前的版本中默认为 1
passes: 2,
},
},
});
```

[passes](https://swc.rs/docs/configuration/minification#jscminifycompress) 是运行压缩的最大次数。在某些情况下,多次压缩可以产生更小的代码。考虑到 Rspack 本身的性能优势,我们将默认值设为 `2` 以在构建性能和打包体积之间取得最佳平衡。

> 详见:[feat: set default SWC minimizer passes to 2 to reduce bundle size](https://github.com/web-infra-dev/rspack/pull/8853)。

### 更快的副作用优化

我们对副作用优化的实现进行了重构,采用了更简洁且更易并行化的方案。通过充分利用多线程并行处理能力,在测试项目中,这个阶段的性能获得了 2-3 倍的提升。

> 详见:[perf: parallelize side effects optimization](https://github.com/web-infra-dev/rspack/pull/8781)。

## 升级指南

### 升级 SWC 插件

在 Rspack v1.2 中,Rust 包中 `swc_core` 已升级到 `10.1.0`。SWC Wasm 插件的用户需要确保与正在使用的 `swc_core` 版本一致,否则可能会导致意外问题。

> 详情请参考 [SWC 文档](https://swc.rs/docs/plugin/selecting-swc-core)。

### WarnCaseSensitiveModules 默认关闭

[WarnCaseSensitiveModulesPlugin](/plugins/webpack/warn-case-sensitive-modules-plugin) 插件用于检查模块的路径,并对路径全部为小写的冲突模块发出警告。Rspack 过去默认启用它,但由于它只是一个 linter 插件,并且它在开发模式下会产生额外的性能开销。所以现在 Rspack 默认禁用了这项功能。

如果你倾向于保持之前的行为,可以设置:

```js title="rspack.config.js"
module.exports = {
plugins: [new rspack.WarnCaseSensitiveModulesPlugin()],
};
```
6 changes: 6 additions & 0 deletions website/docs/zh/blog/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ sidebar: false

在此查看有关 Rspack 的最新文章和发布公告。

## [Rspack 1.2 发布公告](/blog/announcing-1-2)

> 2025 年 1 月 21 日

Rspack 1.2 版本发布,引入实验性的持久化缓存、更快的代码分割算法以及 Yarn PnP 支持等功能。

## [构建系统与前端打包工具](https://github.com/orgs/web-infra-dev/discussions/22)

> 2025 年 1 月 7 日
Expand Down
1 change: 1 addition & 0 deletions website/project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ proxying
px2rem
pxtorem
recognise
resolvepnp
Rollup
rome
rsbuild
Expand Down
Loading