ContextModuleFactory Hooks
The ContextModuleFactory module is used by the Compiler to generate dependencies from webpack specific require.context API. It resolves the requested directory, generates requests for each file and filters against passed regExp. Matching dependencies then passes through NormalModuleFactory.
The ContextModuleFactory class exposes a hooks object of tapable hooks and provides the following
lifecycle hooks. They can be tapped the same way as compiler hooks:
ContextModuleFactory.hooks.someHook.tap(/* ... */);As with the compiler, tapAsync and tapPromise may also be available
depending on the type of hook.
beforeResolve
AsyncSeriesWaterfallHook
Called before resolving the requested directory. The request can be ignored by returning false.
- Callback Parameters:
data
The data object describes the context request to resolve and its properties can be updated in place (for example, overwriting data.request to redirect where modules are loaded from):
context:string— the base directory path from which the context request is resolved.request:string— the resolver request to resolve fromcontext(for example a relative path, a package/module request likesome-package/dir, or a request with loader prefixes).recursive:boolean— whether subdirectories should be searched recursively.regExp:RegExp | false | null— the regular expression used to filter matching files inside the directory, orfalse/nullwhen no regular expression is set (which causes ordinary context requests to match no dependencies and produce an empty context, such asrequire(name)with defaultexprContextRegExp: false).dependencies:ContextDependency[]— the dependency instances associated with the context request.
afterResolve
AsyncSeriesWaterfallHook
Called after the requested directory resolved.
- Callback Parameters:
data
contextModuleFiles
SyncWaterfallHook
Called after directory contents are read. On recursive mode, calls for each sub-directory as well. Callback parameter is an array of all file and folder names in each directory.
- Callback Parameters:
fileNames
alternativeRequests
AsyncSeriesWaterfallHook
Called once per directory with the array of generated { context, request } alternatives, before filtering against regExp. Return the (possibly modified) array.
- Callback Parameters:
modulesoptions



