html-bundler-webpack-plugin
Version:
Generates complete single-page or multi-page website from source assets. Build-in support for Markdown, Eta, EJS, Handlebars, Nunjucks, Pug. Alternative to html-webpack-plugin.
40 lines (29 loc) • 918 B
JavaScript
const makeSerializable = require('webpack/lib/util/makeSerializable');
const createPersistentCache = () => {
const memorizedCache = new WeakMap();
let cacheIndex = 0;
return (instance) => {
if (memorizedCache.has(instance)) {
return memorizedCache.get(instance);
}
class PersistentCache {
instance = instance;
static getData(instance = {}) {
return new PersistentCache(instance);
}
constructor() {}
serialize(context) {
this.instance.serialize(context);
}
deserialize(context) {
this.instance.deserialize(context);
}
}
// the cache index is needed for multiple configuration
makeSerializable(PersistentCache, __filename, `PersistentCache_${cacheIndex}`);
memorizedCache.set(instance, PersistentCache);
cacheIndex++;
return PersistentCache;
};
};
module.exports = createPersistentCache;