Registry / testing / cache-loader

cache-loader

JSON →
library4.1.0jsnpmunverified

Caches the result of following webpack loaders on disk (or database) to speed up subsequent builds. The current stable version is 4.1.0, actively maintained by the webpack-contrib team. Key differentiator: it caches at the loader level rather than at the module level like hard-source-webpack-plugin, making it ideal for expensive transpilation or compilation loaders. Note that there is overhead for reading/writing cache files, so only use for expensive loaders. Supports configurable cache directory, cache key, cache identifier, read/write functions, and read-only mode.

testingdevops
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Used as a webpack loader in configuration, not as a JS import.

module.exports = { module: { rules: [ { test: /\.ext$/, use: ['cache-loader', ...loaders] } ] } }

Can be required to get version for cache identifier.

const pkg = require('cache-loader/package.json');

This shows how to use cache-loader to cache the result of babel-loader on disk.

// webpack.config.js const path = require('path'); module.exports = { module: { rules: [ { test: /\.js$/, use: [ 'cache-loader', 'babel-loader' ], include: path.resolve('src'), }, ], }, };
Debug
Known footguns
gotchaDo not use cache-loader in front of loaders that are not expensive; the caching overhead can slow down builds.
breakingIn version 4.0.0, the minimum Node.js version changed to 8.9.0 and webpack peer dependency to ^4.0.0.
gotchaThe cache is invalidated by default based on the module's absolute path and cacheIdentifier. Changes to dependencies not in the module's require chain may not trigger cache invalidation.
gotchaRead-only mode ('readOnly' option) prevents cache writes but still reads if cache exists. Useful for CI environments.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
8 hits · last 30 days
gptbot
3
mj12bot
1
ahrefsbot
1
Resources