ContextExclusionPlugin.js 721 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. /** @typedef {import("./Compiler")} Compiler */
  3. /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
  4. class ContextExclusionPlugin {
  5. /**
  6. * @param {RegExp} negativeMatcher Matcher regular expression
  7. */
  8. constructor(negativeMatcher) {
  9. this.negativeMatcher = negativeMatcher;
  10. }
  11. /**
  12. * Apply the plugin
  13. * @param {Compiler} compiler Webpack Compiler
  14. * @returns {void}
  15. */
  16. apply(compiler) {
  17. compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
  18. cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
  19. return files.filter(filePath => !this.negativeMatcher.test(filePath));
  20. });
  21. });
  22. }
  23. }
  24. module.exports = ContextExclusionPlugin;