@zaaack/cache-loader
v1.0.4
Published
Caches the result of following loaders on disk.
Downloads
3
Readme
npm install --save-dev @zaaack/cache-loader
Add this loader in front of other (expensive) loaders to cache the result on disk.
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.ext$/,
use: [
'@zaaack/cache-loader',
...loaders
],
include: path.resolve('src')
}
]
}
}
⚠️ Note:
- This is a fork version of original cache-loader, by using leveldb & xxhash & level-ttl, we can make cache faster and easier!
- There is an overhead for saving the reading and saving the cache file, so only use this loader to cache expensive loaders.
|Name|Type|Default|Description|
|:--:|:--:|:-----:|:----------|
|cacheDirectory
|{String}
|path.resolve('.cache-loader')
|Provide a cache directory where cache items should be stored|
|cacheIdentifier
|{String}
|cache-loader:{version} {process.env.NODE_ENV}
|Provide an invalidation identifier which is used to generate the hashes. You can use it for extra dependencies of loaders.|
|ttl
|{Number}
|30 * 24 * 3600 * 1000 (30 days by ms)| TTL(time to live) for cache. |
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
'@zaaack/cache-loader',
'babel-loader'
],
include: path.resolve('src')
}
]
}
}
Options
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: '@zaaack/cache-loader',
options: {
cacheDirectory: path.resolve('.cache')
}
},
'babel-loader'
],
include: path.resolve('src')
}
]
}
}