Cache
Rspack caches snapshots and intermediate build artifacts, then reuses them in subsequent builds to improve build speed.
-
Type:
CacheOptions -
Default: production mode is
false, development mode istrue
Disable cache
Configuring cache to false to disable cache.
Memory cache
Configuring cache to true or { type: "memory" } to enable memory cache.
or
Persistent cache
Configuring cache to { type: "persistent" } to enable persistent cache.
cache.buildDependencies
-
Type:
string[] -
Default:
[]
cache.buildDependencies is an array of files containing build dependencies, Rspack will use the hash of each of these files to invalidate the persistent cache.
It's recommended to set cache.buildDependencies: [__filename] in your rspack configuration to get the latest configuration.
cache.version
-
Type:
string -
Default:
""
Cache versions, different versions of caches are isolated from each other.
In addition to buildDependencies and version configurations that affect persistent cache invalidation, Rspack also invalidates persistent cache when the following fields change.
cache.portable
-
Type:
boolean -
Default:
false
Enable portable cache mode. When enabled, the generated cache content can be shared across different platforms and paths within the same project.
Portable cache is built on top of persistent cache and makes the cache platform-independent by converting platform-specific data (e.g., absolute paths to relative paths) during serialization and deserialization.
A typical use case is in CI environments where Windows, Linux, and macOS can share the same cache for acceleration without generating three separate cache copies.
Example:
Files outside the project directory (outside config.context) will be converted to relative paths. If these files don't exist in the new environment, it will trigger a rebuild of the related modules.
cache.snapshot
Configure snapshot strategy. Snapshot is used to determine which files have been modified during shutdown. The following configurations are supported:
snapshot.immutablePaths
-
Type:
(RegExp | string)[] -
Default:
[]
An array of paths to immutable files, changes to these paths will be ignored during hot restart.
snapshot.managedPaths
-
Type:
(RegExp | string)[] -
Default:
[/[\\/]node_modules[\\/][^.]/]
An array of paths managed by the package manager. During hot start, it will determine whether to modify the path based on the version in package.json.
snapshot.unmanagedPaths
-
Type:
(RegExp | string)[] -
Default:
[]
Specifies an array of paths in snapshot.managedPaths that are not managed by the package manager
cache.storage
-
Type:
{ type: 'filesystem', directory: string } -
Default:
{ type: 'filesystem', directory: 'node_modules/.cache/rspack' }
Configure cache storage. Currently only file system storage is supported. The cache directory can be set through directory. The default is node_modules/.cache/rspack.
Rspack will generate a cache folder in the storage.directory based on config.name, config.mode, the file contents in buildDependencies and version.
Rspack will automatically clean up cache folders that have not been accessed for a long time (7 days) at startup.
Migrating from webpack config
The Rspack cache configuration is different from the webpack cache configuration. You can refer to the following steps to migrate the webpack cache configuration.
- According to the cache type, set the Rspack cache type. Continue with the next step for persistent cache, and stop here for other types of cache.
- Migrate
cache.buildDependencies
- Migrate
cache.versionandcache.name
- Migrate
snapshot
- Migrate
cache.cacheDirectory
Sample migration code:

