webpack-clear-require-cache-plugin
Version:
clear require cache upon webpack compiler afterEmit hook
23 lines (20 loc) • 545 B
JavaScript
;
var pluginName = 'clearRequireCachePlugin';
var apply = function apply(tests, compiler) {
compiler.hooks.afterEmit.tapAsync(pluginName, function (compilation, callback) {
var moduleIds = Object.keys(require.cache);
tests.forEach(function (regex) {
moduleIds.forEach(function (moduleId) {
if (regex.test(moduleId)) {
delete require.cache[moduleId];
}
});
});
callback();
});
};
module.exports = function (options) {
return {
apply: apply.bind(this, options)
};
};