Skip to content

Commit

Permalink
refactor: ssrBuild is boolean only
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed Jul 2, 2022
1 parent 452bee2 commit 03f30dc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion docs/config/index.md
Expand Up @@ -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 }) => {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/vite/src/node/config.ts
Expand Up @@ -66,7 +66,7 @@ export type { RenderBuiltAssetUrl } from './build'
export interface ConfigEnv {
command: 'build' | 'serve'
mode: string
ssrBuild: boolean | string
ssrBuild: boolean
}

/**
Expand Down Expand Up @@ -378,7 +378,7 @@ export async function resolveConfig(
const configEnv = {
mode,
command,
ssrBuild: config.build?.ssr ?? false
ssrBuild: !!config.build?.ssr
}

let { configFile } = config
Expand Down

0 comments on commit 03f30dc

Please sign in to comment.