Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow environment option of createRsbuild to be an empty array #4283

Merged
merged 1 commit into from
Dec 27, 2024
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
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
Loading