Skip to content

Commit 7de7c5b

Browse files
iiio2patak-dev
andauthored
docs: tweak wordings in Environment API doc (#18881)
Co-authored-by: patak <[email protected]>
1 parent a1ad682 commit 7de7c5b

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

docs/guide/api-environment-frameworks.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ app.use('*', async (req, res, next) => {
9292
})
9393
```
9494

95-
## Runtime agnostic SSR
95+
## Runtime Agnostic SSR
9696

9797
Since the `RunnableDevEnvironment` can only be used to run the code in the same runtime as the Vite server, it requires a runtime that can run the Vite Server (a runtime that is compatible with Node.js). This means that you will need to use the raw `DevEnvironment` to make it runtime agnostic.
9898

@@ -264,7 +264,7 @@ export function createHandler(input) {
264264
}
265265
```
266266

267-
## Environments during build
267+
## Environments During Build
268268

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

@@ -283,6 +283,6 @@ export default {
283283
}
284284
```
285285

286-
## Environment agnostic code
286+
## Environment Agnostic Code
287287

288288
Most of the time, the current `environment` instance will be available as part of the context of the code being run so the need to access them through `server.environments` should be rare. For example, inside plugin hooks the environment is exposed as part of the `PluginContext`, so it can be accessed using `this.environment`. See [Environment API for Plugins](./api-environment-plugins.md) to learn about how to build environment aware plugins.

docs/guide/api-environment-instances.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Using `Environment` instances
1+
# Using `Environment` Instances
22

33
:::warning Experimental
44
Environment API is experimental. We'll keep the APIs stable during Vite 6 to let the ecosystem experiment and build on top of it. We're planning to stabilize these new APIs with potential breaking changes in Vite 7.
@@ -11,7 +11,7 @@ Resources:
1111
Please share your feedback with us.
1212
:::
1313

14-
## Accessing the environments
14+
## Accessing the Environments
1515

1616
During dev, the available environments in a dev server can be accessed using `server.environments`:
1717

@@ -118,7 +118,7 @@ An environment instance in the Vite server lets you process a URL using the `env
118118
We are using `transformRequest(url)` and `warmupRequest(url)` in the current version of this proposal so it is easier to discuss and understand for users used to Vite's current API. Before releasing, we can take the opportunity to review these names too. For example, it could be named `environment.processModule(url)` or `environment.loadModule(url)` taking a page from Rollup's `context.load(id)` in plugin hooks. For the moment, we think keeping the current names and delaying this discussion is better.
119119
:::
120120

121-
## Separate module graphs
121+
## Separate Module Graphs
122122

123123
Each environment has an isolated module graph. All module graphs have the same signature, so generic algorithms can be implemented to crawl or query the graph without depending on the environment. `hotUpdate` is a good example. When a file is modified, the module graph of each environment will be used to discover the affected modules and perform HMR for each environment independently.
124124

docs/guide/api-environment-plugins.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Resources:
1111
Please share your feedback with us.
1212
:::
1313

14-
## Accessing the current environment in hooks
14+
## Accessing the Current Environment in Hooks
1515

1616
Given that there were only two Environments until Vite 6 (`client` and `ssr`), a `ssr` boolean was enough to identify the current environment in Vite APIs. Plugin Hooks received a `ssr` boolean in the last options parameter, and several APIs expected an optional last `ssr` parameter to properly associate modules to the correct environment (for example `server.moduleGraph.getModuleByUrl(url, { ssr })`).
1717

@@ -27,7 +27,7 @@ A plugin could use the `environment` instance to change how a module is processe
2727
}
2828
```
2929

30-
## Registering new environments using hooks
30+
## Registering New Environments Using Hooks
3131

3232
Plugins can add new environments in the `config` hook (for example to have a separate module graph for [RSC](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components)):
3333

@@ -39,7 +39,7 @@ Plugins can add new environments in the `config` hook (for example to have a sep
3939

4040
An empty object is enough to register the environment, default values from the root level environment config.
4141

42-
## Configuring environment using hooks
42+
## Configuring Environment Using Hooks
4343

4444
While the `config` hook is running, the complete list of environments isn't yet known and the environments can be affected by both the default values from the root level environment config or explicitly through the `config.environments` record.
4545
Plugins should set default values using the `config` hook. To configure each environment, they can use the new `configEnvironment` hook. This hook is called for each environment with its partially resolved config including resolution of final defaults.
@@ -50,7 +50,7 @@ Plugins should set default values using the `config` hook. To configure each env
5050
options.resolve.conditions = // ...
5151
```
5252
53-
## The `hotUpdate` hook
53+
## The `hotUpdate` Hook
5454
5555
- **Type:** `(this: { environment: DevEnvironment }, options: HotUpdateOptions) => Array<EnvironmentModuleNode> | void | Promise<Array<EnvironmentModuleNode> | void>`
5656
- **See also:** [HMR API](./api-hmr)
@@ -135,7 +135,7 @@ const UnoCssPlugin = () => {
135135
// shared global state
136136
return {
137137
buildStart() {
138-
// init per environment state with WeakMap<Environment,Data>
138+
// init per-environment state with WeakMap<Environment,Data>
139139
// using this.environment
140140
},
141141
configureServer() {
@@ -184,12 +184,12 @@ export default defineConfig({
184184
})
185185
```
186186
187-
## Environment in build hooks
187+
## Environment in Build Hooks
188188
189189
In the same way as during dev, plugin hooks also receive the environment instance during build, replacing the `ssr` boolean.
190190
This also works for `renderChunk`, `generateBundle`, and other build only hooks.
191191
192-
## Shared plugins during build
192+
## Shared Plugins During Build
193193
194194
Before Vite 6, the plugins pipelines worked in a different way during dev and build:
195195
@@ -204,7 +204,7 @@ In a future major (Vite 7 or 8), we aim to have complete alignment:
204204
205205
There will also be a single `ResolvedConfig` instance shared during build, allowing for caching at entire app build process level in the same way as we have been doing with `WeakMap<ResolvedConfig, CachedData>` during dev.
206206
207-
For Vite 6, we need to do a smaller step to keep backward compatibility. Ecosystem plugins are currently using `config.build` instead of `environment.config.build` to access configuration, so we need to create a new `ResolvedConfig` per environment by default. A project can opt-in into sharing the full config and plugins pipeline setting `builder.sharedConfigBuild` to `true`.
207+
For Vite 6, we need to do a smaller step to keep backward compatibility. Ecosystem plugins are currently using `config.build` instead of `environment.config.build` to access configuration, so we need to create a new `ResolvedConfig` per-environment by default. A project can opt-in into sharing the full config and plugins pipeline setting `builder.sharedConfigBuild` to `true`.
208208
209209
This option would only work of a small subset of projects at first, so plugin authors can opt-in for a particular plugin to be shared by setting the `sharedDuringBuild` flag to `true`. This allows for easily sharing state both for regular plugins:
210210

docs/guide/api-environment-runtimes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Resources:
1111
Please share your feedback with us.
1212
:::
1313

14-
## Environment factories
14+
## Environment Factories
1515

1616
Environments factories are intended to be implemented by Environment providers like Cloudflare, and not by end users. Environment factories return a `EnvironmentOptions` for the most common case of using the target runtime for both dev and build environments. The default environment options can also be set so the user doesn't need to do it.
1717

@@ -72,7 +72,7 @@ and frameworks can use an environment with the workerd runtime to do SSR using:
7272
const ssrEnvironment = server.environments.ssr
7373
```
7474

75-
## Creating a new environment factory
75+
## Creating a New Environment Factory
7676

7777
A Vite dev server exposes two environments by default: a `client` environment and an `ssr` environment. The client environment is a browser environment by default, and the module runner is implemented by importing the virtual module `/@vite/client` to client apps. The SSR environment runs in the same Node runtime as the Vite server by default and allows application servers to be used to render requests during dev with full HMR support.
7878

docs/guide/api-environment.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ Please share your feedback with us.
1515

1616
Vite 6 formalizes the concept of Environments. Until Vite 5, there were two implicit Environments (`client`, and optionally `ssr`). The new Environment API allows users and framework authors to create as many environments as needed to map the way their apps work in production. This new capability required a big internal refactoring, but a lot of effort has been placed on backward compatibility. The initial goal of Vite 6 is to move the ecosystem to the new major as smoothly as possible, delaying the adoption of these new experimental APIs until enough users have migrated and frameworks and plugin authors have validated the new design.
1717

18-
## Closing the gap between build and dev
18+
## Closing the Gap Between Build and Dev
1919

2020
For a simple SPA/MPA, no new APIs around environments are exposed to the config. Internally, Vite will apply the options to a `client` environment, but it's not necessary to know of this concept when configuring Vite. The config and behavior from Vite 5 should work seamlessly here.
2121

22-
When we move to a typical server side rendered (SSR) app, we'll have two environments:
22+
When we move to a typical server-side rendered (SSR) app, we'll have two environments:
2323

2424
- `client`: runs the app in the browser.
2525
- `server`: runs the app in node (or other server runtimes) which renders pages before sending them to the browser.
@@ -68,7 +68,7 @@ export default {
6868
}
6969
```
7070

71-
When not explicitly documented, environment inherit the configured top-level config options (for example, the new `server` and `edge` environments will inherit the `build.sourcemap: false` option). A small number of top-level options, like `optimizeDeps`, only apply to the `client` environment, as they don't work well when applied as a default to server environments. The `client` environment can also be configured explicitly through `environments.client`, but we recommend to do it with the top-level options so the client config remains unchanged when adding new environments.
71+
When not explicitly documented, environment inherits the configured top-level config options (for example, the new `server` and `edge` environments will inherit the `build.sourcemap: false` option). A small number of top-level options, like `optimizeDeps`, only apply to the `client` environment, as they don't work well when applied as a default to server environments. The `client` environment can also be configured explicitly through `environments.client`, but we recommend to do it with the top-level options so the client config remains unchanged when adding new environments.
7272

7373
The `EnvironmentOptions` interface exposes all the per-environment options. There are environment options that apply to both `build` and `dev`, like `resolve`. And there are `DevEnvironmentOptions` and `BuildEnvironmentOptions` for dev and build specific options (like `dev.warmup` or `build.outDir`). Some options like `optimizeDeps` only applies to dev, but is kept as top level instead of nested in `dev` for backward compatibility.
7474

@@ -83,7 +83,7 @@ interface EnvironmentOptions {
8383
}
8484
```
8585

86-
The `UserConfig` interface extends from the `EnvironmentOptions` interface, allowing to configure the client and defaults for other environments, configured through the `environments` option. The `client` and a server environment named `ssr` are always present during dev. This allows backward compatibility with `server.ssrLoadModule(url)` and `server.moduleGraph`. During build, the `client` environment is always present, and the `ssr` environment is only present if it is explicitly configured (using `environments.ssr` or for backward compatibility `build.ssr`). An app doesn't need to use the `ssr` name for their SSR environment, it could name it `server` for example.
86+
The `UserConfig` interface extends from the `EnvironmentOptions` interface, allowing to configure the client and defaults for other environments, configured through the `environments` option. The `client` and a server environment named `ssr` are always present during dev. This allows backward compatibility with `server.ssrLoadModule(url)` and `server.moduleGraph`. During build, the `client` environment is always present, and the `ssr` environment is only present if it is explicitly configured (using `environments.ssr` or for backward compatibility `build.ssr`). An app doesn't need to use the `ssr` name for its SSR environment, it could name it `server` for example.
8787

8888
```ts
8989
interface UserConfig extends EnvironmentOptions {
@@ -94,7 +94,7 @@ interface UserConfig extends EnvironmentOptions {
9494

9595
Note that the `ssr` top-level property is going to be deprecated once the Environment API is stable. This option has the same role as `environments`, but for the default `ssr` environment and only allowed configuring of a small set of options.
9696

97-
## Custom environment instances
97+
## Custom Environment Instances
9898

9999
Low level configuration APIs are available so runtime providers can provide environments with proper defaults for their runtimes. These environments can also spawn other processes or threads to run the modules during dev in a closer runtime to the production environment.
100100

@@ -129,7 +129,7 @@ We don't recommend switching to Environment API yet. We are aiming for a good po
129129
- [SSR using `ModuleRunner` API](/changes/ssr-using-modulerunner)
130130
- [Shared plugins during build](/changes/shared-plugins-during-build)
131131

132-
## Target users
132+
## Target Users
133133

134134
This guide provides the basic concepts about environments for end users.
135135

0 commit comments

Comments
 (0)