webpack/lib/ContextExclusionPlugin.js

34 lines
741 B
JavaScript
Raw Normal View History

2018-07-30 23:08:51 +08:00
/*
MIT License http://www.opensource.org/licenses/mit-license.php
*/
"use strict";
/** @typedef {import("./Compiler")} Compiler */
2025-04-23 20:03:37 +08:00
const PLUGIN_NAME = "ContextExclusionPlugin";
class ContextExclusionPlugin {
/**
* @param {RegExp} negativeMatcher Matcher regular expression
*/
constructor(negativeMatcher) {
this.negativeMatcher = negativeMatcher;
}
/**
* Apply the plugin
2018-11-03 04:05:46 +08:00
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, (cmf) => {
cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, (files) =>
files.filter((filePath) => !this.negativeMatcher.test(filePath))
2024-07-31 11:31:11 +08:00
);
});
}
}
module.exports = ContextExclusionPlugin;