The main compilation logic of Rspack runs on the Rust side. For factors such as stability, performance, and architecture, after the Rust side compilation objects are transferred to the JavaScript side when using hooks, the modifications on these objects will not be synchronized to the Rust side. Therefore, most of hooks are "read-only".
buildModuleTriggered before a module build has started。
SyncHook<[Module]>Module: module instanceexecuteModuleIf there exists compiled-time execution modules, this hook will be called when they are executed.
SyncHook<[ExecuteModuleArgument, ExecuteModuleContext]>ExecuteModuleArgument: arguments of compiled-time execution moduleExecuteModuleContext: context of compiled-time execution modulesucceedModuleExecuted when a module has been built successfully.
SyncHook<[Module]>Module: module instancefinishModulesCalled when all modules have been built without errors.
AsyncSeriesHook<[Module[]]>Module[]: List of module instancesoptimizeModulesCalled at the beginning of the module optimization phase.
SyncBailHook<[Module[]]>Module[]: list of module instancesafterOptimizeModulesCalled after modules optimization has completed.
SyncBailHook<[Module[]]>Module[]: list of module instancesoptimizeTreeCalled before optimizing the dependency tree.
AsyncSeriesHook<[Chunk[], Module[]]>Chunk[]: list of chunk instancesModule[]: list of module instancesoptimizeChunkModulesCalled after the tree optimization, at the beginning of the chunk modules optimization.
AsyncSeriesBailHook<[Chunk[], Module[]]>Chunk[]: list of chunk instancesModule[]: list of module instancesadditionalTreeRuntimeRequirementsCalled after the tree runtime requirements collection.
SyncHook<[Chunk, Set<RuntimeGlobals>]>Chunk: chunk instanceSet<RuntimeGlobals>: runtime requirementsruntimeModuleCalled after a runtime module is added into the compilation.
SyncHook<[RuntimeModule, Chunk]>RuntimeModule: runtime module instanceChunk: chunk instanceprocessAssetsProcess the assets before emit.
AsyncSeriesHook<Assets>Assets: list of asset instancesafterProcessAssetsCalled after the processAssets hook had finished without error.
SyncHook<Assets>Assets: list of asset instancesafterSealCalled after the seal phase.
AsyncSeriesHook<[]>chunkHashTriggered to emit the hash for each chunk.
SyncHook<[Chunk, Hash]>Chunk: chunk instanceHash: chunk hash instancechunkAssetTriggered when an asset from a chunk was added to the compilation.
SyncHook<[Chunk, string]>Chunk: chunk instancestring: asset filenamechildCompilerExecuted after setting up a child compiler.
SyncHook<[Compiler, string, number]>Compiler: child compiler instancestring: child compiler namenumber: child compiler indexstatsPresetThis hook is like a list of actions that gets triggered when a preset is used. It takes in an options object. When a plugin manages a preset, it should change settings in this object carefully without replacing existing ones.
SyncHook<[Partial<StatsOptions>, CreateStatsOptionsContext]>Partial<StatsOptions>: stats optionsCreateStatsOptionsContext: stats contextHere's an illustrative plugin example:
This plugin ensures that for the preset "my-preset", if the all option is undefined, it defaults to true.
statsNormalizeThis hook is used to transform an options object into a consistent format that can be easily used by subsequent hooks. It also ensures that missing options are set to their default values.
SyncHook<[Partial<StatsOptions>, CreateStatsOptionsContext]>Partial<StatsOptions>: stats optionsCreateStatsOptionsContext: stats contextHere's an illustrative plugin example:
In this plugin, if the myOption is missing, it sets it to []. Additionally, it ensures that myOption is always an array even if it was originally defined as a single value.
statsFactoryThis hook provides access to the StatsFactory class for specific options.
SyncHook<[StatsFactory, StatsOptions]>StatsFactory: stats factory instance, see Stats Factory Hooks for more detailsStatsOptions: stats optionsstatsPrinterThis hook provides access to the StatsPrinter class for specific options.
SyncHook<[StatsPrinter, StatsOptions]>StatsPrinter: stats printer instance, see Stats Printer Hooks for more details.StatsOptions: stats options