IgnoreWarningsPlugin.js 919 B

123456789101112131415161718192021222324252627282930313233343536
  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("IgnoreWarningsPlugin", warnings =>
  23. warnings.filter(
  24. warning =>
  25. !this._ignoreWarnings.some(ignore => ignore(warning, compilation))
  26. )
  27. );
  28. });
  29. }
  30. }
  31. module.exports = IgnoreWarningsPlugin;