Skip to content

Commit 9dc398b

Browse files
EugeneHlushkomontogeek
authored andcommitted
docs(plugins) IgnorePlugin new syntax and options (#2721)
1 parent 8518cbb commit 9dc398b

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

src/content/plugins/ignore-plugin.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,38 @@ contributors:
77
- EugeneHlushko
88
---
99

10-
Prevent generation of modules for `import` or `require` calls matching the following regular expressions:
10+
IgnorePlugin prevents generation of modules for `import` or `require` calls matching the regular expressions or filter functions:
1111

12-
- `requestRegExp` A RegExp to test the request against.
13-
- `contextRegExp` (optional) A RegExp to test the context (directory) against.
12+
## Using regular expressions
1413

15-
``` js
14+
- `requestRegExp`: A RegExp to test the request against.
15+
- `contextRegExp`: (optional) A RegExp to test the context (directory) against.
16+
17+
```javascript
18+
new webpack.IgnorePlugin({requestRegExp, contextRegExp});
19+
// old way, deprecated in webpack v5
1620
new webpack.IgnorePlugin(requestRegExp, [contextRegExp]);
1721
```
1822

19-
The following examples demonstrate a few ways this plugin can be used.
23+
## Using filter functions
24+
25+
- `checkContext(context)` A Filter function that receives context as the argument, must return boolean.
26+
- `checkResource(resource)` A Filter function that receives resource as the argument, must return boolean.
2027

28+
```javascript
29+
new webpack.IgnorePlugin({
30+
checkContext (context) {
31+
// do something with context
32+
return true|false;
33+
},
34+
checkResource (resource) {
35+
// do something with resource
36+
return true|false;
37+
}
38+
});
39+
```
2140

22-
## Ignore Moment Locales
41+
## Example of ignoring Moment Locales
2342

2443
As of [moment](https://momentjs.com/) 2.18, all locales are bundled together with the core library (see [this GitHub issue](https://github.com/moment/moment/issues/2373)).
2544

@@ -37,8 +56,11 @@ require('./locale/' + name);
3756

3857
...your first regexp must match that `'./locale/'` string. The second `contextRegExp` parameter is then used to select specific directories from where the import took place. The following will cause those locale files to be ignored:
3958

40-
```js
41-
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/);
59+
```javascript
60+
new webpack.IgnorePlugin({
61+
requestRegExp: /^\.\/locale$/,
62+
contextRegExp: /moment$/
63+
});
4264
```
4365

4466
...which means "any require statement matching `'./locale'` from any directories ending with `'moment'` will be ignored.

0 commit comments

Comments
 (0)