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

fix: remove builder.entireApp #18028

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion docs/guide/api-environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ The callback is queued and it will wait for the current update to be resolved be

In the CLI, calling `vite build` and `vite build --ssr` will still build the client only and ssr only environments for backward compatibility.

When `builder.entireApp` is `true` (or when calling `vite build --app`), `vite build` will opt-in into building the entire app instead. This would later on become the default in a future major. A `ViteBuilder` instance will be created (build-time equivalent to a `ViteDevServer`) to build all configured environments for production. By default the build of environments is run in series respecting the order of the `environments` record. A framework or user can further configure how the environments are built using:
When calling `vite build --app` or the `createBuilder()` API, Vite will opt into building the entire app instead. This would later on become the default in a future major. A `ViteBuilder` instance will be created (build-time equivalent to a `ViteDevServer`) to build all configured environments for production. By default the build of environments is run in series respecting the order of the `environments` record. A framework or user can further configure how the environments are built using:

```js
export default {
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ vite build [root]
| `-f, --filter <filter>` | Filter debug logs (`string`) |
| `-m, --mode <mode>` | Set env mode (`string`) |
| `-h, --help` | Display available CLI options |
| `--app` | Build all environments, same as `builder.entireApp` (`boolean`, experimental) |
| `--app` | Build all environments, same as `(await createBuilder()).buildApp()` (`boolean`, experimental) |

## Others

Expand Down
24 changes: 1 addition & 23 deletions packages/vite/src/node/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,6 @@ export async function build(
}
}
const config = await resolveConfigToBuild(inlineConfig, patchConfig)
return buildWithResolvedConfig(config)
}

/**
* @internal used to implement `vite build` for backward compatibility
*/
export async function buildWithResolvedConfig(
config: ResolvedConfig,
): Promise<RollupOutput | RollupOutput[] | RollupWatcher> {
const environmentName = config.build.ssr ? 'ssr' : 'client'
const environment = await config.environments[
environmentName
Expand All @@ -538,7 +529,7 @@ export async function buildWithResolvedConfig(
return buildEnvironment(environment)
}

export function resolveConfigToBuild(
function resolveConfigToBuild(
inlineConfig: InlineConfig = {},
patchConfig?: (config: ResolvedConfig) => void,
patchPlugins?: (resolvedPlugins: Plugin[]) => void,
Expand Down Expand Up @@ -1503,7 +1494,6 @@ export interface ViteBuilder {
export interface BuilderOptions {
sharedConfigBuild?: boolean
sharedPlugins?: boolean
entireApp?: boolean
buildApp?: (builder: ViteBuilder) => Promise<void>
}

Expand All @@ -1519,7 +1509,6 @@ export function resolveBuilderOptions(
return {
sharedConfigBuild: options.sharedConfigBuild ?? false,
sharedPlugins: options.sharedPlugins ?? false,
entireApp: options.entireApp ?? false,
buildApp: options.buildApp ?? defaultBuildApp,
}
}
Expand All @@ -1533,17 +1522,6 @@ export async function createBuilder(
inlineConfig: InlineConfig = {},
): Promise<ViteBuilder> {
const config = await resolveConfigToBuild(inlineConfig)
return createBuilderWithResolvedConfig(inlineConfig, config)
}

/**
* Used to implement the `vite build` command without resolving the config twice
* @internal
*/
export async function createBuilderWithResolvedConfig(
inlineConfig: InlineConfig,
config: ResolvedConfig,
): Promise<ViteBuilder> {
const environments: Record<string, BuildEnvironment> = {}

const builder: ViteBuilder = {
Expand Down
36 changes: 7 additions & 29 deletions packages/vite/src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { performance } from 'node:perf_hooks'
import { cac } from 'cac'
import colors from 'picocolors'
import { VERSION } from './constants'
import type { BuildEnvironmentOptions, ResolvedBuildOptions } from './build'
import type { BuildEnvironmentOptions } from './build'
import type { ServerOptions } from './server'
import type { CLIShortcut } from './shortcuts'
import type { LogLevel } from './logger'
import { createLogger } from './logger'
import { resolveConfig } from './config'
import type { InlineConfig, ResolvedConfig } from './config'
import type { InlineConfig } from './config'

const cli = cac('vite')

Expand Down Expand Up @@ -279,14 +279,14 @@ cli
`[boolean] force empty outDir when it's outside of root`,
)
.option('-w, --watch', `[boolean] rebuilds when modules have changed on disk`)
.option('--app', `[boolean] same as builder.entireApp`)
.option('--app', `[boolean] same as \`(await createBuilder()).buildApp()\``)
.action(
async (
root: string,
options: BuildEnvironmentOptions & BuilderCLIOptions & GlobalCLIOptions,
) => {
filterDuplicateOptions(options)
const build = await import('./build')
const { build, createBuilder } = await import('./build')

const buildOptions: BuildEnvironmentOptions = cleanGlobalCLIOptions(
cleanBuilderCLIOptions(options),
Expand All @@ -301,35 +301,13 @@ cli
logLevel: options.logLevel,
clearScreen: options.clearScreen,
build: buildOptions,
...(options.app ? { builder: { entireApp: true } } : {}),
}
const patchConfig = (resolved: ResolvedConfig) => {
if (resolved.builder.entireApp) {
return
}
// Until the ecosystem updates to use `environment.config.build` instead of `config.build`,
// we need to make override `config.build` for the current environment.
// We can deprecate `config.build` in ResolvedConfig and push everyone to upgrade, and later
// remove the default values that shouldn't be used at all once the config is resolved
const environmentName = resolved.build.ssr ? 'ssr' : 'client'
;(resolved.build as ResolvedBuildOptions) = {
...resolved.environments[environmentName].build,
}
}
const config = await build.resolveConfigToBuild(
inlineConfig,
patchConfig,
)

if (config.builder.entireApp) {
const builder = await build.createBuilderWithResolvedConfig(
inlineConfig,
config,
)
if (options.app) {
const builder = await createBuilder(inlineConfig)
await builder.buildApp()
} else {
// Single environment (client or ssr) build or library mode build
await build.buildWithResolvedConfig(config)
await build(inlineConfig)
}
} catch (e) {
createLogger(options.logLevel).error(
Expand Down
Loading