Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions website/docs/en/api/javascript-api/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createRsbuild(
import { createRsbuild } from '@rsbuild/core';

const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
// Rsbuild configuration
},
});
Expand All @@ -36,25 +36,29 @@ type CreateRsbuildOptions = {
callerName?: string;
environment?: string[];
loadEnv?: boolean | LoadEnvOptions;
rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
config?: RsbuildConfig | (() => Promise<RsbuildConfig>);
};
```

- `cwd`: The root path of the current build, defaults to `process.cwd()`.
- `callerName`: The name of the framework or tool currently invoking Rsbuild, defaults to `'rsbuild'`, see [Specify caller name](#specify-caller-name).
- `environment`: Build only specified [environments](/guide/advanced/environments). If not specified or an empty array is passed, all environments will be built.
- `loadEnv`:Whether to call the [loadEnv](/api/javascript-api/core#loadenv) method to load environment variables and define them as global variables via [source.define](/config/source/define).
- `rsbuildConfig`: Rsbuild configuration object. Refer to [Configuration Overview](/config/) for all available configuration options.
- `config`: Rsbuild configuration object. Refer to [Configuration Overview](/config/) for all available configuration options.

:::tip
`config` was introduced in Rsbuild 1.6. In earlier versions, use `rsbuildConfig` as an alternative.
:::

### Load configuration async

`rsbuildConfig` can also be an async function for dynamically loading Rsbuild configuration and performing custom operations.
`config` can also be an async function for dynamically loading Rsbuild configuration and performing custom operations.

```ts
import { createRsbuild, loadConfig } from '@rsbuild/core';

const rsbuild = await createRsbuild({
rsbuildConfig: async () => {
config: async () => {
const { content } = await loadConfig();
someFunctionToUpdateConfig(content);
return content;
Expand Down Expand Up @@ -98,7 +102,7 @@ import { myPlugin } from './myPlugin';

const rsbuild = await createRsbuild({
callerName: 'rslib',
rsbuildConfig: {
config: {
plugins: [myPlugin],
},
});
Expand Down Expand Up @@ -151,7 +155,7 @@ const { content } = await loadConfig();
console.log(content); // -> Rsbuild config object

const rsbuild = await createRsbuild({
rsbuildConfig: content,
config: content,
});
```

Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/api/javascript-api/dev-server-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import express from 'express';
async function startDevServer() {
// Init Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
4 changes: 2 additions & 2 deletions website/docs/en/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ const pluginFoo = {
};

const rsbuild = createRsbuild({
rsbuildConfig: {
config: {
plugins: [pluginFoo],
},
});
Expand All @@ -595,7 +595,7 @@ Or check if a plugin exists in a specified environment:

```ts
const rsbuild = createRsbuild({
rsbuildConfig: {
config: {
environments: {
web: {
plugins: [pluginFoo],
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/community/releases/v0-5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { createRsbuild } from '@rsbuild/core';
async function startCustomServer() {
const app = express();
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/config/server/middleware-mode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import express from 'express';
async function startDevServer() {
// Initialize Rsbuild in middleware mode
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/guide/advanced/environments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export async function startDevServer() {

// Init Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: content,
config: content,
});

const app = express();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/guide/advanced/ssr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import { createRsbuild } from '@rsbuild/core';

async function initRsbuild() {
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
18 changes: 11 additions & 7 deletions website/docs/zh/api/javascript-api/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function createRsbuild(
import { createRsbuild } from '@rsbuild/core';

const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
// Rsbuild configuration
},
});
Expand All @@ -36,25 +36,29 @@ type CreateRsbuildOptions = {
callerName?: string;
environment?: string[];
loadEnv?: boolean | LoadEnvOptions;
rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
config?: RsbuildConfig | (() => Promise<RsbuildConfig>);
};
```

- `cwd`:当前执行构建的根路径,默认值为 `process.cwd()`
- `callerName`:当前调用者的名称,默认值为 `'rsbuild'`,详见 [指定调用者名称](#指定调用者名称)。
- `environment`:只构建指定的 [environments](/guide/advanced/environments),如果未指定或传入空数组,则构建所有环境。
- `loadEnv`:是否调用 [loadEnv](/api/javascript-api/core#loadenv) 方法来加载环境变量,并通过 [source.define](/config/source/define) 定义为全局变量。
- `rsbuildConfig`:Rsbuild 配置对象。参考 [配置总览](/config/) 查看所有可用的配置项。
- `config`:Rsbuild 配置对象。参考 [配置总览](/config/) 查看所有可用的配置项。

:::tip
`config` 是 Rsbuild 1.6 新增的选项。在旧版本中,可使用 `rsbuildConfig` 作为替代。
:::

### 异步加载配置

`rsbuildConfig` 也可以是一个异步函数,你可以通过该函数来动态加载 Rsbuild 配置,并进行一些自定义操作。
`config` 也可以是一个异步函数,你可以通过该函数来动态加载 Rsbuild 配置,并进行一些自定义操作。

```ts
import { createRsbuild, loadConfig } from '@rsbuild/core';

const rsbuild = await createRsbuild({
rsbuildConfig: async () => {
config: async () => {
const { content } = await loadConfig();
someFunctionToUpdateConfig(content);
return content;
Expand Down Expand Up @@ -98,7 +102,7 @@ import { myPlugin } from './myPlugin';

const rsbuild = await createRsbuild({
callerName: 'rslib',
rsbuildConfig: {
config: {
plugins: [myPlugin],
},
});
Expand Down Expand Up @@ -151,7 +155,7 @@ const { content } = await loadConfig();
console.log(content); // -> Rsbuild config object

const rsbuild = await createRsbuild({
rsbuildConfig: content,
config: content,
});
```

Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/api/javascript-api/dev-server-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import express from 'express';
async function startDevServer() {
// 初始化 Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
4 changes: 2 additions & 2 deletions website/docs/zh/api/javascript-api/instance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ const pluginFoo = {
};

const rsbuild = createRsbuild({
rsbuildConfig: {
config: {
plugins: [pluginFoo],
},
});
Expand All @@ -618,7 +618,7 @@ rsbuild.isPluginExists(pluginFoo.name); // true

```ts
const rsbuild = createRsbuild({
rsbuildConfig: {
config: {
environments: {
web: {
plugins: [pluginFoo],
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/community/releases/v0-5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { createRsbuild } from '@rsbuild/core';
async function startCustomServer() {
const app = express();
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/config/server/middleware-mode.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import express from 'express';
async function startDevServer() {
// 以 middleware mode 初始化 Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/advanced/environments.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ export async function startDevServer() {

// Init Rsbuild
const rsbuild = await createRsbuild({
rsbuildConfig: content,
config: content,
});

const app = express();
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/guide/advanced/ssr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import { createRsbuild } from '@rsbuild/core';

async function initRsbuild() {
const rsbuild = await createRsbuild({
rsbuildConfig: {
config: {
server: {
middlewareMode: true,
},
Expand Down
Loading