1
|
"use strict";
|
2
|
|
3
|
/** @typedef {import("./Compiler")} Compiler */
|
4
|
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
|
5
|
|
6
|
class ContextExclusionPlugin {
|
7
|
/**
|
8
|
* @param {RegExp} negativeMatcher Matcher regular expression
|
9
|
*/
|
10
|
constructor(negativeMatcher) {
|
11
|
this.negativeMatcher = negativeMatcher;
|
12
|
}
|
13
|
|
14
|
/**
|
15
|
* Apply the plugin
|
16
|
* @param {Compiler} compiler Webpack Compiler
|
17
|
* @returns {void}
|
18
|
*/
|
19
|
apply(compiler) {
|
20
|
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => {
|
21
|
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
|
22
|
return files.filter(filePath => !this.negativeMatcher.test(filePath));
|
23
|
});
|
24
|
});
|
25
|
}
|
26
|
}
|
27
|
|
28
|
module.exports = ContextExclusionPlugin;
|