2017-09-25 19:28:29 +08:00
|
|
|
"use strict";
|
|
|
|
|
2018-07-05 13:20:24 +08:00
|
|
|
/** @typedef {import("./Compiler")} Compiler */
|
|
|
|
/** @typedef {import("./ContextModuleFactory")} ContextModuleFactory */
|
|
|
|
|
2017-09-25 19:28:29 +08:00
|
|
|
class ContextExclusionPlugin {
|
2018-07-05 13:20:24 +08:00
|
|
|
/**
|
|
|
|
* @param {RegExp} negativeMatcher Matcher regular expression
|
|
|
|
*/
|
2017-09-25 19:28:29 +08:00
|
|
|
constructor(negativeMatcher) {
|
|
|
|
this.negativeMatcher = negativeMatcher;
|
|
|
|
}
|
|
|
|
|
2018-07-05 13:20:24 +08:00
|
|
|
/**
|
|
|
|
* Apply the plugin
|
|
|
|
* @param {Compiler} compiler Webpack Compiler
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2017-09-25 19:28:29 +08:00
|
|
|
apply(compiler) {
|
2018-07-05 13:20:24 +08:00
|
|
|
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", (
|
|
|
|
/** @type {ContextModuleFactory} */ cmf
|
|
|
|
) => {
|
2018-02-25 09:00:20 +08:00
|
|
|
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => {
|
2017-09-25 19:28:29 +08:00
|
|
|
return files.filter(filePath => !this.negativeMatcher.test(filePath));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = ContextExclusionPlugin;
|