webpack/lib/IgnoreWarningsPlugin.js

39 lines
942 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
/** @typedef {import("../declarations/WebpackOptions").IgnoreWarningsNormalized} IgnoreWarningsNormalized */
/** @typedef {import("./Compiler")} Compiler */
2025-04-23 20:03:37 +08:00
const PLUGIN_NAME = "IgnoreWarningsPlugin";
class IgnoreWarningsPlugin {
/**
* @param {IgnoreWarningsNormalized} ignoreWarnings conditions to ignore warnings
*/
constructor(ignoreWarnings) {
this._ignoreWarnings = ignoreWarnings;
}
2024-07-31 12:23:44 +08:00
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
2025-04-23 20:03:37 +08:00
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
compilation.hooks.processWarnings.tap(PLUGIN_NAME, warnings =>
2024-07-31 11:31:11 +08:00
warnings.filter(
warning =>
!this._ignoreWarnings.some(ignore => ignore(warning, compilation))
)
);
});
}
}
module.exports = IgnoreWarningsPlugin;