Cache
Rspack caches snapshots and intermediate build artifacts, then reuses them in subsequent builds to improve build speed.
- Type:
- Default:
truein development mode,falsein production mode and none mode
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.
Unlike webpack, Rspack does not include any preset build dependencies by default. It's recommended to add your project config files to cache.buildDependencies to ensure the cache is invalidated when configuration changes.
Note: When using Rspack CLI, the config file is automatically added to cache.buildDependencies.
When resolving build dependency files, Rspack recursively parses JS/TS files via AST to track transitive dependencies. For packages under node_modules, recursive resolution stops and the package's package.json is tracked instead.
cache.version
-
Type:
string -
Default:
""
Cache versions, different versions of caches are isolated from each other.
Don't share the same cache (same version and same storage.directory) between builds with different configurations. Doing so may cause incorrect cache hits.
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.readonly
-
Type:
boolean -
Default:
false
Enable read-only cache mode. When enabled, the cache will only be read from disk and never written to, which is useful for CI environments where you want to use a pre-warmed cache without modifying it.
Example:
Enable only in CI:
cache.snapshot
-
Type:
object -
Default:
{}
Configure snapshot strategy. Snapshot is used to determine which files have been modified since the last build. The following configurations are supported:
snapshot.immutablePaths
-
Type:
(RegExp | string)[] -
Default:
[]
An array of paths to immutable files. On hot restart, changes to these paths will be ignored and the cache will be considered valid without re-checking file contents. Suitable for content-addressed paths that are guaranteed to never change once written.
snapshot.managedPaths
-
Type:
(RegExp | string)[] -
Default:
[/[\\/]node_modules[\\/][^.]/]
An array of paths managed by the package manager. On hot restart, Rspack will use the version field in the corresponding package.json to determine whether a package has changed, instead of hashing file contents. This speeds up cache validation for packages that are only updated via the package manager.
snapshot.unmanagedPaths
-
Type:
(RegExp | string)[] -
Default:
[]
Specifies paths within snapshot.managedPaths that should not be treated as managed by the package manager. Files in these paths will fall back to content-hash-based cache validation.
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:

