ContextExclusionPlugin.js 836 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @typedef {import("./Compiler")} Compiler */
  6. const PLUGIN_NAME = "ContextExclusionPlugin";
  7. class ContextExclusionPlugin {
  8. /**
  9. * Creates an instance of ContextExclusionPlugin.
  10. * @param {RegExp} negativeMatcher Matcher regular expression
  11. */
  12. constructor(negativeMatcher) {
  13. this.negativeMatcher = negativeMatcher;
  14. }
  15. /**
  16. * Applies the plugin by registering its hooks on the compiler.
  17. * @param {Compiler} compiler the compiler instance
  18. * @returns {void}
  19. */
  20. apply(compiler) {
  21. compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, (cmf) => {
  22. cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, (files) =>
  23. files.filter((filePath) => !this.negativeMatcher.test(filePath))
  24. );
  25. });
  26. }
  27. }
  28. module.exports = ContextExclusionPlugin;