Low-level plugins
These plugins are publicly exposed low-level building blocks that Rspack primarily uses to implement target presets, runtime templates, child compilers, and higher-level plugins.
For most application builds, prefer the corresponding high-level configuration. Direct use is mainly intended for custom compilers, child compilers, and advanced integrations.
Categories of low-level plugins:
environment
Plugins affecting the compiler environment and runtime target.
ElectronTargetPlugin
ElectronTargetPlugin keeps Electron built-in modules external so Electron can load them at runtime. Pass 'main', 'preload', or 'renderer' to externalize the additional modules available in that process.
The externalsPresets.electron, externalsPresets.electronMain, externalsPresets.electronRenderer, and externalsPresets.electronPreload options apply this plugin internally.
For a regular Electron application, prefer the corresponding target:
When configuring a child compiler directly, apply the plugin to that compiler:
NodeEnvironmentPlugin
NodeEnvironmentPlugin installs infrastructure logging, a cached Node.js input file system, the Node.js fs module as the output file system, and a watch file system on a compiler. The rspack() API applies it automatically to the root compiler.
When a custom compiler needs its own Node.js file-system environment, pass its normalized infrastructure logging options and apply the plugin directly:
This plugin configures compiler I/O and logging; it does not set the JavaScript runtime target. Use NodeTargetPlugin when Node.js built-in modules should remain external.
NodeTargetPlugin
NodeTargetPlugin keeps Node.js built-in modules and requests using the node: scheme external so the Node.js runtime loads them instead of Rspack bundling them. The externalsPresets.node option applies this plugin internally.
For a regular Node.js application, prefer the node target:
When configuring a child compiler directly, apply the plugin to that compiler:
entry
Plugins that add entry chunks to the compilation.
DynamicEntryPlugin
DynamicEntryPlugin calls an entry function during every make event and adds the returned entries to the compilation. This allows the entry list to change between watch rebuilds.
The direct API receives normalized entry descriptions, so each import value is an array:
For a regular build, prefer an entry function, which Rspack normalizes and passes to this plugin automatically.
EntryOptionPlugin
EntryOptionPlugin handles the entryOption compiler hook. It applies an EntryPlugin for each static entry request or a DynamicEntryPlugin for a function entry. Rspack applies it automatically to the root compiler.
The static applyEntryOption helper is useful when adding normalized entries to a child compiler:
output
Plugins affecting generated modules, chunks, and runtime loading.
EnableChunkLoadingPlugin
EnableChunkLoadingPlugin enables the runtime modules required by a chunk-loading type. Rspack normally applies it for the types collected in output.enabledChunkLoadingTypes.
The supported built-in types are 'jsonp', 'import-scripts', 'require', 'async-node', and 'import'.
Direct application is useful when a dynamic entry selects a type that Rspack cannot discover while normalizing the configuration:
For a custom chunk-loading implementation, call EnableChunkLoadingPlugin.setEnabled(compiler, type) after installing its runtime hooks. This method only registers the type; it does not implement chunk loading.
EnableLibraryPlugin
EnableLibraryPlugin registers a library output type with the compiler. Rspack normally applies it for the types collected in output.enabledLibraryTypes.
The following dynamic entry selects the 'var' library type and enables it explicitly because Rspack cannot inspect a function entry during configuration normalization:
For a regular library build, prefer output.library, which automatically enables its library type.
EnableWasmLoadingPlugin
EnableWasmLoadingPlugin enables the runtime modules required by a WebAssembly loading type. Rspack normally applies it for the types collected in output.enabledWasmLoadingTypes.
The supported types are 'fetch', 'async-node', and 'universal'.
The following example sets output.wasmLoading to false to disable automatic setup, then directly applies EnableWasmLoadingPlugin to install the 'fetch' loading runtime:
For a regular build, prefer output.wasmLoading, which automatically enables the selected type.
EvalDevToolModulePlugin
EvalDevToolModulePlugin wraps each non-external JavaScript module in eval and appends a sourceURL, allowing browser developer tools to display the original module name. Setting devtool: 'eval' applies this plugin automatically.
The following configuration applies it directly and uses dashboard as the source URL namespace:
The moduleFilenameTemplate and sourceUrlComment options can customize the generated module URL and comment format.
FetchCompileAsyncWasmPlugin
FetchCompileAsyncWasmPlugin adds the browser runtime that fetches and compiles asynchronous WebAssembly modules. EnableWasmLoadingPlugin('fetch') applies this implementation internally.
This example disables automatic WebAssembly loading setup and installs the fetch implementation directly:
For a regular web build, prefer output.wasmLoading: 'fetch', which enables the same runtime automatically.
JsonpTemplatePlugin
JsonpTemplatePlugin configures browser output for child compilers. It sets output.chunkLoading to 'jsonp', applies the 'array-push' chunk format, and enables the required JSONP chunk-loading runtime.
The following browser entry creates an asynchronous chunk:
This configuration creates a child compiler and applies JsonpTemplatePlugin directly:
JsonpTemplatePlugin makes the child compiler emit array-push chunks and load asynchronous chunks by adding script elements to the page.
For a regular web build, prefer target: 'web'. It selects the 'array-push' chunk format and 'jsonp' chunk loading through Rspack's target defaults. Setting output.chunkLoading: 'jsonp' only selects the loading implementation; it does not apply JsonpTemplatePlugin or choose the chunk format.
NodeTemplatePlugin
NodeTemplatePlugin configures Node.js output for child compilers. It applies the 'commonjs' chunk format, sets output.chunkLoading to 'require' by default, and enables the required chunk-loading runtime.
asyncChunkLoading
- Type:
boolean - Default:
false
When asyncChunkLoading is true, the plugin uses 'async-node' chunk loading instead of 'require'.
The following Node.js entry creates an asynchronous chunk:
This configuration creates a child compiler and applies NodeTemplatePlugin directly:
NodeTemplatePlugin makes the child compiler emit CommonJS chunks and load asynchronous chunks with require.
For a regular Node.js build, prefer target: 'node'. It selects the 'commonjs' chunk format and 'require' chunk loading through Rspack's target defaults. Setting output.chunkLoading: 'require' only selects the loading implementation; it does not apply NodeTemplatePlugin or choose the chunk format.
WebWorkerTemplatePlugin
WebWorkerTemplatePlugin configures Web Worker output for child compilers. It sets output.chunkLoading to 'import-scripts', applies the 'array-push' chunk format, and enables the required importScripts chunk-loading runtime.
The following worker creates an asynchronous chunk:
This configuration creates a child compiler and applies WebWorkerTemplatePlugin directly:
WebWorkerTemplatePlugin makes the child compiler emit array-push chunks and load asynchronous chunks with importScripts.
For a regular Web Worker build, prefer target: 'webworker'. It selects the 'array-push' chunk format and 'import-scripts' chunk loading through Rspack's target defaults. Setting output.chunkLoading: 'import-scripts' only selects the loading implementation; it does not apply WebWorkerTemplatePlugin or choose the chunk format.
loader
Plugins that customize the context in which loaders execute.
LoaderOptionsPlugin
LoaderOptionsPlugin copies custom option fields onto the loader context for resources matching test, include, and exclude. The matching fields themselves are used only as filters and are not copied.
This loader reads a custom message property from its context:
The plugin provides that property only while processing .message files:
This plugin mainly supports loaders that read custom properties from this. New loaders should usually receive values through their own loader options.
LoaderTargetPlugin
LoaderTargetPlugin assigns target to this.target in every loader context. It is useful when a custom compiler needs loaders to observe a target that differs from the compiler's configured target.
The following loader replaces its input with the target it observes:
Although the build target is web, this plugin makes the loader receive 'node':
For a regular build, prefer the top-level target option.
module federation
These plugins implement the exposes, remotes, and shared parts of Module Federation. For regular application builds, prefer ModuleFederationPlugin, which configures these low-level plugins together.
ContainerPlugin
ContainerPlugin creates a container entry that exposes local modules through the Module Federation get and init interface. It is the low-level implementation of the exposes option.
This configuration emits remoteEntry.js and exposes src/Button.js as ./Button:
ContainerReferencePlugin
ContainerReferencePlugin registers remote containers as externals and adds the runtime needed to load modules from them. It is the low-level implementation of the remotes option.
With the following configuration, an import such as import('catalog/Button') loads ./Button from the remote container:
ConsumeSharedPlugin
ConsumeSharedPlugin resolves configured module requests from a share scope. It can enforce version and singleton requirements and use a local module as a fallback when no suitable provider is available.
This example consumes react as a singleton from the default share scope and falls back to the locally installed package without checking its version:
ProvideSharedPlugin
ProvideSharedPlugin registers local modules and their versions in a share scope so other builds can consume them. It is the provider half of the shared option.
The shorthand form below provides the locally installed react package under the react share key and infers its version from the package metadata:
SharePlugin
SharePlugin applies both ConsumeSharedPlugin and ProvideSharedPlugin for the same shared configuration. It is the low-level equivalent of ModuleFederationPlugin's shared option.
This example provides the local react package as a fallback and consumes a singleton instance from the default share scope:
TreeShakingSharedPlugin
TreeShakingSharedPlugin creates independent builds and optimizes exports for Module Federation shared dependencies. ModuleFederationPlugin applies it automatically when at least one shared dependency enables treeShaking.
Options
mfConfig: TheModuleFederationPluginOptionsused to configure the shared dependencies and output.secondary: Whether to perform a second tree-shaking pass during the independent build. The default isfalse.onBuildAssets: A callback invoked with the generated shared fallback assets.
Direct application is mainly intended for deployment integrations that perform a secondary build. It must be combined with a sharing plugin so TreeShakingSharedPlugin can collect the shared modules to build:
The plugin creates an independent build only for shared dependencies that enable treeShaking and retain a local implementation. Direct use does not generate Module Federation stats or manifest files. When ModuleFederationPlugin applies it internally with manifest generation enabled, the plugin writes the generated fallback asset information into those files.
experiments
RemoveDuplicateModulesPlugin
RemoveDuplicateModulesPlugin finds modules that occur in the same set of multiple chunks and moves them into one reusable or newly created shared chunk. Rspack uses it internally for modern-module library output.
In this example, both entries import the same src/shared.js module. Disabling splitChunks makes RemoveDuplicateModulesPlugin responsible for extracting that duplicated module:
This page is adapted from webpack documentation under the CC BY 4.0, with modifications.

