网页
综合
更新时间 2026-11-14 16:19:02
Cache | webpack
自动蜘蛛
webpack.js.org
正文约 4798 字
Cache the generated webpack modules and chunks to improve build speed. cache: true is an alias to cache: { type: 'memory' }. To disable caching pass false:
The default value of cache depends on the mode:
While setting cache.type to 'filesystem' opens up more options for configuration.
Collect unused memory allocated during deserialization, only available when cache.type is set to 'filesystem'. This requires copying data into smaller buffers and has a performance cost.
The default value of cache.allowCollectingMemory depends on the mode:
cache.buildDependencies is an object of arrays of additional code dependencies for the build. Webpack will use a hash of each of these items and all dependencies to invalidate the filesystem cache.
Defaults to webpack/lib to get all dependencies of webpack.
It's recommended to set cache.buildDependencies.config: [__filename] in your webpack configuration to get the latest configuration and all dependencies.
Base directory for the cache. Defaults to node_modules/.cache/webpack.
cache.cacheDirectory option is only available when cache.type is set to 'filesystem'.
The final location of the cache is a combination of cache.cacheDirectory + cache.name.
Locations for the cache. Defaults to path.resolve(cache.cacheDirectory, cache.name).
Cache computation of modules which are unchanged and reference only unchanged modules. It can only be used along with cache.type of 'memory', besides, experiments.cacheUnaffected must be enabled to use it.
false | 'gzip' | 'brotli' | 'zstd'
Compression type used for the cache files. By default it is false.
'zstd' (Zstandard) is available since webpack 5.109.0 and requires Node.js >= 22.15.0, where the built-in node:zlib zstd bindings are available.
cache.compression option is only available when cache.type is set to 'filesystem'.
Algorithm used the hash generation. See Node.js crypto for more details. Defaults to md4.
cache.hashAlgorithm option is only available when cache.type is set to 'filesystem'.
Time in milliseconds. cache.idleTimeout denotes the time period after which the cache storing should happen.
cache.idleTimeout option is only available when cache.type is set to 'filesystem'.
Time in milliseconds. cache.idleTimeoutAfterLargeChanges is the time period after which the cache storing should happen when larger changes have been detected.
cache.idleTimeoutAfterLargeChanges option is only available when cache.type is set to 'filesystem'.
Time in milliseconds. cache.idleTimeoutForInitialStore is the time period after which the initial cache storing should happen.
cache.idleTimeoutForInitialStore option is only available when cache.type is set to 'filesystem'.
Moved to snapshot.managedPaths
cache.managedPaths is still accepted by the configuration schema (only under type: 'filesystem') but ignored: webpack drops it while normalizing the configuration and only reads snapshot.managedPaths, which is the effective option for package-manager managed paths.
The amount of time in milliseconds that unused cache entries are allowed to stay in the filesystem cache; defaults to one month.
cache.maxAge option is only available when cache.type is set to 'filesystem'.
Define the lifespan of unused cache entries in the memory cache.
cache.maxGenerations: 1: Cache entries are removed after being unused for a single compilation.
cache.maxGenerations: Infinity: Cache entries are kept forever.
cache.maxGenerations option is only available when cache.type is set to 'memory'.
Define the lifespan of unused cache entries in the memory cache.
cache.maxMemoryGenerations: 0: Persistent cache will not use an additional memory cache. It will only cache items in memory until they are serialized to disk. Once serialized the next read will deserialize them from the disk again. This mode will minimize memory usage but introduce a performance cost.
cache.maxMemoryGenerations: 1: This will purge items from the memory cache once they are serialized and unused for at least one compilation. When they are used again they will be deserialized from the disk. This mode will minimize memory usage while still keeping active items in the memory cache.
cache.maxMemoryGenerations: small numbers > 0 will have a performance cost for the GC operation. It gets lower as the number increases.
The default value of cache.maxMemoryGenerations depends on the mode:
Cache computation of modules which are unchanged and reference only unchanged modules in memory. It can only be used along with cache.type of 'filesystem', besides, experiments.cacheUnaffected must be enabled to use it.
Name for the cache. Different names will lead to different coexisting caches. Defaults to ${config.name}-${config.mode}. Using cache.name makes sense when you have multiple configurations which should have independent caches.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。