ContextExclusionPlugin.js 797 B

1234567891011121314151617181920212223242526272829303132
  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. class ContextExclusionPlugin {
  8. /**
  9. * @param {RegExp} negativeMatcher Matcher regular expression
  10. */
  11. constructor(negativeMatcher) {
  12. this.negativeMatcher = negativeMatcher;
  13. }
  14. /**
  15. * Apply the plugin
  16. * @param {Compiler} compiler the compiler instance
  17. * @returns {void}
  18. */
  19. apply(compiler) {
  20. compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
  21. cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
  22. return files.filter(filePath => !this.negativeMatcher.test(filePath));
  23. });
  24. });
  25. }
  26. }
  27. module.exports = ContextExclusionPlugin;