ContextExclusionPlugin.js 807 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. */
  4. "use strict";
  5. /** @typedef {import("./Compiler")} Compiler */
  6. /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
  7. const PLUGIN_NAME = "ContextExclusionPlugin";
  8. class ContextExclusionPlugin {
  9. /**
  10. * @param {RegExp} negativeMatcher Matcher regular expression
  11. */
  12. constructor(negativeMatcher) {
  13. this.negativeMatcher = negativeMatcher;
  14. }
  15. /**
  16. * Apply the plugin
  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;