close

JavaScript API

Rslib provides a comprehensive JavaScript API for developers to directly use Rslib's capabilities in JavaScript or TypeScript code.

Rslib's JavaScript API can be used in Node.js, Deno, or Bun.

Version requirements

v0.19.0 and above.

Getting started

This basic example demonstrates how to use the Rslib JavaScript API.

1. Install Rslib

Install the @rslib/core package:

npm
yarn
pnpm
bun
deno
npm add @rslib/core -D

2. Create an Rslib instance

Call the createRslib method to create an Rslib instance:

import { createRslib } from '@rslib/core';

const rslib = await createRslib();

The createRslib method accepts various options. Learn more in the API - createRslib documentation.

3. Call Rslib instance methods

The Rslib instance provides several methods for different scenarios.

For example, when building the output, use the rslib.build method which will build production outputs:

await rslib.build();
Tip

For more information about Rslib instance methods, see the Rslib instance documentation.

These three steps cover the basic usage of Rslib. Next, you can customize the build process with Rslib configurations and Rsbuild plugins.

Export formats

Rslib only supports ES Modules formats:

index.mjs
import { createRslib } from '@rslib/core';