Skip to content

Commit

Permalink
fix: set default command for createCompiler() (#4254)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Dec 24, 2024
1 parent 0ac2db1 commit 7a45ffd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/core/src/createRsbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { rspackProvider } from './provider/provider';
import { startProdServer } from './server/prodServer';
import type {
Build,
CreateCompiler,
CreateDevServer,
CreateRsbuildOptions,
Falsy,
Expand Down Expand Up @@ -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',
Expand All @@ -240,11 +249,7 @@ export async function createRsbuild(
'getRsbuildConfig',
'getNormalizedConfig',
]),
...pick(providerInstance, [
'initConfigs',
'inspectConfig',
'createCompiler',
]),
...pick(providerInstance, ['initConfigs', 'inspectConfig']),
};

const getFlattenedPlugins = async (pluginOptions: RsbuildPlugins) => {
Expand Down

0 comments on commit 7a45ffd

Please sign in to comment.