Created
April 15, 2023 15:12
-
-
Save Super-Chama/990cb1aba379cce5d801aa8ba29c27a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SuppressWarningsPlugin { | |
warning; | |
maxWarnings; | |
constructor(maxWarnings = 0) { | |
this.maxWarnings = maxWarnings; | |
} | |
apply(compiler) { | |
compiler.hooks.emit.tap("SuppressWarningsPlugin", (compilation) => { | |
if (!Array.isArray(compilation.warnings)) return; | |
const index = compilation.warnings.findIndex( | |
(warnObj) => warnObj.name == "ESLintError" | |
); | |
const e = compilation.warnings.splice(index, 1)[0]; | |
if (Array.isArray(this.warning)) { | |
const formattedMessage = e.message.split(/\r?\n/).filter((msg) => { | |
return this.warning.findIndex((warn) => warn == msg) === -1; | |
}); | |
if (formattedMessage.length > 0) { | |
e.message = formattedMessage.join("\n"); | |
compilation.warnings.push(e); | |
} | |
} else { | |
this.warning = e.message.split(/\r?\n/); | |
} | |
}); | |
} | |
} | |
module.exports = SuppressWarningsPlugin; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment