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".
buildModule
Triggered before a module build has started。
SyncHook<[Module]>
Module
: module instanceexecuteModule
If 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 modulesucceedModule
Executed when a module has been built successfully.
SyncHook<[Module]>
Module
: module instancefinishModules
Called when all modules have been built without errors.
AsyncSeriesHook<[Module[]]>
Module[]
: List of module instancesoptimizeModules
Called at the beginning of the module optimization phase.
SyncBailHook<[Module[]]>
Module[]
: list of module instancesafterOptimizeModules
Called after modules optimization has completed.
SyncBailHook<[Module[]]>
Module[]
: list of module instancesoptimizeTree
Called before optimizing the dependency tree.
AsyncSeriesHook<[Chunk[], Module[]]>
Chunk[]
: list of chunk instancesModule[]
: list of module instancesoptimizeChunkModules
Called after the tree optimization, at the beginning of the chunk modules optimization.
AsyncSeriesBailHook<[Chunk[], Module[]]>
Chunk[]
: list of chunk instancesModule[]
: list of module instancesadditionalTreeRuntimeRequirements
Called after the tree runtime requirements collection.
SyncHook<[Chunk, Set<RuntimeGlobals>]>
Chunk
: chunk instanceSet<RuntimeGlobals>
: runtime requirementsruntimeModule
Called after a runtime module is added into the compilation.
SyncHook<[RuntimeModule, Chunk]>
RuntimeModule
: runtime module instanceChunk
: chunk instanceprocessAssets
Process the assets before emit.
AsyncSeriesHook<Assets>
Assets
: list of asset instancesafterProcessAssets
Called after the processAssets hook had finished without error.
SyncHook<Assets>
Assets
: list of asset instancesafterSeal
Called after the seal phase.
AsyncSeriesHook<[]>
chunkHash
Triggered to emit the hash for each chunk.
SyncHook<[Chunk, Hash]>
Chunk
: chunk instanceHash
: chunk hash instancechunkAsset
Triggered when an asset from a chunk was added to the compilation.
SyncHook<[Chunk, string]>
Chunk
: chunk instancestring
: asset filenamechildCompiler
Executed after setting up a child compiler.
SyncHook<[Compiler, string, number]>
Compiler
: child compiler instancestring
: child compiler namenumber
: child compiler indexstatsPreset
This 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
.
statsNormalize
This 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.
statsFactory
This 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 optionsstatsPrinter
This 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