Skip to content

Instantly share code, notes, and snippets.

@Super-Chama
Created April 15, 2023 15:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Super-Chama/990cb1aba379cce5d801aa8ba29c27a4 to your computer and use it in GitHub Desktop.
Save Super-Chama/990cb1aba379cce5d801aa8ba29c27a4 to your computer and use it in GitHub Desktop.
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