JavaScript API

Rsbuild provides a complete set of JavaScript APIs for developers to build higher level solutions on top of Rsbuild.

Access Example

Here is a basic example of how to access the Rsbuild JavaScript API.

1. Install Rsbuild

You need to install the @rsbuild/core package:

npm add @rsbuild/core -D

2. Create an Rsbuild Instance

You can call the createRsbuild method to create an Rsbuild instance:

import { createRsbuild } from '@rsbuild/core';

const rsbuild = await createRsbuild();

The createRsbuild method provides some options, which you can learn more about in the API - createRsbuild.

3. Call Rsbuild Instance Method

The Rsbuild instance provides some methods, which you can use it according to the usage scenarios.

To start local development, it is recommended to use the rsbuild.startDevServer method, which will start a local Dev Server.

await rsbuild.startDevServer();

After successfully starting Dev Server, you can see the following logs:

> Local:    http://localhost:8081
  > Network:

To deploy the App to production environment, it is recommended to use the method, which will build the production outputs.


For more introduction of Rsbuild instance methods, please read the Rsbuild Instance chapter.

After completing the above three steps, you have learned the basic usage of Rsbuild. Next, you can customize the build process through the Rsbuild plugin and Rsbuild configs.