close

Rslib types

This section describes some of the type definitions provided by the Rslib.

RslibInstance

The type of Rslib instance, corresponding to the return value of the createRslib method.

import type { 
type RslibInstance = {
    getRslibConfig(): Readonly<RslibConfig>;
    onAfterCreateRsbuild(callback: OnAfterCreateRsbuildFn): void;
    build(options?: BuildOptions): Promise<BuildResult>;
    inspectConfig(options?: InspectConfigOptions): Promise<InspectConfigResult>;
    startMFDevServer(options?: StartMFDevServerOptions): Promise<StartServerResult>;
}
RslibInstance
} from '@rslib/core';
let
let rslib: RslibInstance
rslib
:
type RslibInstance = {
    getRslibConfig(): Readonly<RslibConfig>;
    onAfterCreateRsbuild(callback: OnAfterCreateRsbuildFn): void;
    build(options?: BuildOptions): Promise<BuildResult>;
    inspectConfig(options?: InspectConfigOptions): Promise<InspectConfigResult>;
    startMFDevServer(options?: StartMFDevServerOptions): Promise<StartServerResult>;
}
RslibInstance
;

RslibConfig

The type of Rslib configuration.

import type { RslibConfig } from '@rslib/core';

const 
const config: RslibConfig
config
: RslibConfig = {
RslibConfig.lib: LibConfig[]
lib
: [
{
LibConfig.format?: Format | undefined

Output format for the generated JavaScript files.

@defaultValue'esm'@seehttps://rslib.rs/config/lib/format
format
: 'esm',
}, ], };

You can also import the type definitions of each field in the Rslib config:

import type {
  
type AutoExternal = boolean | {
    dependencies?: boolean;
    optionalDependencies?: boolean;
    peerDependencies?: boolean;
    devDependencies?: boolean;
}
AutoExternal
,
type BannerAndFooter = {
    js?: string;
    css?: string;
    dts?: string;
}
BannerAndFooter
,
type Dts = boolean | {
    bundle?: boolean | {
        bundledPackages?: string[];
    };
    distPath?: string;
    build?: boolean;
    abortOnError?: boolean;
    autoExtension?: boolean;
    alias?: Record<string, string>;
    tsgo?: boolean;
}
Dts
,
type Format = "esm" | "cjs" | "umd" | "mf" | "iife"
Format
,
LibConfig,
type Redirect = {
    js?: JsRedirect;
    style?: StyleRedirect;
    asset?: AssetRedirect;
    dts?: DtsRedirect;
}
Redirect
,
type Shims = {
    cjs?: {
        "import.meta.url"?: boolean;
    };
    esm?: {
        __filename?: boolean;
        __dirname?: boolean;
        require?: boolean;
    };
}
Shims
,
type Syntax = EcmaScriptVersion | string[]
Syntax
,
} from '@rslib/core';

RsbuildPlugin

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 { 
type RsbuildPlugin = {
    name: string;
    apply?: RsbuildPluginApply;
    setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
    enforce?: "pre" | "post";
    pre?: string[];
    post?: string[];
    remove?: string[];
}

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.

@example
const myPlugin = (): RsbuildPlugin => ({
  name: 'my-plugin',
  setup(api) {
    api.onBeforeBuild(() => {
      console.log('Build starting...');
    });
  }
});
RsbuildPlugin
} from '@rslib/core';
const
const myPlugin: RsbuildPlugin
myPlugin
:
type RsbuildPlugin = {
    name: string;
    apply?: RsbuildPluginApply;
    setup: (api: RsbuildPluginAPI) => MaybePromise<void>;
    enforce?: "pre" | "post";
    pre?: string[];
    post?: string[];
    remove?: string[];
}

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.

@example
const myPlugin = (): RsbuildPlugin => ({
  name: 'my-plugin',
  setup(api) {
    api.onBeforeBuild(() => {
      console.log('Build starting...');
    });
  }
});
RsbuildPlugin
= {
name: string

The name of the plugin, a unique identifier.

name
: 'my-plugin',
setup: (api: RsbuildPluginAPI) => MaybePromise<void>

The setup function of the plugin, which can be an async function. This function is called once when the plugin is initialized.

@paramapi provides the context info, utility functions and lifecycle hooks.
setup
() {},
};

CreateRslibOptions

The param type of createRslib method.

import type { 
type CreateRslibOptions = {
    cwd?: string;
    config?: RslibConfig | (() => Promise<RslibConfig>);
    loadEnv?: boolean | LoadEnvOptions;
}
CreateRslibOptions
} from '@rslib/core';

BuildOptions

The param type of rslib.build method.

import type { 
type BuildOptions = CommonOptions & {
    watch?: boolean;
}
BuildOptions
} from '@rslib/core';

StartMFDevServerOptions

The param type of rslib.startMFDevServer method.

import type { 
type StartMFDevServerOptions = {
    lib?: string[];
}
StartMFDevServerOptions
} from '@rslib/core';

InspectConfigOptions

The param type of rslib.inspectConfig method.

import type { 
type InspectConfigOptions = CommonOptions & {
    mode?: RsbuildMode;
    verbose?: boolean;
    outputPath?: string;
    writeToDisk?: boolean;
}
InspectConfigOptions
} from '@rslib/core';

Rspack

Includes all types exported by @rspack/core, such as Rspack.Configuration.

import type { 
import Rspack
Rspack
} from '@rslib/core';
const
const rspackConfig: Rspack.RspackOptions
rspackConfig
:
import Rspack
Rspack
.
type Configuration = {
    name?: Rspack.Name;
    dependencies?: Rspack.Dependencies;
    extends?: string | string[];
    entry?: Rspack.Entry;
    output?: Rspack.Output;
    target?: Rspack.Target;
    mode?: Rspack.Mode;
    experiments?: Rspack.Experiments;
    externals?: Rspack.Externals;
    externalsType?: Rspack.ExternalsType;
    externalsPresets?: Rspack.ExternalsPresets;
    infrastructureLogging?: Rspack.InfrastructureLogging;
    ... 20 more ...;
    lazyCompilation?: boolean | Rspack.LazyCompilationOptions;
}

Configuration for Rspack

Configuration
= {};

Rsbuild

Includes all types exported by @rsbuild/core, such as Rsbuild.ToolsConfig.

See @rsbuild/core - src/index.ts for all exported types of Rsbuild.

import type { 
import Rsbuild
Rsbuild
} from '@rslib/core';
const
const rsbuildConfig: Rsbuild.ToolsConfig
rsbuildConfig
:
import Rsbuild
Rsbuild
.
export ToolsConfig
ToolsConfig
= {};

Others

See @rslib/core - src/index.ts for all exported types.