Skip to content

Commit

Permalink
fix: allow environment option of createRsbuild to be an empty arr…
Browse files Browse the repository at this point in the history
…ay (#4283)
  • Loading branch information
chenjiahan authored Dec 27, 2024
1 parent 540eaca commit 4b02eaa
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/core/src/createContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -202,6 +207,6 @@ export async function createContext(
hooks: initHooks(),
config: { ...rsbuildConfig },
originalConfig: userConfig,
specifiedEnvironments: options.environment,
specifiedEnvironments,
};
}
2 changes: 2 additions & 0 deletions packages/core/src/types/rsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
/**
Expand Down
2 changes: 1 addition & 1 deletion website/docs/en/api/javascript-api/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion website/docs/zh/api/javascript-api/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type CreateRsbuildOptions = {
```

- `cwd`:当前执行构建的根路径,默认值为 `process.cwd()`
- `environment`:只构建指定的 [environments](/guide/advanced/environments)
- `environment`:只构建指定的 [environments](/guide/advanced/environments),如果未指定或传入空数组,则构建所有环境
- `rsbuildConfig`:Rsbuild 配置对象。参考 [配置总览](/config/) 查看所有可用的配置项。

## loadConfig
Expand Down

0 comments on commit 4b02eaa

Please sign in to comment.