ContextExclusionPlugin.js 854 B

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @import Compiler from "./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. /** @type {RegExp} */
  14. this.negativeMatcher = negativeMatcher;
  15. }
  16. /**
  17. * Applies the plugin by registering its hooks on the compiler.
  18. * @param {Compiler} compiler the compiler instance
  19. * @returns {void}
  20. */
  21. apply(compiler) {
  22. compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, (cmf) => {
  23. cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, (files) =>
  24. files.filter((filePath) => !this.negativeMatcher.test(filePath))
  25. );
  26. });
  27. }
  28. }
  29. module.exports = ContextExclusionPlugin;