Skip to content

Commit 23d085c

Browse files
committed
feat(core): simplify config option of createRsbuild
1 parent 62012e2 commit 23d085c

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

packages/core/src/cli/init.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export async function init({
101101

102102
const rsbuild = await createRsbuild({
103103
cwd: root,
104-
rsbuildConfig: () => loadConfig(root),
104+
config: () => loadConfig(root),
105105
environment: commonOpts.environment,
106106
loadEnv:
107107
commonOpts.env === false

packages/core/src/createRsbuild.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ export async function createRsbuild(
168168
})
169169
: null;
170170

171-
const config = isFunction(options.rsbuildConfig)
172-
? await options.rsbuildConfig()
173-
: options.rsbuildConfig || {};
171+
const configOrFactory = options.config ?? options.rsbuildConfig;
172+
const config = isFunction(configOrFactory)
173+
? await configOrFactory()
174+
: configOrFactory || {};
174175

175176
// debug mode should always verbose logs
176177
if (config.logLevel && !isDebug()) {

packages/core/src/types/rsbuild.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,16 @@ export type CreateRsbuildOptions = {
150150
* If not specified or passing an empty array, all environments will be built.
151151
*/
152152
environment?: string[];
153+
/**
154+
* Alias for `config`.
155+
* This option will be deprecated in the future.
156+
*/
157+
rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
153158
/**
154159
* Rsbuild configurations.
155160
* Passing a function to load the config asynchronously with custom logic.
156161
*/
157-
rsbuildConfig?: RsbuildConfig | (() => Promise<RsbuildConfig>);
162+
config?: RsbuildConfig | (() => Promise<RsbuildConfig>);
158163
/**
159164
* Whether to call `loadEnv` to load environment variables and define them
160165
* as global variables via `source.define`.

0 commit comments

Comments
 (0)