Skip to content

Commit dcea0b1

Browse files
committed
fix: only build all environments if none have been build
1 parent fa6912d commit dcea0b1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/vite/src/node/build.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,12 +1549,6 @@ export interface BuilderOptions {
15491549
buildApp?: (builder: ViteBuilder) => Promise<void>
15501550
}
15511551

1552-
async function defaultBuildApp(builder: ViteBuilder): Promise<void> {
1553-
for (const environment of Object.values(builder.environments)) {
1554-
await builder.build(environment)
1555-
}
1556-
}
1557-
15581552
export const builderOptionsDefaults = Object.freeze({
15591553
sharedConfigBuild: false,
15601554
sharedPlugins: false,
@@ -1566,7 +1560,7 @@ export function resolveBuilderOptions(
15661560
): ResolvedBuilderOptions | undefined {
15671561
if (!options) return
15681562
return mergeWithDefaults(
1569-
{ ...builderOptionsDefaults, buildApp: defaultBuildApp },
1563+
{ ...builderOptionsDefaults, buildApp: async () => {} },
15701564
options,
15711565
)
15721566
}
@@ -1621,6 +1615,16 @@ export async function createBuilder(
16211615
if (!configBuilderBuildAppCalled) {
16221616
await configBuilder.buildApp(builder)
16231617
}
1618+
// fallback to building all environments if no environments have been built
1619+
if (
1620+
Object.values(builder.environments).every(
1621+
(environment) => !environment.isBuilt,
1622+
)
1623+
) {
1624+
for (const environment of Object.values(builder.environments)) {
1625+
await builder.build(environment)
1626+
}
1627+
}
16241628
},
16251629
async build(
16261630
environment: BuildEnvironment,

0 commit comments

Comments
 (0)