zodern:caching-minifier

v0.5.0Published last year

zodern:caching-minifier

An easy way to make minifier plugins cache. Extends caching-compiler to add support for minifiers.

The cache key is a hash of the file's content and source map. Uses both an in-memory and on disk cache.

Example:

1class AwesomeMinifier extends CachingMinifier {
2  constructor() {
3    super({
4      minifierName: 'awesome',
5      defaultCacheSize: 1024*1024*10,
6    });
7  }
8  minifyOneFile(inputFile) {
9    // Should return a { code, sourcemap } object.
10    return Awesomifier.minify(inputFile.getContentsAsString());
11  }
12  processFilesForBundle(files, options) {
13    // normal code for processFilesForBundle
14    // except to minify a file call this.minifyFile(file);
15    // this.minifyFile handles caching, and will call
16    // this.minifyOneFile as needed
17  }
18}
19
20Plugin.registerMinifier({
21  extensions: ['js'],
22  archMatching: 'web',
23}, () => new AwesomeCompiler());