NormalModuleFactory Hooks

The NormalModuleFactory module is used by the Compiler to generate modules. Starting with entry points, it resolves each request, parses the content to find further requests, and keeps crawling through files by resolving all and parsing any new files. At last stage, each dependency becomes a Module instance.

The NormalModuleFactory class extends Tapable and provides the following lifecycle hooks. They can be tapped the same way as compiler hooks:

NormalModuleFactory.hooks.someHook.tap(/* ... */);

NormaleModuleFactory creates Parser and Generator instances which can be accessed by HookMaps. Identifier must be passed to tap into these:

NormalModuleFactory.hooks.someHook.for('identifier').tap(/* ... */);

As with the compiler, tapAsync and tapPromise may also be available depending on the type of hook.

beforeResolve

AsyncSeriesBailHook

Fired when a new dependency request is encountered. A dependency can be ignored by returning false. Otherwise, it should return undefined to proceed.

  • Callback Parameters: ResolveData

factorize

AsyncSeriesBailHook

Fired before initiating resolve. It should return undefined to proceed.

  • Callback Parameters: resolveData

resolve

AsyncSeriesBailHook

Fired before the request is resolved. A dependency can be ignored by returning false. Returning a Module instance would finalize the process. Otherwise, it should return undefined to proceed.

  • Callback Parameters: resolveData

resolveForScheme

AsyncSeriesBailHook

Fired before a request with scheme (URI) is resolved.

  • Callback Parameters: resolveData

afterResolve

AsyncSeriesBailHook

Fired after the request is resolved.

  • Callback Parameters: resolveData

createModule

AsyncSeriesBailHook

Fired before a Module instance is created.

  • Callback Parameters: createData resolveData

module

SyncWaterfallHook

Fired after a Module instance is created.

  • Callback Parameters: module createData resolveData

createParser

HookMap<SyncBailHook>

Fired before a Parser instance is created. parserOptions is options in module.parser for the corresponding identifier or an empty object.

  • Hook Parameters: identifier

  • Callback Parameters: parserOptions

parser

HookMap<SyncHook>

Fired after a Parser instance is created.

  • Hook Parameters: identifier

  • Callback Parameters: parser parserOptions

Possible default identifiers: javascript/auto javascript/dynamic javascript/esm json webassembly/sync webassembly/async asset

createGenerator

HookMap<SyncBailHook>

Fired before a Generator instance is created. generatorOptions is options in module.parser for the corresponding identifier or an empty object.

  • Hook Parameters: identifier

  • Callback Parameters: generatorOptions

generator

HookMap<SyncHook>

Fired after a Generator instance is created.

  • Hook Parameters: identifier

  • Callback Parameters: generator generatorOptions

Possible default identifiers: json webassembly/sync webassembly/async asset asset/source asset/resource asset/inline


Contributors