This section describes some of the type definitions provided by the Rsbuild.
The type of Rsbuild instance, corresponding to the return value of the createRsbuild method.
import type { RsbuildInstance } from '@rsbuild/core';
let rsbuild: RsbuildInstance;
The type of Rsbuild configuration.
import type { RsbuildConfig } from '@rsbuild/core';
const config: RsbuildConfig = {
// ...
};
You can also import the type definitions of each field in the Rsbuild config:
import type {
DevConfig,
HtmlConfig,
ToolsConfig,
SourceConfig,
ServerConfig,
OutputConfig,
SecurityConfig,
PerformanceConfig,
ModuleFederationConfig,
} from '@rsbuild/core';
The type of Rsbuild configuration after normalization, corresponding to the return value of the getNormalizedConfig method.
import type { NormalizedConfig } from '@rsbuild/core';
const config: NormalizedConfig = api.getNormalizedConfig();
You can also import the type definitions of each field in the normalized config:
import type {
NormalizedDevConfig,
NormalizedHtmlConfig,
NormalizedToolsConfig,
NormalizedSourceConfig,
NormalizedServerConfig,
NormalizedOutputConfig,
NormalizedSecurityConfig,
NormalizedPerformanceConfig,
NormalizedModuleFederationConfig,
} from '@rsbuild/core';
The type of Rsbuild environment configuration after normalization, corresponding to the return value of the getNormalizedConfig({ environment })
method.
import type { NormalizedEnvironmentConfig } from '@rsbuild/core';
const config: NormalizedEnvironmentConfig = api.getNormalizedConfig({
environment,
});
The type of the context property in the Rsbuild instance.
import type { RsbuildContext } from '@rsbuild/core';
const context: RsbuildContext = rsbuild.context;
Defines the structure and behavior of an Rsbuild plugin.
Rsbuild plugins provide a standardized way to extend build functionality through lifecycle hooks and configuration modifications.
import type { RsbuildPlugin } from '@rsbuild/core';
const myPlugin: RsbuildPlugin = {
name: 'my-plugin',
setup() {},
};
The API interface that Rsbuild exposes to plugins through the setup
function.
It allows plugins to interact with the build process, modify configurations, register hooks, and access context information.
import type { RsbuildPluginAPI } from '@rsbuild/core';
const myPlugin = {
name: 'my-plugin',
setup(api: RsbuildPluginAPI) {},
};
The type of build target.
import type { RsbuildTarget } from '@rsbuild/core';
The param type of createRsbuild method.
import type { CreateRsbuildOptions } from '@rsbuild/core';
The param type of rsbuild.inspectConfig method.
import type { InspectConfigOptions } from '@rsbuild/core';
Includes all types exported by @rspack/core
, such as Rspack.Configuration
.
import type { Rspack } from '@rsbuild/core';
const rspackConfig: Rspack.Configuration = {};
See @rsbuild/core - src/index.ts for all exported types.