IgnoreWarningsPlugin.js 964 B

123456789101112131415161718192021222324252627282930313233343536373839
  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").IgnoreWarningsNormalized} IgnoreWarningsNormalized */
  7. /** @typedef {import("./Compiler")} Compiler */
  8. class IgnoreWarningsPlugin {
  9. /**
  10. * @param {IgnoreWarningsNormalized} ignoreWarnings conditions to ignore warnings
  11. */
  12. constructor(ignoreWarnings) {
  13. this._ignoreWarnings = ignoreWarnings;
  14. }
  15. /**
  16. * Apply the plugin
  17. * @param {Compiler} compiler the compiler instance
  18. * @returns {void}
  19. */
  20. apply(compiler) {
  21. compiler.hooks.compilation.tap("IgnoreWarningsPlugin", compilation => {
  22. compilation.hooks.processWarnings.tap(
  23. "IgnoreWarningsPlugin",
  24. warnings => {
  25. return warnings.filter(warning => {
  26. return !this._ignoreWarnings.some(ignore =>
  27. ignore(warning, compilation)
  28. );
  29. });
  30. }
  31. );
  32. });
  33. }
  34. }
  35. module.exports = IgnoreWarningsPlugin;