UNPKG

964 BJavaScriptView Raw
1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Tobias Koppers @sokra
4*/
5
6"use strict";
7
8/** @typedef {import("../declarations/WebpackOptions").IgnoreWarningsNormalized} IgnoreWarningsNormalized */
9/** @typedef {import("./Compiler")} Compiler */
10
11class IgnoreWarningsPlugin {
12 /**
13 * @param {IgnoreWarningsNormalized} ignoreWarnings conditions to ignore warnings
14 */
15 constructor(ignoreWarnings) {
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("IgnoreWarningsPlugin", compilation => {
25 compilation.hooks.processWarnings.tap(
26 "IgnoreWarningsPlugin",
27 warnings => {
28 return warnings.filter(warning => {
29 return !this._ignoreWarnings.some(ignore =>
30 ignore(warning, compilation)
31 );
32 });
33 }
34 );
35 });
36 }
37}
38
39module.exports = IgnoreWarningsPlugin;