Skip to content

Commit 1141df8

Browse files
committed
chore: merge main
2 parents 1befecb + 6f60adc commit 1141df8

File tree

219 files changed

+9704
-4696
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

219 files changed

+9704
-4696
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848

4949
- name: Get changed files
5050
id: changed-files
51-
uses: tj-actions/changed-files@c65cd883420fd2eb864698a825fc4162dd94482c # v44.5.7
51+
uses: tj-actions/changed-files@e9772d140489982e0e3704fea5ee93d536f1e275 # v45.0.1
5252
with:
5353
files: |
5454
docs/**

docs/.vitepress/config.ts

+46-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,13 @@ export default defineConfig({
262262
link: '/guide/philosophy',
263263
},
264264
{
265-
text: 'Migration from v4',
265+
text: 'Migration from v5',
266266
link: '/guide/migration',
267267
},
268+
{
269+
text: 'Breaking Changes',
270+
link: '/changes/',
271+
},
268272
],
269273
},
270274
{
@@ -283,8 +287,8 @@ export default defineConfig({
283287
link: '/guide/api-javascript',
284288
},
285289
{
286-
text: 'Vite Runtime API',
287-
link: '/guide/api-vite-runtime',
290+
text: 'Environment API',
291+
link: '/guide/api-environment',
288292
},
289293
{
290294
text: 'Config Reference',
@@ -332,6 +336,45 @@ export default defineConfig({
332336
],
333337
},
334338
],
339+
'/changes/': [
340+
{
341+
text: 'Breaking Changes',
342+
link: '/changes/',
343+
},
344+
{
345+
text: 'Current',
346+
items: [],
347+
},
348+
{
349+
text: 'Future',
350+
items: [
351+
{
352+
text: 'this.environment in Hooks',
353+
link: '/changes/this-environment-in-hooks',
354+
},
355+
{
356+
text: 'HMR hotUpdate Plugin Hook',
357+
link: '/changes/hotupdate-hook',
358+
},
359+
{
360+
text: 'Move to per-environment APIs',
361+
link: '/changes/per-environment-apis',
362+
},
363+
{
364+
text: 'SSR using ModuleRunner API',
365+
link: '/changes/ssr-using-modulerunner',
366+
},
367+
{
368+
text: 'Shared plugins during build',
369+
link: '/changes/shared-plugins-during-build',
370+
},
371+
],
372+
},
373+
{
374+
text: 'Past',
375+
items: [],
376+
},
377+
],
335378
},
336379

337380
outline: {

docs/blog/announcing-vite5-1.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ The new API brings many benefits:
5656

5757
The initial idea [was proposed by Pooya Parsa](https://github.com/nuxt/vite/pull/201) and implemented by [Anthony Fu](https://github.com/antfu) as the [vite-node](https://github.com/vitest-dev/vitest/tree/main/packages/vite-node#readme) package to [power Nuxt 3 Dev SSR](https://antfu.me/posts/dev-ssr-on-nuxt) and later also used as the base for [Vitest](https://vitest.dev). So the general idea of vite-node has been battle-tested for quite some time now. This is a new iteration of the API by [Vladimir Sheremet](https://github.com/sheremet-va), who had already re-implemented vite-node in Vitest and took the learnings to make the API even more powerful and flexible when adding it to Vite Core. The PR was one year in the makings, you can see the evolution and discussions with ecosystem maintainers [here](https://github.com/vitejs/vite/issues/12165).
5858

59-
Read more in the [Vite Runtime API guide](/guide/api-vite-runtime) and [give us feedback](https://github.com/vitejs/vite/discussions/15774).
59+
::: info
60+
The Vite Runtime API evolved into the Module Runner API, released in Vite 6 as part of the [Environment API](/guide/api-environment).
61+
:::
6062

6163
## Features
6264

docs/changes/hotupdate-hook.md

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# HMR `hotUpdate` Plugin Hook
2+
3+
::: tip Feedback
4+
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
5+
:::
6+
7+
We're planning to deprecate the `handleHotUpdate` plugin hook in favor of [`hotUpdate` hook](/guide/api-environment#the-hotupdate-hook) to be [Environment API](/guide/api-environment.md) aware, and handle additional watch events with `create` and `delete`.
8+
9+
Affected scope: `Vite Plugin Authors`
10+
11+
::: warning Future Deprecation
12+
`hotUpdate` was first introduced in `v6.0`. The deprecation of `handleHotUpdate` is planned for `v7.0`. We don't yet recommend moving away from `handleHotUpdate` yet. If you want to experiment and give us feedback, you can use the `future.removePluginHookHandleHotUpdate` to `"warn"` in your vite config.
13+
:::
14+
15+
## Motivation
16+
17+
The [`handleHotUpdate` hook](/guide/api-plugin.md#handlehotupdate) allows to perform custom HMR update handling. A list of modules to be updated is passed in the `HmrContext`
18+
19+
```ts
20+
interface HmrContext {
21+
file: string
22+
timestamp: number
23+
modules: Array<ModuleNode>
24+
read: () => string | Promise<string>
25+
server: ViteDevServer
26+
}
27+
```
28+
29+
This hook is called once for all environments, and the passed modules have mixed information from the Client and SSR environments only. Once frameworks move to custom environments, a new hook that is called for each of them is needed.
30+
31+
The new `hotUpdate` hook works in the same way as `handleHotUpdate` but it is called for each environment and receives a new `HotUpdateContext` instance:
32+
33+
```ts
34+
interface HotUpdateContext {
35+
type: 'create' | 'update' | 'delete'
36+
file: string
37+
timestamp: number
38+
modules: Array<EnvironmentModuleNode>
39+
read: () => string | Promise<string>
40+
server: ViteDevServer
41+
}
42+
```
43+
44+
The current dev environment can be accessed like in other Plugin hooks with `this.environment`. The `modules` list will now be module nodes from the current environment only. Each environment update can define different update strategies.
45+
46+
This hook is also now called for additional watch events and not only for `'update'`. Use `type` to differentiate between them.
47+
48+
## Migration Guide
49+
50+
Filter and narrow down the affected module list so that the HMR is more accurate.
51+
52+
```js
53+
handleHotUpdate({ modules }) {
54+
return modules.filter(condition)
55+
}
56+
57+
// Migrate to:
58+
59+
hotUpdate({ modules }) {
60+
return modules.filter(condition)
61+
}
62+
```
63+
64+
Return an empty array and perform a full reload:
65+
66+
```js
67+
handleHotUpdate({ server, modules, timestamp }) {
68+
// Invalidate modules manually
69+
const invalidatedModules = new Set()
70+
for (const mod of modules) {
71+
server.moduleGraph.invalidateModule(
72+
mod,
73+
invalidatedModules,
74+
timestamp,
75+
true
76+
)
77+
}
78+
server.ws.send({ type: 'full-reload' })
79+
return []
80+
}
81+
82+
// Migrate to:
83+
84+
hotUpdate({ modules, timestamp }) {
85+
// Invalidate modules manually
86+
const invalidatedModules = new Set()
87+
for (const mod of modules) {
88+
this.environment.moduleGraph.invalidateModule(
89+
mod,
90+
invalidatedModules,
91+
timestamp,
92+
true
93+
)
94+
}
95+
this.environment.hot.send({ type: 'full-reload' })
96+
return []
97+
}
98+
```
99+
100+
Return an empty array and perform complete custom HMR handling by sending custom events to the client:
101+
102+
```js
103+
handleHotUpdate({ server }) {
104+
server.ws.send({
105+
type: 'custom',
106+
event: 'special-update',
107+
data: {}
108+
})
109+
return []
110+
}
111+
112+
// Migrate to...
113+
114+
hotUpdate() {
115+
this.environment.hot.send({
116+
type: 'custom',
117+
event: 'special-update',
118+
data: {}
119+
})
120+
return []
121+
}
122+
```

docs/changes/index.md

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Breaking Changes
2+
3+
List of breaking changes in Vite including API deprecations, removals, and changes. Most of the changes below can be opt-in using the [`future` option](/config/shared-options.html#future) in your Vite config.
4+
5+
## Planned
6+
7+
These changes are planned for the next major version of Vite. The deprecation or usage warnings will guide you where possible, and we're reaching out to framework, plugin authors, and users to apply these changes.
8+
9+
- _No planned changes yet_
10+
11+
## Considering
12+
13+
These changes are being considered and are often experimental APIs that intend to improve upon current usage patterns. As not all changes are listed here, please check out the [Experimental Label in Vite GitHub Discussions](https://github.com/vitejs/vite/discussions/categories/feedback?discussions_q=label%3Aexperimental+category%3AFeedback) for the full list.
14+
15+
We don't recommend switching to these APIs yet. They are included in Vite to help us gather feedback. Please check these proposals and let us know how they work in your use case in each's linked GitHub Discussions.
16+
17+
- [`this.environment` in Hooks](/changes/this-environment-in-hooks)
18+
- [HMR `hotUpdate` Plugin Hook](/changes/hotupdate-hook)
19+
- [Move to per-environment APIs](/changes/per-environment-apis)
20+
- [SSR using `ModuleRunner` API](/changes/ssr-using-modulerunner)
21+
- [Shared plugins during build](/changes/shared-plugins-during-build)
22+
23+
## Past
24+
25+
The changes below has been done or reverted. They are no longer relevant in the current major version.
26+
27+
- _No past changes yet_

docs/changes/per-environment-apis.md

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Move to per-environment APIs
2+
3+
::: tip Feedback
4+
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
5+
:::
6+
7+
Multiple APIs from ViteDevServer related to module graph has replaced with more isolated Environment APIs.
8+
9+
- `server.moduleGraph` -> [`environment.moduleGraph`](/guide/api-environment#separate-module-graphs)
10+
- `server.transformRequest` -> `environment.transformRequest`
11+
- `server.warmupRequest` -> `environment.warmupRequest`
12+
13+
Affect scope: `Vite Plugin Authors`
14+
15+
::: warning Future Deprecation
16+
The Environment instance was first introduced at `v6.0`. The deprecation of `server.moduleGraph` and other methods that are now in environments is planned for `v7.0`. We don't recommend moving away from server methods yet. To identify your usage, set these in your vite config.
17+
18+
```ts
19+
future: {
20+
removeServerModuleGraph: 'warn',
21+
removeServerTransformRequest: 'warn',
22+
}
23+
```
24+
25+
:::
26+
27+
## Motivation
28+
29+
// TODO:
30+
31+
## Migration Guide
32+
33+
// TODO:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Shared Plugins during Build
2+
3+
::: tip Feedback
4+
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
5+
:::
6+
7+
// TODO:
8+
See [Shared plugins during build](/guide/api-environment.md#shared-plugins-during-build).
9+
10+
Affect scope: `Vite Plugin Authors`
11+
12+
::: warning Future Default Change
13+
`builder.sharedConfigBuild` was first introduce in `v6.0`. You can set it true to check how your plugins work with a shared config. We're looking for feedback about changing the default in a future major once the plugin ecosystem is ready.
14+
:::
15+
16+
## Motivation
17+
18+
// TODO:
19+
20+
## Migration Guide
21+
22+
// TODO:
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# SSR using `ModuleRunner` API
2+
3+
::: tip Feedback
4+
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
5+
:::
6+
7+
`server.ssrLoadModule` has been replaced by [Module Runner](/guide/api-environment#modulerunner).
8+
9+
Affect scope: `Vite Plugin Authors`
10+
11+
::: warning Future Deprecation
12+
`ModuleRunner` was first introduce in `v6.0`. The deprecation of `server.ssrLoadModule` is planned for a future major. To identify your usage, set `future.removeSrLoadModule` to `"warn"` in your vite config.
13+
:::
14+
15+
## Motivation
16+
17+
// TODO:
18+
19+
## Migration Guide
20+
21+
// TODO:
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# `this.environment` in Hooks
2+
3+
::: tip Feedback
4+
Give us feedback at [Environment API feedback discussion](https://github.com/vitejs/vite/discussions/16358)
5+
:::
6+
7+
Before Vite 6, only two environments were available: `client` and `ssr`. A single `options.ssr` plugin hook argument in `resolveId`, `load` and `transform` allowed plugin authors to differentiate between these two environments when processing modules in plugin hooks. In Vite 6, a Vite application can define any number of named environments as needed. We're introducing `this.environment` in the plugin context to interact with the environment of the current module in hooks.
8+
9+
Affect scope: `Vite Plugin Authors`
10+
11+
::: warning Future Deprecation
12+
`this.environment` was introduced in `v6.0`. The deprecation of `options.ssr` is planned for `v7.0`. At that point we'll start recommending migrating your plugins to use the new API. To identify your usage, set `future.removePluginHookSsrArgument` to `"warn"` in your vite config.
13+
:::
14+
15+
## Motivation
16+
17+
`this.environment` not only allow the plugin hook implementation to know the current environment name, it also gives access to the environment config options, module graph information, and transform pipeline (`environment.config`, `environment.moduleGraph`, `environment.transformRequest()`). Having the environment instance available in the context allows plugin authors to avoid the dependency of the whole dev server (typically cached at startup through the `configureServer` hook).
18+
19+
## Migration Guide
20+
21+
For the existing plugin to do a quick migration, replace the `options.ssr` argument with `this.environment.name !== 'client'` in the `resolveId`, `load` and `transform` hooks:
22+
23+
```ts
24+
import { Plugin } from 'vite'
25+
26+
export function myPlugin(): Plugin {
27+
return {
28+
name: 'my-plugin',
29+
resolveId(id, importer, options) {
30+
const isSSR = options.ssr // [!code --]
31+
const isSSR = this.environment.name !== 'client' // [!code ++]
32+
33+
if (isSSR) {
34+
// SSR specific logic
35+
} else {
36+
// Client specific logic
37+
}
38+
},
39+
}
40+
}
41+
```
42+
43+
For a more robust long term implementation, the plugin hook should handle for [multiple environments](/guide/api-environment.html#accessing-the-current-environment-in-hooks) using fine-grained environment options instead of relying on the environment name.

docs/config/build-options.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,19 @@ When set to `true`, the build will also generate an SSR manifest for determining
192192

193193
Produce SSR-oriented build. The value can be a string to directly specify the SSR entry, or `true`, which requires specifying the SSR entry via `rollupOptions.input`.
194194

195+
## build.emitAssets
196+
197+
- **Type:** `boolean`
198+
- **Default:** `false`
199+
200+
During non-client builds, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in other environments build. It is responsibility of the framework to merge the assets with a post build step.
201+
195202
## build.ssrEmitAssets
196203

197204
- **Type:** `boolean`
198205
- **Default:** `false`
199206

200-
During the SSR build, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in both the client and SSR build. It is responsibility of the framework to merge the assets with a post build step.
207+
During the SSR build, static assets aren't emitted as it is assumed they would be emitted as part of the client build. This option allows frameworks to force emitting them in both the client and SSR build. It is responsibility of the framework to merge the assets with a post build step. This option will be replaced by `build.emitAssets` once Environment API is stable.
201208

202209
## build.minify
203210

docs/config/shared-options.md

+9
Original file line numberDiff line numberDiff line change
@@ -490,3 +490,12 @@ Whether your application is a Single Page Application (SPA), a [Multi Page Appli
490490
- `'custom'`: don't include HTML middlewares
491491

492492
Learn more in Vite's [SSR guide](/guide/ssr#vite-cli). Related: [`server.middlewareMode`](./server-options#server-middlewaremode).
493+
494+
## future
495+
496+
- **Type:** `Record<string, 'warn' | undefined>`
497+
- **Related:** [Breaking Changes](/changes/)
498+
499+
Enable future breaking changes to prepare for a smooth migration to the next major version of Vite. The list may be updated, added, or removed at any time as new features are developed.
500+
501+
See the [Breaking Changes](/changes/) page for details of the possible options.

0 commit comments

Comments
 (0)