chore: update with sapphi's suggestions

Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
This commit is contained in:
patak-dev 2024-10-24 14:14:46 +02:00
parent 91dae2cb01
commit 042f60c31b
2 changed files with 26 additions and 16 deletions

View File

@ -439,7 +439,9 @@ export interface UserConfig extends DefaultEnvironmentOptions {
/**
* Environment overrides
*/
[key: `$${string}`]: EnvironmentOptions
[key: `$${string}`]: EnvironmentOptions | undefined
$client?: EnvironmentOptions
$ssr?: EnvironmentOptions
/**
* Whether your application is a Single Page Application (SPA),
* a Multi-Page Application (MPA), or Custom Application (SSR
@ -975,10 +977,12 @@ export async function resolveConfig(
for (const name of Object.keys(config)) {
if (name.startsWith('$')) {
const environmentName = name as `$${string}`
environments[environmentName] = config[environmentName] = mergeConfig(
defaultEnvironmentOptions,
config[environmentName],
)
if (config[environmentName]) {
environments[environmentName] = config[environmentName] = mergeConfig(
defaultEnvironmentOptions,
config[environmentName],
)
}
}
}
@ -989,15 +993,17 @@ export async function resolveConfig(
const resolvedEnvironments: Record<`$${string}`, ResolvedEnvironmentOptions> =
{}
for (const environmentName of Object.keys(environments) as `$${string}`[]) {
resolvedEnvironments[environmentName] = resolveEnvironmentOptions(
environmentName,
config[environmentName],
resolvedDefaultResolve.alias,
resolvedDefaultResolve.preserveSymlinks,
logger,
environmentName,
config.experimental?.skipSsrTransform,
)
if (config[environmentName]) {
resolvedEnvironments[environmentName] = resolveEnvironmentOptions(
environmentName,
config[environmentName],
resolvedDefaultResolve.alias,
resolvedDefaultResolve.preserveSymlinks,
logger,
environmentName,
config.experimental?.skipSsrTransform,
)
}
}
// Backward compatibility: merge environments.$client.dev.optimizeDeps back into optimizeDeps
@ -1288,9 +1294,9 @@ export async function resolveConfig(
safeModulePaths: new Set<string>(),
}
resolved = {
...config,
...(config as Omit<InlineConfig, `$${string}`>),
...resolved,
} as ResolvedConfig
}
// Backward compatibility hook, modify the resolved config before it is used
// to create internal plugins. For example, `config.build.ssr`. Once we rework

View File

@ -279,6 +279,8 @@ export interface ViteDevServer {
*/
environments: DevEnvironment[]
[key: `$${string}`]: DevEnvironment
$client: DevEnvironment
$ssr: DevEnvironment
/**
* Module graph that tracks the import relationships, url to file mapping
* and hmr state.
@ -526,6 +528,8 @@ export async function _createServer(
environments: Object.values(environments),
...environments,
$client: environments.$client,
$ssr: environments.$ssr,
pluginContainer,
get moduleGraph() {