IgnoreWarningsPlugin.js 942 B

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