From 67bed171a673cb6b90b803020e37a7af81662501 Mon Sep 17 00:00:00 2001 From: neverland Date: Fri, 27 Dec 2024 20:54:22 +0800 Subject: [PATCH] fix: allow `environment` option of `createRsbuild` be an empty array --- packages/core/src/createContext.ts | 7 ++++++- packages/core/src/types/rsbuild.ts | 2 ++ website/docs/en/api/javascript-api/core.mdx | 2 +- website/docs/zh/api/javascript-api/core.mdx | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/core/src/createContext.ts b/packages/core/src/createContext.ts index 5257c9f195..2a40d574fe 100644 --- a/packages/core/src/createContext.ts +++ b/packages/core/src/createContext.ts @@ -192,6 +192,11 @@ export async function createContext( const rsbuildConfig = await withDefaultConfig(rootPath, userConfig); const cachePath = join(rootPath, 'node_modules', '.cache'); + const specifiedEnvironments = + options.environment && options.environment.length > 0 + ? options.environment + : undefined; + return { version: RSBUILD_VERSION, rootPath, @@ -202,6 +207,6 @@ export async function createContext( hooks: initHooks(), config: { ...rsbuildConfig }, originalConfig: userConfig, - specifiedEnvironments: options.environment, + specifiedEnvironments, }; } diff --git a/packages/core/src/types/rsbuild.ts b/packages/core/src/types/rsbuild.ts index 8848016682..d3eaa49b82 100644 --- a/packages/core/src/types/rsbuild.ts +++ b/packages/core/src/types/rsbuild.ts @@ -99,6 +99,8 @@ export type CreateRsbuildOptions = { cwd?: string; /** * Only build specified environments. + * For example, passing `['web']` will only build the `web` environment. + * If not specified or passing an empty array, all environments will be built. */ environment?: string[]; /** diff --git a/website/docs/en/api/javascript-api/core.mdx b/website/docs/en/api/javascript-api/core.mdx index f2d8181ee8..221a7dd434 100644 --- a/website/docs/en/api/javascript-api/core.mdx +++ b/website/docs/en/api/javascript-api/core.mdx @@ -39,7 +39,7 @@ type CreateRsbuildOptions = { ``` - `cwd`: The root path of the current build, defaults to `process.cwd()`. -- `environment`: Only build specified [environments](/guide/advanced/environments). +- `environment`: Only build specified [environments](/guide/advanced/environments). If not specified or passing an empty array, all environments will be built. - `rsbuildConfig`: Rsbuild configuration object. Refer to [Configuration Overview](/config/) for all available configuration options. ## loadConfig diff --git a/website/docs/zh/api/javascript-api/core.mdx b/website/docs/zh/api/javascript-api/core.mdx index f2cb894738..bb553f4160 100644 --- a/website/docs/zh/api/javascript-api/core.mdx +++ b/website/docs/zh/api/javascript-api/core.mdx @@ -39,7 +39,7 @@ type CreateRsbuildOptions = { ``` - `cwd`:当前执行构建的根路径,默认值为 `process.cwd()` -- `environment`:只构建指定的 [environments](/guide/advanced/environments)。 +- `environment`:只构建指定的 [environments](/guide/advanced/environments),如果未指定或传入空数组,则构建所有环境。 - `rsbuildConfig`:Rsbuild 配置对象。参考 [配置总览](/config/) 查看所有可用的配置项。 ## loadConfig