CC 4.0 License
The content of this section is derived from the content of the following links and is subject to the CC BY 4.0 license.
The following contents can be assumed to be the result of modifications and deletions based on the original contents if not specifically stated.
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
electron.ElectronTargetPlugin(context)
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
node.NodeEnvironmentPlugin()
Applies a Node.js-style filesystem to the compiler.
NodeTargetPlugin
node.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(context, entry)
Similar to EntryPlugin but accepts a function as the entry argument. This function is called during each make event to determine the entry points dynamically.
EntryOptionPlugin
EntryOptionPlugin()
output
Plugins affecting generated modules, chunks, and runtime loading.
EnableChunkLoadingPlugin
javascript.EnableChunkLoadingPlugin(type)
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
library.EnableLibraryPlugin(type)
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
wasm.EnableWasmLoadingPlugin(type)
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(options)
Decorates the module template by wrapping each module in an eval annotated with // @sourceURL.
FetchCompileAsyncWasmPlugin
web.FetchCompileAsyncWasmPlugin()
Provides runtime code for fetching and compiling asynchronous WebAssembly modules, and is often used with a child compiler.
JsonpTemplatePlugin
web.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
node.NodeTemplatePlugin(options)
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
webworker.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
LoaderOptionsPlugin
LoaderOptionsPlugin(options)
LoaderTargetPlugin
LoaderTargetPlugin(target)
module federation
Low-level plugins used by ModuleFederationPlugin.
ContainerPlugin
container.ContainerPlugin(options)
ContainerReferencePlugin
container.ContainerReferencePlugin(options)
ConsumeSharedPlugin
sharing.ConsumeSharedPlugin(options)
ProvideSharedPlugin
sharing.ProvideSharedPlugin(options)
SharePlugin
sharing.SharePlugin(options)
TreeShakingSharedPlugin
sharing.TreeShakingSharedPlugin(options)
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 after collecting complete dependency information:
The plugin creates an independent build only for shared dependencies that enable treeShaking and retain a local implementation. When mfConfig.manifest is enabled, it records the generated fallback assets in the stats and manifest.
experiments
RemoveDuplicateModulesPlugin
experiments.RemoveDuplicateModulesPlugin()

