Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1605,6 +1605,7 @@ export async function createBuilder(
if (useLegacyBuilder) {
await setupEnvironment(config.build.ssr ? 'ssr' : 'client', config)
} else {
const environmentConfigs: [string, ResolvedConfig][] = []
for (const environmentName of Object.keys(config.environments)) {
// We need to resolve the config again so we can properly merge options
// and get a new set of plugins for each build environment. The ecosystem
Expand Down Expand Up @@ -1647,9 +1648,14 @@ export async function createBuilder(
patchPlugins,
)
}

await setupEnvironment(environmentName, environmentConfig)
environmentConfigs.push([environmentName, environmentConfig])
}
await Promise.all(
environmentConfigs.map(
async ([environmentName, environmentConfig]) =>
await setupEnvironment(environmentName, environmentConfig),
),
)
}

return builder
Expand Down
32 changes: 17 additions & 15 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,22 +509,24 @@ export async function _createServer(

const environments: Record<string, DevEnvironment> = {}

for (const [name, environmentOptions] of Object.entries(
config.environments,
)) {
environments[name] = await environmentOptions.dev.createEnvironment(
name,
config,
{
ws,
},
)
}
await Promise.all(
Object.entries(config.environments).map(
async ([name, environmentOptions]) => {
const environment = await environmentOptions.dev.createEnvironment(
name,
config,
{
ws,
},
)
environments[name] = environment

for (const environment of Object.values(environments)) {
const previousInstance = options.previousEnvironments?.[environment.name]
await environment.init({ watcher, previousInstance })
}
const previousInstance =
options.previousEnvironments?.[environment.name]
await environment.init({ watcher, previousInstance })
},
),
)

// Backward compatibility

Expand Down
Loading