@zaaack/cache-loader

1.0.4 • Public • Published

npm node deps test coverage chat

Cache Loader

Caches the result of following loaders on disk

Install

npm install --save-dev @zaaack/cache-loader

Usage

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:

  1. This is a fork version of original cache-loader, by using leveldb & xxhash & level-ttl, we can make cache faster and easier!
  2. There is an overhead for saving the reading and saving the cache file, so only use this loader to cache expensive loaders.

Options

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.

Examples

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')
      }
    ]
  }
}

Maintainers

Tobias Koppers Juho Vepsäläinen Joshua Wiens Artem Sapegin Michael Ciniawsky Alexander Krasnoyarov Zack Young

Readme

Keywords

none

Package Sidebar

Install

npm i @zaaack/cache-loader

Weekly Downloads

1

Version

1.0.4

License

MIT

Last publish

Collaborators

  • zaaack