Cache
The cache option controls Rspack's caching strategy and lets Rspack reuse cached data across builds to improve build performance.
- Type:
- Default:
{ type: 'memory' }in development mode (equivalent totrue),falsein production mode and none mode
Memory cache
Set cache to true or { type: 'memory' } to enable in-memory cache. Memory cache is kept only in the current compiler process and is useful for rebuilds, watch mode, and HMR.
Memory cache does not write cache data to disk, so it is cleared when the process exits and cannot speed up a fresh build started later. It is best suited for long-running development workflows where the same compiler instance handles multiple rebuilds.
or:
Persistent cache
Set cache to { type: 'persistent' } to enable persistent cache. Persistent cache stores cache data on disk so later build processes can reuse it.
buildDependencies
- Type:
string[] - Default:
[]
cache.buildDependencies is an array of file or directory paths treated as build dependencies. Rspack tracks these paths and invalidates the persistent cache when any tracked build dependency changes.
Unlike webpack, Rspack does not include any preset build dependencies by default. Add project configuration files that are not loaded by Rspack CLI to cache.buildDependencies so the cache is invalidated when those files change.
Note: When using Rspack CLI, the config file is automatically added to cache.buildDependencies.
When resolving build dependencies, Rspack recursively traverses directories and parses JS/TS files via AST to track transitive dependencies. For dependencies resolved under node_modules, recursive resolution stops and the corresponding package's package.json is tracked when available.
version
- Type:
string - Default:
""
cache.version is an additional version string included in the persistent cache key. Use it to manually isolate or invalidate persistent cache data.
Don't share the same cache (same cache.version and same cache.storage.directory) between builds with different configurations. Doing so may cause incorrect cache hits.
In addition to buildDependencies validation and version, the persistent cache key also includes the Rspack version, config.name, config.mode, and persistent cache options that affect cached content.
Changing these values isolates the cache and avoids reusing stale persistent cache data.
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.
Example:
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.
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.
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:
snapshot
- Type:
object - Default:
{ immutablePaths: [], managedPaths: [/[\\/]node_modules[\\/][^.]/], unmanagedPaths: [] }
Configure the snapshot strategy used by persistent cache to determine which dependencies have changed since the previous build.
snapshot.immutablePaths
- Type:
(RegExp | string)[] - Default:
[]
An array of immutable paths. When restoring from persistent cache, Rspack treats matching paths as unchanged and does not re-check their contents. This is suitable for content-addressed paths that never change after being written.
snapshot.managedPaths
- Type:
(RegExp | string)[] - Default:
[/[\\/]node_modules[\\/][^.]/]
An array of paths managed by the package manager. When restoring from persistent cache, Rspack uses 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 through the package manager.
snapshot.unmanagedPaths
- Type:
(RegExp | string)[] - Default:
[]
Specifies paths within cache.snapshot.managedPaths that should not be treated as managed by the package manager. Files in these paths fall back to content-hash-based cache validation.
storage
- Type:
{ type: 'filesystem'; directory?: string; maxAge?: number; maxGenerations?: number }
Configure cache storage. Currently only filesystem storage is supported.
storage.type
- Type:
'filesystem' - Default:
'filesystem'
Use type to configure the cache storage type. Currently only filesystem storage is supported.
storage.directory
- Type:
string - Default:
node_modules/.cache/rspack/<mode>ornode_modules/.cache/rspack/<name>-<mode>
Use directory to configure the cache directory. The default directory is resolved from config.context, config.name, config.mode, and the multi-compiler index. In multi-compiler mode, later compilers append -<index> to avoid sharing the same directory.
Configure different config.name values for different compilers so they use different cache.storage.directory values and avoid cache conflicts.
storage.maxAge
- Type:
number(positive integer, in seconds) orInfinity - Default:
7 * 24 * 60 * 60(7 days)
The maximum time, in seconds, that a cache generation can remain unused. During cleanup, Rspack removes cache generations that have not been accessed for longer than maxAge. Set maxAge to Infinity to disable age-based cleanup.
storage.maxGenerations
- Type:
number(positive integer) orInfinity - Default:
3
This is a generational cleanup policy that controls how many cache generations can be retained in the current cache directory. When the number of generations exceeds the limit, Rspack removes old inactive generations. Set maxGenerations to Infinity to disable generation-based cleanup.
Inspect persistent cache logs
Persistent cache logs are emitted through the rspack.persistentCache logger. To display them in the build stats, enable this logger with stats.loggingDebug:
The logs include key persistent cache events, such as whether persistent cache is enabled, whether build dependencies are valid, whether cache recovery succeeded, and why the persistent cache was invalidated. They also include read and write timings for each cache phase (for example, build dependency validation, snapshot restore, occasion recovery, staging, and flushing to disk).
If you want to include logs from other loggers too, enable stats.logging:
Disable cache
Set cache to false to disable both memory cache and persistent cache. Disabling cache is generally not recommended because it can make rebuilds during development significantly slower.
Migrating from webpack
See Migrate from webpack - Cache configuration for how to migrate webpack cache configuration to Rspack.

