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

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

this.environment introduced in Vite 6 for plugin hooks

In Vite 6, the this.environment property was introduced in the plugin context to interact with the environment of the current module in hooks. This allows plugins to access environment information without relying on the single options.ssr argument that was used in Vite versions before 6. Before Vite 6, only two environments were available: client and ssr.

options.ssr deprecation planned for future Vite major version

The options.ssr argument in plugin hooks is planned for deprecation in a future major version of Vite. Plugin authors should migrate to use this.environment instead. To identify usage of the old API, set future.removePluginHookSsrArgument to 'warn' in the vite config.

this.environment provides access to config, moduleGraph, and transformRequest

The this.environment property gives plugin authors access to environment.config, environment.moduleGraph, and environment.transformRequest(). This allows plugins to have the environment instance available in the context and avoid dependency on the whole dev server.

Migration from options.ssr to this.environment.config.consumer

To migrate existing plugins, replace the options.ssr argument with this.environment.config.consumer === 'server' in the resolveId, load, and transform hooks. When this.environment.config.consumer equals 'server', it indicates SSR mode; otherwise it indicates client mode.

Migration example: using this.environment in resolveId hook

Example showing migration from options.ssr to this.environment in a plugin's resolveId hook: ```ts import { Plugin } from 'vite' export function myPlugin(): Plugin { return { name: 'my-plugin', resolveId(id, importer, options) { const isSSR = this.environment.config.consumer === 'server' if (isSSR) { // SSR specific logic } else { // Client specific logic } }, } } ```

Vite 6 supports any number of named environments

In Vite 6, a Vite application can define any number of named environments as needed, unlike previous versions which were limited to client and ssr environments.

Give your agent this brain