new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Vite · Guide · all subjects

environment api/build

11 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Environment build backward compatibility

In the CLI, calling vite build (client only) and vite build --ssr (SSR only) will still build only the specified environment for backward compatibility.

App build with builder option

When the builder option is set (even to an empty object {}), vite build opts in to building the entire app instead of just the client. This builds all configured environments for production. By default, environments are built in series, following the order of the environments record. The builder option will become the default in a future major version.

builder.buildApp option

Control how environments are built through the builder.buildApp config option. It receives the ViteBuilder instance and is responsible for building each environment. Use this to build environments in parallel or in a custom order. Example: const environments = Object.values(builder.environments); await Promise.all(environments.map((environment) => builder.build(environment)));

buildApp plugin hook

Plugins can define a buildApp hook with signature (this: MinimalPluginContextWithoutEnvironment, builder: ViteBuilder) => Promise<void>. It is an async, sequential, global hook. Hooks with order 'pre' or null run first, then the configured builder.buildApp, then hooks with order 'post'. Within a hook, environment.isBuilt tells whether an environment has already been built.

createBuilder function

Use createBuilder to trigger an app build from your own code. It is the build-time equivalent of createServer: it resolves the config and returns a ViteBuilder instance. Call builder.buildApp() to build every configured environment, or builder.build(environment) to build a single environment. createBuilder supersedes the standalone build function for environment-aware builds.

Environment instance in build hooks

During build, plugin hooks receive the environment instance, replacing the ssr boolean parameter. This also applies to renderChunk, generateBundle, and other build-only hooks.

Vite 6 plugins shared during build in single process

In Vite 6, all environments are built in a single process so the plugin pipeline and inter-environment communication can be aligned with development. Before Vite 6, during build, plugins were isolated for each environment in different processes (vite build then vite build --ssr), requiring state sharing through manifest files.

builder.sharedConfigBuild option for shared config

A project can opt-in to sharing the full config and plugins pipeline across environments during build by setting builder.sharedConfigBuild to true. By default in Vite 6, a new ResolvedConfig is created per-environment to maintain backward compatibility, since ecosystem plugins use config.build instead of environment.config.build.

Plugin sharedDuringBuild flag

Plugin authors can opt-in for a particular plugin to be shared across all environments during build by setting the sharedDuringBuild flag to true on the plugin object. This allows for easily sharing state both during dev and build for plugins that support it.

Example shared plugin with sharedDuringBuild flag

Example of a plugin with sharedDuringBuild flag: ```js function myPlugin() { // Share state among all environments in dev and build const sharedState = ... return { name: 'shared-plugin', transform(code, id) { ... }, // Opt-in into a single instance for all environments sharedDuringBuild: true, } } ``` Setting sharedDuringBuild: true makes the plugin use a single shared instance across all environments during both dev and build.

Client environment always present during build

During build, the client environment is always present. The ssr environment is only present if explicitly configured using environments.ssr or for backward compatibility build.ssr.

Give your agent this brain