10
0

BasicEffectRulePlugin.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
  7. /** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
  8. class BasicEffectRulePlugin {
  9. /**
  10. * @param {string} ruleProperty the rule property
  11. * @param {string=} effectType the effect type
  12. */
  13. constructor(ruleProperty, effectType) {
  14. this.ruleProperty = ruleProperty;
  15. this.effectType = effectType || ruleProperty;
  16. }
  17. /**
  18. * @param {RuleSetCompiler} ruleSetCompiler the rule set compiler
  19. * @returns {void}
  20. */
  21. apply(ruleSetCompiler) {
  22. ruleSetCompiler.hooks.rule.tap(
  23. "BasicEffectRulePlugin",
  24. (path, rule, unhandledProperties, result, references) => {
  25. if (unhandledProperties.has(this.ruleProperty)) {
  26. unhandledProperties.delete(this.ruleProperty);
  27. const value =
  28. rule[/** @type {keyof RuleSetRule} */ (this.ruleProperty)];
  29. result.effects.push({
  30. type: this.effectType,
  31. value
  32. });
  33. }
  34. }
  35. );
  36. }
  37. }
  38. module.exports = BasicEffectRulePlugin;