For AI agents: the complete documentation index is available at /zh/llms.txt, the full documentation bundle is available at /zh/llms-full.txt, and this page is available as Markdown at /zh/api/plugin-api/context-module-factory-hooks.md.
close

ContextModuleFactory 钩子

Compiler 使用 ContextModuleFactory 模块从 require.context API 生成依赖关系。它会解析请求的目录,为每个文件生成请求,并依据传递来的 regExp 进行过滤。最后匹配成功的依赖关系将被传入 NormalModuleFactory。

beforeResolve

AsyncSeriesWaterfallHook<[BeforeResolveResult], BeforeResolveResult | void>

在解析请求的目录之前调用。

回调可以返回解析数据,也可以直接修改解析数据而不返回值。返回 false 会忽略该请求。

afterResolve

AsyncSeriesWaterfallHook<[AfterResolveResult], AfterResolveResult | void>

在请求的目录解析完成后调用。

回调可以返回解析数据,也可以直接修改解析数据而不返回值。返回 false 会忽略该请求。