Skip to content

Commit feab7fa

Browse files
authored
feat: enable rspack persistent cache default (#7889)
1 parent 29ae3fe commit feab7fa

File tree

7 files changed

+112
-9
lines changed

7 files changed

+112
-9
lines changed

packages/cli/builder/src/createBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function parseConfig(
2222
rsbuildPlugins: RsbuildPlugin[];
2323
}> {
2424
builderConfig.performance ??= {};
25-
builderConfig.performance.buildCache ??= false;
25+
builderConfig.performance.buildCache ??= true;
2626

2727
const { rsbuildConfig, rsbuildPlugins } = await parseCommonConfig(
2828
builderConfig,

packages/cli/builder/tests/__snapshots__/cache.test.ts.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`builder rspack with cache > should disable cache by default 1`] = `
4+
{
5+
"buildDependencies": [
6+
"package.json",
7+
"tsconfig.json",
8+
"modern.config.ts",
9+
],
10+
"storage": {
11+
"directory": "node_modules/.cache/rspack",
12+
"type": "filesystem",
13+
},
14+
"type": "persistent",
15+
"version": "web-test",
16+
}
17+
`;
18+
319
exports[`builder rspack with cache > should generator rspack config correctly with cache 1`] = `
420
{
521
"buildDependencies": [

packages/cli/builder/tests/__snapshots__/default.test.ts.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
exports[`builder rspack > should generator rspack config correctly 1`] = `
44
{
5+
"cache": true,
56
"context": "",
67
"devtool": "cheap-module-source-map",
78
"entry": {
@@ -12,6 +13,18 @@ exports[`builder rspack > should generator rspack config correctly 1`] = `
1213
},
1314
"experiments": {
1415
"asyncWebAssembly": true,
16+
"cache": {
17+
"buildDependencies": [
18+
"package.json",
19+
"tsconfig.json",
20+
],
21+
"storage": {
22+
"directory": "node_modules/.cache/rspack",
23+
"type": "filesystem",
24+
},
25+
"type": "persistent",
26+
"version": "web-development",
27+
},
1528
"inlineConst": false,
1629
"inlineEnum": false,
1730
"rspackFuture": {
@@ -1252,6 +1265,7 @@ exports[`builder rspack > should generator rspack config correctly 2`] = `
12521265

12531266
exports[`builder rspack > should generator rspack config correctly when node 1`] = `
12541267
{
1268+
"cache": true,
12551269
"context": "",
12561270
"devtool": "source-map",
12571271
"entry": {
@@ -1261,6 +1275,18 @@ exports[`builder rspack > should generator rspack config correctly when node 1`]
12611275
},
12621276
"experiments": {
12631277
"asyncWebAssembly": true,
1278+
"cache": {
1279+
"buildDependencies": [
1280+
"package.json",
1281+
"tsconfig.json",
1282+
],
1283+
"storage": {
1284+
"directory": "node_modules/.cache/rspack",
1285+
"type": "filesystem",
1286+
},
1287+
"type": "persistent",
1288+
"version": "node-production",
1289+
},
12641290
"inlineConst": true,
12651291
"inlineEnum": true,
12661292
"rspackFuture": {
@@ -2113,6 +2139,7 @@ exports[`builder rspack > should generator rspack config correctly when node 1`]
21132139

21142140
exports[`builder rspack > should generator rspack config correctly when prod 1`] = `
21152141
{
2142+
"cache": true,
21162143
"context": "",
21172144
"devtool": "hidden-source-map",
21182145
"entry": {
@@ -2123,6 +2150,18 @@ exports[`builder rspack > should generator rspack config correctly when prod 1`]
21232150
},
21242151
"experiments": {
21252152
"asyncWebAssembly": true,
2153+
"cache": {
2154+
"buildDependencies": [
2155+
"package.json",
2156+
"tsconfig.json",
2157+
],
2158+
"storage": {
2159+
"directory": "node_modules/.cache/rspack",
2160+
"type": "filesystem",
2161+
},
2162+
"type": "persistent",
2163+
"version": "web-production",
2164+
},
21262165
"inlineConst": true,
21272166
"inlineEnum": true,
21282167
"rspackFuture": {
@@ -3354,6 +3393,7 @@ exports[`builder rspack > should generator rspack config correctly when prod 1`]
33543393

33553394
exports[`builder rspack > should generator rspack config correctly when service-worker 1`] = `
33563395
{
3396+
"cache": true,
33573397
"context": "",
33583398
"devtool": "hidden-source-map",
33593399
"entry": {
@@ -3363,6 +3403,18 @@ exports[`builder rspack > should generator rspack config correctly when service-
33633403
},
33643404
"experiments": {
33653405
"asyncWebAssembly": true,
3406+
"cache": {
3407+
"buildDependencies": [
3408+
"package.json",
3409+
"tsconfig.json",
3410+
],
3411+
"storage": {
3412+
"directory": "node_modules/.cache/rspack",
3413+
"type": "filesystem",
3414+
},
3415+
"type": "persistent",
3416+
"version": "workerSSR-production",
3417+
},
33663418
"inlineConst": true,
33673419
"inlineEnum": true,
33683420
"rspackFuture": {

packages/cli/builder/tests/__snapshots__/environment.test.ts.snap

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
exports[`builder environment compat > should generator environment config correctly 1`] = `
44
[
55
{
6+
"cache": true,
67
"context": "",
78
"devtool": "cheap-module-source-map",
89
"entry": {
@@ -13,6 +14,18 @@ exports[`builder environment compat > should generator environment config correc
1314
},
1415
"experiments": {
1516
"asyncWebAssembly": true,
17+
"cache": {
18+
"buildDependencies": [
19+
"package.json",
20+
"tsconfig.json",
21+
],
22+
"storage": {
23+
"directory": "node_modules/.cache/rspack",
24+
"type": "filesystem",
25+
},
26+
"type": "persistent",
27+
"version": "web-development",
28+
},
1629
"inlineConst": false,
1730
"inlineEnum": false,
1831
"rspackFuture": {
@@ -1211,6 +1224,7 @@ exports[`builder environment compat > should generator environment config correc
12111224
},
12121225
},
12131226
{
1227+
"cache": true,
12141228
"context": "",
12151229
"devtool": "cheap-module-source-map",
12161230
"entry": {
@@ -1220,6 +1234,18 @@ exports[`builder environment compat > should generator environment config correc
12201234
},
12211235
"experiments": {
12221236
"asyncWebAssembly": true,
1237+
"cache": {
1238+
"buildDependencies": [
1239+
"package.json",
1240+
"tsconfig.json",
1241+
],
1242+
"storage": {
1243+
"directory": "node_modules/.cache/rspack",
1244+
"type": "filesystem",
1245+
},
1246+
"type": "persistent",
1247+
"version": "node-development",
1248+
},
12231249
"inlineConst": false,
12241250
"inlineEnum": false,
12251251
"rspackFuture": {
@@ -2033,6 +2059,7 @@ exports[`builder environment compat > should generator environment config correc
20332059
},
20342060
},
20352061
{
2062+
"cache": true,
20362063
"context": "",
20372064
"devtool": "cheap-module-source-map",
20382065
"entry": {
@@ -2042,6 +2069,18 @@ exports[`builder environment compat > should generator environment config correc
20422069
},
20432070
"experiments": {
20442071
"asyncWebAssembly": true,
2072+
"cache": {
2073+
"buildDependencies": [
2074+
"package.json",
2075+
"tsconfig.json",
2076+
],
2077+
"storage": {
2078+
"directory": "node_modules/.cache/rspack",
2079+
"type": "filesystem",
2080+
},
2081+
"type": "persistent",
2082+
"version": "workerSSR-development",
2083+
},
20452084
"inlineConst": false,
20462085
"inlineEnum": false,
20472086
"rspackFuture": {

packages/cli/builder/tests/cache.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('builder rspack with cache', () => {
1515
origin: { bundlerConfigs },
1616
} = await rsbuild.inspectConfig();
1717

18-
expect(bundlerConfigs[0].cache).toBeUndefined();
19-
expect(bundlerConfigs[0].experiments?.cache).toBeUndefined();
18+
expect(bundlerConfigs[0].cache).toBeTruthy();
19+
expect(bundlerConfigs[0].experiments?.cache).toMatchSnapshot();
2020
});
2121

2222
it('should generator rspack config correctly with cache', async () => {

packages/document/docs/en/configure/app/performance/build-cache.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type BuildCacheConfig =
2828

2929
Controls the caching behavior during the build process.
3030

31-
When you are using webpack as build tool, Modern.js will enable build cache by default to improve the compile speed. You can disable the build cache by setting it to `false`:
31+
Modern.js will enable build cache by default to improve the compile speed. You can disable the build cache by setting it to `false`:
3232

3333
```js
3434
export default {
@@ -38,8 +38,6 @@ export default {
3838
};
3939
```
4040

41-
It should be noted that, Rspack's persistent cache is [experimental](https://rspack.rs/config/experiments#experimentscache), which may change in future versions, and this feature needs to be turned on manually.
42-
4341
import RsbuildConfig from '@site-docs-en/components/rsbuild-config-tooltip';
4442

4543
<RsbuildConfig configName="performance.buildCache" />

packages/document/docs/zh/configure/app/performance/build-cache.mdx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type BuildCacheConfig =
2828

2929
控制 Modern.js 在构建过程中的缓存行为。
3030

31-
在使用 webpack 构建时,Modern.js 默认会开启构建缓存来提升二次构建的速度。如果不希望缓存,你可以将 `buildCache` 置为 `false` 将其禁用掉:
31+
在构建时,Modern.js 默认会开启构建缓存来提升二次构建的速度。如果不希望缓存,你可以将 `buildCache` 置为 `false` 将其禁用掉:
3232

3333
```js
3434
export default {
@@ -38,8 +38,6 @@ export default {
3838
};
3939
```
4040

41-
需要注意的是,Rspack 的持久化缓存处于[实验性阶段](https://rspack.rs/zh/config/experiments#experimentscache),可能会在未来的版本中发生变化,该功能需要手动开启。
42-
4341
import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
4442

4543
<RsbuildConfig configName="performance.buildCache" />

0 commit comments

Comments
 (0)