performance.buildCache
- Type:
- Default:
false - Version:
>= 1.2.5
To enable or configure persistent build cache.
When enabled, Rspack will store the build snapshots in the cache directory. In subsequent builds, if the cache is hit, Rspack can reuse the cached results instead of rebuilding from scratch, which can reduce the build time.
Enable cache
Setting performance.buildCache to true will enable the persistent build cache:
Or only enable cache in development mode:
Options
cacheDirectory
- Type:
string - Default:
<root>/node_modules/.cache/rspack
Set the directory for cache files. Relative paths are resolved from the project root.
cacheDigest
- Type:
Array<string | undefined> - Default:
undefined
Add additional cache digests, the previous build cache will be invalidated when any value in the array changes.
cacheDigest allows you to add variables that affect the build result, for example process.env.SOME_ENV.
buildDependencies
- Type:
string[]
buildDependencies is an array of additional code dependencies for the build. Rspack will use a hash of each of these items and all dependencies to invalidate the filesystem cache.
Equivalent to Rspack's cache.buildDependencies option.
Default value
Rsbuild will use the following configuration files as the default build dependencies:
package.json- The file selected by source.tsconfigPath
- The
.envfiles loaded by Rsbuild, when automatic env loading is enabled .browserslistrctailwind.config.*
Additionally:
- When using Rsbuild CLI, it will also automatically add the Rsbuild configuration file (
rsbuild.config.*) to the build dependencies. - When using Rsbuild's loadConfig JS API, it will also automatically add the configuration file path to the build dependencies.
Example
When you add other build dependencies, Rsbuild merges these custom dependencies with the default dependencies and passes them to Rspack.
View cache statistics
Use the onAfterEnvironmentCompile hook to read cache statistics after each compilation and check whether cached results are being reused.
This requires Rsbuild >= 2.3.0. Enable the experimental experiments.newCache option:
For the meaning of each field, see Rspack's cacheInfo documentation.

