Skip to content

Commit 1925eeb

Browse files
committed
feat: builder.entireApp, remove --environment
1 parent a63190c commit 1925eeb

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

packages/vite/src/node/build.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,6 +1400,7 @@ export interface ViteBuilder {
14001400
export interface BuilderOptions {
14011401
sharedConfigBuild?: boolean
14021402
sharedPlugins?: boolean
1403+
entireApp?: boolean
14031404
buildApp?: (builder: ViteBuilder) => Promise<void>
14041405
}
14051406

@@ -1415,6 +1416,7 @@ export function resolveBuilderOptions(
14151416
return {
14161417
sharedConfigBuild: options.sharedConfigBuild ?? false,
14171418
sharedPlugins: options.sharedPlugins ?? false,
1419+
entireApp: options.entireApp ?? false,
14181420
buildApp: options.buildApp ?? defaultBuildApp,
14191421
}
14201422
}

packages/vite/src/node/cli.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ interface GlobalCLIOptions {
3131
}
3232

3333
interface BuilderCLIOptions {
34-
environment?: string
3534
app?: boolean
3635
}
3736

@@ -113,9 +112,7 @@ function cleanBuilderCLIOptions<Options extends BuilderCLIOptions>(
113112
options: Options,
114113
): Omit<Options, keyof BuilderCLIOptions> {
115114
const ret = { ...options }
116-
delete ret.environment
117115
delete ret.app
118-
119116
return ret
120117
}
121118

@@ -281,14 +278,14 @@ cli
281278
)
282279
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
283280
.option('--environment [name]', `[string] build a single environment`)
284-
.option('--app', `[boolean] build all the environments`)
281+
.option('--app', `[boolean] same as builder.entireApp`)
285282
.action(
286283
async (
287284
root: string,
288285
options: BuildEnvironmentOptions & BuilderCLIOptions & GlobalCLIOptions,
289286
) => {
290287
filterDuplicateOptions(options)
291-
const { build, createBuilder } = await import('./build')
288+
const { createBuilder, buildEnvironment } = await import('./build')
292289

293290
const buildOptions: BuildEnvironmentOptions = cleanGlobalCLIOptions(
294291
cleanBuilderCLIOptions(options),
@@ -305,22 +302,21 @@ cli
305302
}
306303

307304
try {
308-
if (options.app || options.environment) {
309-
const builder = await createBuilder(config)
310-
if (options.environment) {
311-
const environment = builder.environments[options.environment]
312-
if (!environment) {
313-
throw new Error(
314-
`The environment ${options.environment} isn't configured.`,
315-
)
316-
}
317-
await builder.build(environment)
318-
} else {
319-
// --app: build all environments
320-
await builder.buildApp()
321-
}
305+
const builder = await createBuilder(config)
306+
// TODO: Backward compatibility with lib and single environment build
307+
// Ideally we would move to only building the entire app with this command
308+
if (builder.config.build.lib) {
309+
await buildEnvironment(
310+
builder.config,
311+
builder.environments.client,
312+
builder.config.build.lib,
313+
)
314+
} else if (builder.config.builder.entireApp || options.app) {
315+
await builder.buildApp()
322316
} else {
323-
await build(config)
317+
const ssr = !!builder.config.build.ssr
318+
const environment = builder.environments[ssr ? 'ssr' : 'client']
319+
await builder.build(environment)
324320
}
325321
} catch (e) {
326322
createLogger(options.logLevel).error(

0 commit comments

Comments
 (0)