Compiler Hooks

Overview

environment

Called while preparing the compiler environment, right after initializing the plugins in the configuration file.

  • Type: SyncHook<[]>

afterEnvironment

Called right after the environment hook, when the compiler environment setup is complete.

  • Type: SyncHook<[]>

entryOption

Called after the entry configuration from Rspack options has been processed.

  • Type: SyncBailHook<[string, EntryNormalized]>
  • Arguments:
    • string: same with context
    • EntryNormalized: normalized entry

afterPlugins

Called after setting up initial set of internal plugins.

  • Type: SyncHook<[Compiler]>
  • Arguments:
    • Compiler: current compiler instance

afterResolvers

Triggered after resolver setup is complete.

  • Type: SyncHook<[Compiler]>
  • Arguments:
    • Compiler: current compiler instance

initialize

Called when a compiler object is initialized.

  • Type: SyncHook<[]>

beforeRun

Adds a hook right before running the compiler.

  • Type: AsyncSeriesHook<[Compiler]>
  • Arguments:
    • Compiler: current compiler instance

run

Called ad the beginning of a build execution.

  • Type: AsyncSeriesHook<[Compiler]>
  • Arguments:
    • Compiler: current compiler instance

watchRun

Executes a plugin during watch mode after a new compilation is triggered but before the compilation is actually started.

  • Type: AsyncSeriesHook<[Compiler]>
  • Arguments:
    • Compiler: current compiler instance

beforeCompile

Executes a plugin after compilation parameters are created.

  • Type: AsyncSeriesHook<[]>

compile

Called right after beforeCompile, before a new compilation is created.

  • Type: SyncHook<[]>

thisCompilation

Called while initializing the compilation, right before calling the compilation hook.

  • Type: SyncHook<[Compilation]>
  • Arguments:

compilation

Runs a plugin after a compilation has been created.

  • Type: SyncHook<[Compilation]>
  • Arguments:

make

Called before the make phase.

In the make phase, Rspack will build the module graph starting from the entry, and use the loader to handle each module.

  • Type: AsyncParallelHook<[Compilation]>
  • Arguments:

afterCompile

Called after the make phase and before the seal phase.

In the seal phase, Rspack will create chunk graph from the module graph and then generate the assets.

  • Type: AsyncSeriesHook<[Compilation]>
  • Arguments:

shouldEmit

Called before emitting assets. Should return a boolean telling whether to emit.

  • Type: SyncBailHook<[Compilation]>
  • Arguments:

emit

Called right before emitting assets to output dir.

  • Type: AsyncSeriesHook<[Compilation]>
  • Arguments:

afterEmit

Called after emitting assets to output directory.

  • Type: AsyncSeriesHook<[Compilation]>
  • Arguments:

done

Called when the compilation has completed.

  • Type: AsyncSeriesHook<Stats>
  • Arguments:
    • Stats: generated stats object

afterDone

Called after done hook.

  • Type: SyncHook<Stats>
  • Arguments:
    • Stats: generated stats object

failed

Called if the compilation fails.

  • Type: SyncHook<[Error]>

watchClose

Called when a watching compilation has stopped.

  • Type: SyncHook<[]>

shutdown

Called when the compiler is closing.

  • Type: AsyncSeriesHook<[]>