IgnoreWarningsPlugin.js 991 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. * @param {IgnoreFn[]} ignoreWarnings conditions to ignore warnings
  13. */
  14. constructor(ignoreWarnings) {
  15. /** @type {IgnoreFn[]} */
  16. this._ignoreWarnings = ignoreWarnings;
  17. }
  18. /**
  19. * Apply the plugin
  20. * @param {Compiler} compiler the compiler instance
  21. * @returns {void}
  22. */
  23. apply(compiler) {
  24. compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
  25. compilation.hooks.processWarnings.tap(PLUGIN_NAME, (warnings) =>
  26. warnings.filter(
  27. (warning) =>
  28. !this._ignoreWarnings.some((ignore) => ignore(warning, compilation))
  29. )
  30. );
  31. });
  32. }
  33. }
  34. module.exports = IgnoreWarningsPlugin;