From 03f30dc1597570410bf203c99a040f226215aa6f Mon Sep 17 00:00:00 2001 From: patak-dev Date: Sat, 2 Jul 2022 18:12:56 +0200 Subject: [PATCH] refactor: ssrBuild is boolean only --- docs/config/index.md | 4 +++- packages/vite/src/node/config.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/config/index.md b/docs/config/index.md index 35991ae0da5d75..d57c4b41727e55 100644 --- a/docs/config/index.md +++ b/docs/config/index.md @@ -61,7 +61,7 @@ Vite also directly supports TS config files. You can use `vite.config.ts` with t ## Conditional Config -If the config needs to conditional determine options based on the command (`dev`/`serve` or `build`), the [mode](/guide/env-and-mode) being used, or if the build is for a SSR entry, it can export a function instead: +If the config needs to conditional determine options based on the command (`dev`/`serve` or `build`), the [mode](/guide/env-and-mode) being used, or if it is a SSR build (`ssrBuild`), it can export a function instead: ```js export default defineConfig(({ command, mode, ssrBuild }) => { @@ -78,6 +78,8 @@ export default defineConfig(({ command, mode, ssrBuild }) => { }) ``` +Only `ssrBuild` is included, as during dev, the config creates a single server shared between the SSR and non-SSR requests. + It is important to note that in Vite's API the `command` value is `serve` during dev (in the cli `vite`, `vite dev`, and `vite serve` are aliases), and `build` when building for production (`vite build`). ## Async Config diff --git a/packages/vite/src/node/config.ts b/packages/vite/src/node/config.ts index dd1df4dab9b39d..7325a736644b00 100644 --- a/packages/vite/src/node/config.ts +++ b/packages/vite/src/node/config.ts @@ -66,7 +66,7 @@ export type { RenderBuiltAssetUrl } from './build' export interface ConfigEnv { command: 'build' | 'serve' mode: string - ssrBuild: boolean | string + ssrBuild: boolean } /** @@ -378,7 +378,7 @@ export async function resolveConfig( const configEnv = { mode, command, - ssrBuild: config.build?.ssr ?? false + ssrBuild: !!config.build?.ssr } let { configFile } = config