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.

npm install cache-loader
INSTALL
IMPORT
SIG · CACHE-LOADER
C
cache-loader
testingjavascriptv4.1.0
harness data pending
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.

cache-loader
module.exports = { module: { rules: [ { test: /\.ext$/, use: ['cache-loader', ...loaders] } ] } }
import cacheLoader from 'cache-loader'
Used as a webpack loader in configuration, not as a JS import.
cache-loader/package.json
const pkg = require('cache-loader/package.json');
Can be required to get version for cache identifier.

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 issues
gotchaDo not use cache-loader in front of loaders that are not expensive; the caching overhead can slow down builds.
fix
Only use cache-loader for expensive loaders like babel-loader, ts-loader, or sass-loader.
affects: >=0.0.0
breakingIn version 4.0.0, the minimum Node.js version changed to 8.9.0 and webpack peer dependency to ^4.0.0.
fix
Upgrade Node.js to >=8.9.0 and webpack to ^4.0.0.
affects: >=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.
fix
Use 'cacheKey' option to customize cache key generation.
affects: >=0.0.0
gotchaRead-only mode ('readOnly' option) prevents cache writes but still reads if cache exists. Useful for CI environments.
fix
Set readOnly: true in loader options to avoid writes.
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'cache-loader'
cache-loader is not installed or not in node_modules.
fix
npm install --save-dev cache-loader
Error: cache-loader's peer dependency webpack@^4.0.0 is not installed.
Installed webpack version is incompatible with cache-loader's peer dependencies.
fix
npm install --save-dev webpack@^4.0.0
Module parse failed: Unexpected token. You may need an appropriate loader.
cache-loader is placed incorrectly in loader order; it must come before the expensive loader.
fix
Ensure cache-loader is the first loader in the 'use' array.
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies
webpackrequiredpeer dependency - works as a webpack loader
Agent activity
18 hits · last 30 days
node
16
OpenAI (training)
1
Resources
cache-loader — npm install cache-loader · libregistry