Rsbuild Core

This section describes some of the core methods provided by Rsbuild.

createRsbuild

Create a Rsbuild instance object.

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

const rsbuild = await createRsbuild({
  // options
});

options

The first parameter of createRsbuild is a options object, you can pass in the following options:

type RsbuildEntry = Record<string, string | string[]>;

type RsbuildTarget = 'web' | 'node' | 'web-worker';

type CreateRsbuildOptions = {
  cwd?: string;
  target?: RsbuildTarget | RsbuildTarget[];
  provider?: RsbuildProvider;
  configPath?: string | null;
  rsbuildConfig?: RsbuildConfig;
};

Description:

  • cwd: The root path of the current build, the default value is process.cwd().
  • target: Build target type, the default value is ['web'], see chapter Build Target for details.
  • configPath: The path to the config file of higher-level solution (absolute path), this parameter affects the build cache update.
  • provider: Used to switch the underlying bundler.
  • rsbuildConfig: Rsbuild configuration object. Rsbuild provides a rich set of configuration options that allow you to customize the build behavior flexibly. You can find all available configuration options in the Configuration section.

mergeRsbuildConfig

Used to merge multiple Rsbuild configuration objects.

The mergeRsbuildConfig function takes multiple configuration objects as parameters. It deep merges each configuration object, automatically combining multiple function values into an array of sequentially executed functions, and returns a merged configuration object.

  • Type
function mergeRsbuildConfig(...configs: RsbuildConfig[]): RsbuildConfig;
  • Example
import { mergeRsbuildConfig } from '@rsbuild/core';

const config1 = {
  dev: {
    https: false,
  },
};
const config2 = {
  dev: {
    https: true,
  },
};

const mergedConfig = mergeRsbuildConfig(config1, config2);

console.log(mergedConfig); // { dev: { https: true } }

This method will not modify the config object in the input parameter.