1 | /*
|
2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
3 | */
|
4 |
|
5 | ;
|
6 |
|
7 | /** @typedef {import("./Compiler")} Compiler */
|
8 | /** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
|
9 |
|
10 | class ContextExclusionPlugin {
|
11 | /**
|
12 | * @param {RegExp} negativeMatcher Matcher regular expression
|
13 | */
|
14 | constructor(negativeMatcher) {
|
15 | this.negativeMatcher = negativeMatcher;
|
16 | }
|
17 |
|
18 | /**
|
19 | * Apply the plugin
|
20 | * @param {Compiler} compiler the compiler instance
|
21 | * @returns {void}
|
22 | */
|
23 | apply(compiler) {
|
24 | compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
|
25 | cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
|
26 | return files.filter(filePath => !this.negativeMatcher.test(filePath));
|
27 | });
|
28 | });
|
29 | }
|
30 | }
|
31 |
|
32 | module.exports = ContextExclusionPlugin;
|