IgnoreWarningsPlugin.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. MIT License http://www.opensource.org/licenses/mit-license.php
  3. Author Tobias Koppers @sokra
  4. */
  5. "use strict";
  6. /** @typedef {import("./Compiler")} Compiler */
  7. /** @typedef {import("./Compilation")} Compilation */
  8. /** @typedef {(warning: Error, compilation: Compilation) => boolean} IgnoreFn */
  9. const PLUGIN_NAME = "IgnoreWarningsPlugin";
  10. class IgnoreWarningsPlugin {
  11. /**
  12. * Creates an instance of IgnoreWarningsPlugin.
  13. * @param {IgnoreFn[]} ignoreWarnings conditions to ignore warnings
  14. */
  15. constructor(ignoreWarnings) {
  16. /** @type {IgnoreFn[]} */
  17. this._ignoreWarnings = ignoreWarnings;
  18. }
  19. /**
  20. * Applies the plugin by registering its hooks on the compiler.
  21. * @param {Compiler} compiler the compiler instance
  22. * @returns {void}
  23. */
  24. apply(compiler) {
  25. compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
  26. compilation.hooks.processWarnings.tap(PLUGIN_NAME, (warnings) =>
  27. warnings.filter(
  28. (warning) =>
  29. !this._ignoreWarnings.some((ignore) => ignore(warning, compilation))
  30. )
  31. );
  32. });
  33. }
  34. }
  35. module.exports = IgnoreWarningsPlugin;