From 3aa6750d736d1010e9db18b97db0e3514975cd96 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 24 Dec 2024 13:17:23 +0800 Subject: [PATCH] fix: set default command for `createCompiler()` --- packages/core/src/createRsbuild.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/core/src/createRsbuild.ts b/packages/core/src/createRsbuild.ts index 3db9b27579..2a61b66aa6 100644 --- a/packages/core/src/createRsbuild.ts +++ b/packages/core/src/createRsbuild.ts @@ -44,6 +44,7 @@ import { rspackProvider } from './provider/provider'; import { startProdServer } from './server/prodServer'; import type { Build, + CreateCompiler, CreateDevServer, CreateRsbuildOptions, Falsy, @@ -212,10 +213,18 @@ export async function createRsbuild( return providerInstance.createDevServer(...args); }; + const createCompiler: CreateCompiler = (...args) => { + if (!context.command) { + context.command = getNodeEnv() === 'development' ? 'dev' : 'build'; + } + return providerInstance.createCompiler(...args); + }; + const rsbuild = { build, preview, startDevServer, + createCompiler, createDevServer, ...pick(pluginManager, [ 'addPlugins', @@ -240,11 +249,7 @@ export async function createRsbuild( 'getRsbuildConfig', 'getNormalizedConfig', ]), - ...pick(providerInstance, [ - 'initConfigs', - 'inspectConfig', - 'createCompiler', - ]), + ...pick(providerInstance, ['initConfigs', 'inspectConfig']), }; const getFlattenedPlugins = async (pluginOptions: RsbuildPlugins) => {