1.0.1 • Published 4 years ago

@bsmth/loader-cache v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

bismuth loader cache

Disk caching utils used internally by @bsmth webpack loaders.

Motivations

Dealing with images can be really messy, when you have to support multiple resolutions, formats and compression levels. @bsmth/img-loader attempts to solve this by doing all conversions, resizing and compressions automatically and on demand, when you import an image.


Installation

yarn add --dev @bsmth/loader-cache
npm i --save-dev @bsmth/loader-cache

Setup

You need to add the loader and this cache management plugin to your webpack config.

import { CachePlugin } from "@bsmth/loader-cache";

export default {
	plugins: [
		// ...
		new CachePlugin({
			// ...
		}),
	],
};

Options

Some @bsmth loaders will cache processed images and intermediates on disk. To manage the cache (e.g. to auto clear stale files) we provides a CachePlugin which accepts the following options:

NameTypeDefaultDescription
enabledbooleantruean easy way to disable the plugin conditionally
cacheDirstring'.bsmth-loader-cache'specifies the cache directory
deleteUnusedFilesbooleantruewhether to auto delete unused cache files
aggressivebooleantruetoggles aggressive cache cleaning. If true, the plugin will check for and delete stale files on every change.This may be undesirable, for example when testing/comparing different quality renditions, since the assets will be rebuilt every time.Disabling this option instructs the plugin to only check and clean once on startup.
verbosebooleanfalsetoggles verbose logging

Inner workings

import { 
  read, 
  write, 
  has, 
  getFilename, 
  invalidateChildren, 
  ensureCacheReady 
} from '@bsmth/loader-cache';

This area is ment for internal documentation in the future.

License

© 2021 the project bismuth authors, licensed under MIT.