API Reference

Rspack

Rust-based bundler with a webpack-compatible API that delivers fast cold starts and incremental builds for large applications.

Official Documentation ↗
CompatibilityThis documentation covers version v2.3.1. Check the official docs for the latest API surface.

Installation

npmnpm install --save-dev @rspack/core
pnpmpnpm add -D @rspack/core

Methods

Overview

Rspack is a Rust-based bundler that reuses the webpack configuration and plugin model while providing much faster cold and incremental builds. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.

Core APIs

  • rspack — Creates a Compiler from a webpack-style configuration object.
  • compiler.run — Executes one compilation and reports stats through the callback.
  • compiler.watch — Enables incremental rebuilds on file changes with a watch handle.

Example

const { rspack } = require('@rspack/core');

const compiler = rspack({
  entry: './src/index.js',
  output: { path: __dirname + '/dist' },
});

Notes

Most webpack configuration maps directly, but some community loaders have no native equivalent yet. Validate plugin compatibility early when migrating.

Verification

Run one compile and then watch a source edit, confirming incremental rebuild latency is far below a full build.

Errors

The following points are quoted verbatim from the official documentation. 来源:https://rspack.dev/api/javascript-api/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:52:17.619Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.

FAQ

Is the Rspack config the same as webpack?
Rspack implements a largely webpack-compatible configuration and plugin interface, but a few loaders and plugins still need native Rspack equivalents.
Which built-in plugins ship with @rspack/core?
Common ones such as HtmlRspackPlugin, DefinePlugin, and CopyRspackPlugin are exported directly from @rspack/core.
How do I migrate an existing webpack config?
Swap the webpack import for @rspack/core, then replace unsupported loaders; the CLI and most options map one to one.