What is webpack-filter-warnings-plugin?
The webpack-filter-warnings-plugin is an npm package designed to help developers filter out unwanted warnings from the webpack compilation process. This can be particularly useful in large projects where certain warnings are known and benign, allowing developers to focus on more significant issues.
What are webpack-filter-warnings-plugin's main functionalities?
Filter specific warnings
This feature allows developers to exclude specific warnings from the webpack output by using regular expressions. In the provided code sample, the plugin is configured to exclude warnings that match the regular expression related to critical dependency warnings.
const FilterWarningsPlugin = require('webpack-filter-warnings-plugin');
module.exports = {
plugins: [
new FilterWarningsPlugin({
exclude: /Critical dependency: the request of a dependency is an expression/
})
]
};
Other packages similar to webpack-filter-warnings-plugin
ignore-emit-webpack-plugin
Similar to webpack-filter-warnings-plugin, ignore-emit-webpack-plugin allows developers to ignore specific files or warnings during the webpack emit phase. It differs in that it focuses on the output files rather than the warnings themselves, providing a more targeted approach for controlling the output.
webpack-filter-warnings-plugin
![coverage](https://codecov.io/gh/mattlewis92/webpack-filter-warnings-plugin/branch/master/graph/badge.svg)
Allows you to hide certain warnings from webpack compilations
Install
npm i -D webpack-filter-warnings-plugin
Usage
const { FilterWarningsPlugin } = require('webpack-filter-warnings-plugin');
module.exports = {
plugins: [
new FilterWarningsPlugin({
exclude: /any-warnings-matching-this-will-be-hidden/
})
]
}
Using with Typescript
Webpack Filter Warnings Plugin is completely written in Typescript. As such, it exposes Typescript bindings.
Before using it, install webpack typings:
npm i --save-dev @types/webpack
or
yarn add --dev @types/webpack
Use ES imports:
import { FilterWarningsPlugin } from 'webpack-filter-warnings-plugin';
Options
Library exposes only one option: exclude
. It may be one of RegExp
, String
or Function
.
String as exclude
filter
When passing string as exclude parameter, phrase is converted to wildcard and matches any phrase that contains it.
module.exports = {
plugins: [
new FilterWarningsPlugin({
exclude: 'hide me'
})
]
}
This config will match any of Should hide me
, Hide me, please
, HiDe Me
(filter is case insensitive) etc.
Function as exclude
filter
module.exports = {
plugins: [
new FilterWarningsPlugin({
exclude: (input) => /.*hide.*/.test(input),
})
]
}
Why not use the built in stats.warningsFilter option?
Currently karma-webpack does not respect the stats.warningsFilter option. Also when excluding all warnings, webpack still says Compiled with warnings.
when all warnings are filtered. Hopefully this plugin will no longer need to exist one day.
Licence
MIT