Skip to content

Commit 29dd26e

Browse files
committed
refactor: build --app
1 parent 2a3bcb3 commit 29dd26e

File tree

5 files changed

+19
-29
lines changed

5 files changed

+19
-29
lines changed

docs/guide/api-vite-environment.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -821,13 +821,14 @@ Other non-default environments can be build using `vite build --environment=name
821821
822822
## Building all environments
823823
824-
Calling `vite build --all` will instantiate a `ViteBuilder` (build-time equivalent to a `ViteDevServer`) to build all configured environments for production. By default the build of environments is run in series respecting the order of the `environments` record. A framework or user can further configure how the environments are built using:
824+
Calling `vite build --app` will instantiate a `ViteBuilder` (build-time equivalent to a `ViteDevServer`) to build all configured environments for production. By default the build of environments is run in series respecting the order of the `environments` record. A framework or user can further configure how the environments are built using:
825825
826826
```js
827827
export default {
828828
builder: {
829-
buildEnvironments: asnyc (builder) => {
830-
return Promise.all(Object.values(builder.environments).map( environment => builder.build(environment) ))
829+
buildApp: asnyc (builder) => {
830+
const environments = Object.values(builder.environments)
831+
return Promise.all(environments.map(environment => builder.build(environment)))
831832
}
832833
}
833834
}

packages/vite/src/node/build.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,33 +1394,27 @@ export class BuildEnvironment extends Environment {
13941394
export interface ViteBuilder {
13951395
environments: Record<string, BuildEnvironment>
13961396
config: ResolvedConfig
1397-
buildEnvironments(): Promise<void>
1397+
buildApp(): Promise<void>
13981398
build(
13991399
environment: BuildEnvironment,
14001400
): Promise<RollupOutput | RollupOutput[] | RollupWatcher>
14011401
}
14021402

14031403
export interface BuilderOptions {
1404-
buildEnvironments?: (
1405-
builder: ViteBuilder,
1406-
build: (environment: BuildEnvironment) => Promise<void>,
1407-
) => Promise<void>
1404+
buildApp?: (builder: ViteBuilder) => Promise<void>
14081405
}
14091406

1410-
async function defaultBuildEnvironments(
1411-
builder: ViteBuilder,
1412-
build: (environment: BuildEnvironment) => Promise<void>,
1413-
): Promise<void> {
1407+
async function defaultBuildApp(builder: ViteBuilder): Promise<void> {
14141408
for (const environment of Object.values(builder.environments)) {
1415-
await build(environment)
1409+
await builder.build(environment)
14161410
}
14171411
}
14181412

14191413
export function resolveBuilderOptions(
14201414
options: BuilderOptions = {},
14211415
): ResolvedBuilderOptions {
14221416
return {
1423-
buildEnvironments: options.buildEnvironments ?? defaultBuildEnvironments,
1417+
buildApp: options.buildApp ?? defaultBuildApp,
14241418
}
14251419
}
14261420

@@ -1463,18 +1457,13 @@ export async function createViteBuilder(
14631457
const builder: ViteBuilder = {
14641458
environments,
14651459
config: defaultConfig,
1466-
async buildEnvironments() {
1460+
async buildApp() {
14671461
if (defaultConfig.build.watch) {
14681462
throw new Error(
1469-
'Watch mode is not yet supported in viteBuilder.buildEnvironments()',
1463+
'Watch mode is not yet supported in viteBuilder.buildApp()',
14701464
)
14711465
}
1472-
return defaultConfig.builder.buildEnvironments(
1473-
builder,
1474-
async (environment) => {
1475-
await this.build(environment)
1476-
},
1477-
)
1466+
return defaultConfig.builder.buildApp(builder)
14781467
},
14791468
async build(environment: BuildEnvironment) {
14801469
return buildEnvironment(environment.config, environment)

packages/vite/src/node/cli.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ cli
281281
)
282282
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
283283
.option('--environment [name]', `[string] build a single environment`)
284-
.option('--all', `[boolean] build all environments`)
284+
.option('--app', `[boolean] build all the environments`)
285285
.action(
286286
async (
287287
root: string,
@@ -316,8 +316,8 @@ cli
316316
}
317317
await builder.build(environment)
318318
} else {
319-
// --all: build all environments
320-
await builder.buildEnvironments()
319+
// --app: build all environments
320+
await builder.buildApp()
321321
}
322322
} else {
323323
await build(config)

playground/environment-react-ssr/vite.config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ export default defineConfig((env) => ({
4747
},
4848

4949
builder: {
50-
async buildEnvironments(builder, build) {
51-
await build(builder.environments.client)
52-
await build(builder.environments.ssr)
50+
async buildApp(builder) {
51+
await builder.build(builder.environments.client)
52+
await builder.build(builder.environments.ssr)
5353
},
5454
},
5555
}))

playground/vitestSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ export async function startDefaultServe(): Promise<void> {
260260
)
261261
if (buildConfig.builder) {
262262
const builder = await createViteBuilder({}, { root: rootDir })
263-
await builder.buildEnvironments()
263+
await builder.buildApp()
264264
} else {
265265
const rollupOutput = await build(buildConfig)
266266
const isWatch = !!resolvedConfig!.build.watch

0 commit comments

Comments
 (0)