UNPKG

webpack-clear-require-cache-plugin

Version:

clear require cache upon webpack compiler afterEmit hook

22 lines (19 loc) 503 B
const pluginName = 'clearRequireCachePlugin'; const apply = (tests, compiler) => { compiler.hooks.afterEmit.tapAsync(pluginName, (compilation, callback) => { const moduleIds = Object.keys(require.cache); tests.forEach(regex => { moduleIds.forEach(moduleId => { if (regex.test(moduleId)) { delete require.cache[moduleId]; } }); }); callback(); }); } module.exports = function(options) { return { apply: apply.bind(this, options), }; };