Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ssrBuild flag in config env #8863

Merged
merged 7 commits into from Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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:
patak-dev marked this conversation as resolved.
Show resolved Hide resolved

```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.
patak-dev marked this conversation as resolved.
Show resolved Hide resolved

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`).
patak-dev marked this conversation as resolved.
Show resolved Hide resolved

## 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