Rsbuild provides a comprehensive JavaScript API for developers to build higher-level tools or frameworks on top of Rsbuild.
Rsbuild's JavaScript API can be used in Node.js, Deno, or Bun.
This basic example demonstrates how to use the Rsbuild JavaScript API.
Install the @rsbuild/core
package:
npm add @rsbuild/core -D
Call the createRsbuild method to create an Rsbuild instance:
import { createRsbuild } from '@rsbuild/core';
const rsbuild = await createRsbuild();
The createRsbuild
method accepts various options. Learn more in the API - createRsbuild documentation.
The Rsbuild instance provides several methods for different scenarios.
For local development, use the rsbuild.startDevServer method to start a local dev server:
await rsbuild.startDevServer();
Once the dev server starts successfully, these logs will appear:
➜ Local: http://localhost:3000
➜ Network: http://192.168.0.1:3000
For production deployment, use the rsbuild.build method to build production outputs:
await rsbuild.build();
For more information about Rsbuild instance methods, see the Rsbuild Instance documentation.
These three steps cover the basic usage of Rsbuild. Next, you can customize the build process with Rsbuild plugins and configurations.
Rsbuild supports both ES Modules and CommonJS formats:
import { createRsbuild } from '@rsbuild/core';
const { createRsbuild } = require('@rsbuild/core');
We recommend using ES modules, which align better with community standards.