npm install --save-dev 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: [
'cache-loader',
...loaders
],
include: path.resolve('src')
}
]
}
}
⚠️ Note that 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 |
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
'cache-loader',
'babel-loader'
],
include: path.resolve('src')
}
]
}
}
webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: path.resolve('.cache')
}
},
'babel-loader'
],
include: path.resolve('src')
}
]
}
}
Tobias Koppers |
Juho Vepsäläinen |
Joshua Wiens |
Artem Sapegin |
Michael Ciniawsky |
Alexander Krasnoyarov |