Rsbuild Types
This section describes some of the type definitions provided by the Rsbuild.
RsbuildInstance
The type of Rsbuild instance, corresponding to the return value of the createRsbuild method.
import type { RsbuildInstance } from '@rsbuild/core';
let rsbuild: RsbuildInstance;
RsbuildConfig
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';
NormalizedConfig
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';
NormalizedEnvironmentConfig
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,
});
RsbuildContext
The type of the context property in the Rsbuild instance.
import type { RsbuildContext } from '@rsbuild/core';
const context: RsbuildContext = rsbuild.context;
RsbuildPlugin
The type of Rsbuild plugin.
import type { RsbuildPlugin } from '@rsbuild/core';
const myPlugin: RsbuildPlugin = {
name: 'my-plugin',
setup() {},
};
RsbuildPluginAPI
The type of the api
object passed into the setup
function in the Rsbuild plugin.
import type { RsbuildPluginAPI } from '@rsbuild/core';
const myPlugin = {
name: 'my-plugin',
setup(api: RsbuildPluginAPI) {},
};
RsbuildTarget
The type of build target.
import type { RsbuildTarget } from '@rsbuild/core';
EnvironmentContext
Environment context is a read-only object that provides some context infos about the current environment.
type EnvironmentContext = {
name: string;
browserslist: string[];
config: NormalizedEnvironmentConfig;
distPath: string;
entry: RsbuildEntry;
htmlPaths: Record<string, string>;
tsconfigPath?: string;
};
environment.name
The unique name of the current environment is used to distinguish and locate the environment, corresponds to the key in the environments configuration.
environment.browserslist
The range of target browsers that the project is compatible with. See details in Browserslist.
environment.config
The Rsbuild environment configuration after normalization.
type NormalizedEnvironmentConfig = DeepReadonly<{
dev: NormalizedDevConfig;
html: NormalizedHtmlConfig;
tools: NormalizedToolsConfig;
source: NormalizedSourceConfig;
server: NormalizedServerConfig;
output: NormalizedOutputConfig;
plugins?: RsbuildPlugins;
security: NormalizedSecurityConfig;
performance: NormalizedPerformanceConfig;
moduleFederation?: ModuleFederationConfig;
}>;
environment.distPath
The absolute path of the output directory, corresponding to the output.distPath.root
config in RsbuildConfig
.
environment.entry
The entry object from the source.entry option.
type RsbuildEntry = Record<string, string | string[] | EntryDescription>;
environment.htmlPaths
The path information for all HTML assets.
This API will return an object, the key is the entry name and the value is the relative path of the HTML file in the dist directory.
type htmlPaths = Record<string, string>;
environment.tsconfigPath
The absolute path of the tsconfig.json file, or undefined
if the tsconfig.json file does not exist in current project.
type TsconfigPath = string | undefined;
CreateRsbuildOptions
The param type of createRsbuild method.
import type { CreateRsbuildOptions } from '@rsbuild/core';
InspectConfigOptions
The param type of rsbuild.inspectConfig method.
import type { InspectConfigOptions } from '@rsbuild/core';
Rspack
Includes all types exported by @rspack/core
, such as Rspack.Configuration
.
import type { Rspack } from '@rsbuild/core';
const rspackConfig: Rspack.Configuration = {};
Others
- OnExitFn
- OnAfterBuildFn
- OnAfterCreateCompilerFn
- OnAfterStartDevServerFn
- OnAfterStartProdServerFn
- OnBeforeBuildFn
- OnBeforeStartDevServerFn
- OnBeforeStartProdServerFn
- OnBeforeCreateCompilerFn
- OnCloseDevServerFn
- OnDevCompileDoneFn
- ModifyRsbuildConfigFn
- ModifyBundlerChainFn
- ModifyRspackConfigFn
- TransformFn,
- TransformHandler
- more...