Skip to content

Commit a626a62

Browse files
committed
chore: merge main
2 parents 2b87665 + e7a0c5e commit a626a62

File tree

113 files changed

+2764
-1737
lines changed

Some content is hidden

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

113 files changed

+2764
-1737
lines changed

docs/.vitepress/config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,11 @@ export default defineConfig({
486486
languages: ['ts', 'js', 'json'],
487487
codeTransformers: [transformerTwoslash()],
488488
config(md) {
489-
md.use(groupIconMdPlugin)
489+
md.use(groupIconMdPlugin, {
490+
titleBar: {
491+
includeSnippet: true,
492+
},
493+
})
490494
md.use(markdownItImageSize, {
491495
publicDir: path.resolve(import.meta.dirname, '../public'),
492496
})

docs/config/build-options.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,71 @@ export default defineConfig({
185185
})
186186
```
187187

188+
## build.license
189+
190+
- **Type:** `boolean | { fileName?: string }`
191+
- **Default:** `false`
192+
193+
When set to `true`, the build will generate a `.vite/license.md` file that includes all bundled dependencies' licenses. It can be hosted to display and acknowledge the dependencies used by the app. When `fileName` is passed, it will be used as the license file name relative to the `outDir`. An example output may look like this:
194+
195+
```md
196+
# Licenses
197+
198+
The app bundles dependencies which contain the following licenses:
199+
200+
## dep-1 - 1.2.3 (CC0-1.0)
201+
202+
CC0 1.0 Universal
203+
204+
...
205+
206+
## dep-2 - 4.5.6 (MIT)
207+
208+
MIT License
209+
210+
...
211+
```
212+
213+
If the `fileName` ends with `.json`, the raw JSON metadata will be generated instead and can be used for further processing. For example:
214+
215+
```json
216+
[
217+
{
218+
"name": "dep-1",
219+
"version": "1.2.3",
220+
"identifier": "CC0-1.0",
221+
"text": "CC0 1.0 Universal\n\n..."
222+
},
223+
{
224+
"name": "dep-2",
225+
"version": "4.5.6",
226+
"identifier": "MIT",
227+
"text": "MIT License\n\n..."
228+
}
229+
]
230+
```
231+
232+
::: tip
233+
If you'd like to reference the license file in the built code, you can use `build.rollupOptions.output.banner` to inject a comment at the top of the files. For example:
234+
235+
```js twoslash [vite.config.js]
236+
import { defineConfig } from 'vite'
237+
238+
export default defineConfig({
239+
build: {
240+
license: true,
241+
rollupOptions: {
242+
output: {
243+
banner:
244+
'/* See licenses of bundled dependencies at https://example.com/license.md */',
245+
},
246+
},
247+
},
248+
})
249+
```
250+
251+
:::
252+
188253
## build.manifest
189254

190255
- **Type:** `boolean | string`

docs/config/dep-optimization-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Unless noted, the options in this section are only applied to the dependency opt
1010

1111
By default, Vite will crawl all your `.html` files to detect dependencies that need to be pre-bundled (ignoring `node_modules`, `build.outDir`, `__tests__` and `coverage`). If `build.rollupOptions.input` is specified, Vite will crawl those entry points instead.
1212

13-
If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://github.com/SuperchupuDev/tinyglobby) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. `node_modules` will not be ignored for patterns that explicitly include the string `node_modules`.
13+
If neither of these fit your needs, you can specify custom entries using this option - the value should be a [`tinyglobby` pattern](https://superchupu.dev/tinyglobby/comparison) or array of patterns that are relative from Vite project root. This will overwrite default entries inference. Only `node_modules` and `build.outDir` folders will be ignored by default when `optimizeDeps.entries` is explicitly defined. If other folders need to be ignored, you can use an ignore pattern as part of the entries list, marked with an initial `!`. `node_modules` will not be ignored for patterns that explicitly include the string `node_modules`.
1414

1515
## optimizeDeps.exclude <NonInheritBadge />
1616

docs/config/server-options.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ Set to `true` to exit if port is already in use, instead of automatically trying
9292

9393
Enable TLS + HTTP/2. The value is an [options object](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) passed to `https.createServer()`.
9494

95-
Note that this downgrades to TLS only when the [`server.proxy` option](#server-proxy) is also used.
96-
9795
A valid certificate is needed. For a basic setup, you can add [@vitejs/plugin-basic-ssl](https://github.com/vitejs/vite-plugin-basic-ssl) to the project plugins, which will automatically create and cache a self-signed certificate. But we recommend creating your own certificates.
9896

9997
## server.open
@@ -233,7 +231,7 @@ The error that appears in the Browser when the fallback happens can be ignored.
233231

234232
Warm up files to transform and cache the results in advance. This improves the initial page load during server starts and prevents transform waterfalls.
235233

236-
`clientFiles` are files that are used in the client only, while `ssrFiles` are files that are used in SSR only. They accept an array of file paths or [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) patterns relative to the `root`.
234+
`clientFiles` are files that are used in the client only, while `ssrFiles` are files that are used in SSR only. They accept an array of file paths or [`tinyglobby` patterns](https://superchupu.dev/tinyglobby/comparison) relative to the `root`.
237235

238236
Make sure to only add files that are frequently used to not overload the Vite dev server on startup.
239237

docs/guide/api-environment-plugins.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ The hook can choose to:
146146
147147
## Per-environment State in Plugins
148148
149-
Given that the same plugin instance is used for different environments, the plugin state needs to be keyed with `this.environment`. This is the same pattern the ecosystem has already been using to keep state about modules using the `ssr` boolean as key to avoid mixing client and ssr modules state. A `Map<Environment, State>` can be used to keep the state for each environment separately. Note that for backward compatibility, `buildStart` and `buildEnd` are only called for the client environment without the `perEnvironmentStartEndDuringDev: true` flag.
149+
Given that the same plugin instance is used for different environments, the plugin state needs to be keyed with `this.environment`. This is the same pattern the ecosystem has already been using to keep state about modules using the `ssr` boolean as key to avoid mixing client and ssr modules state. A `Map<Environment, State>` can be used to keep the state for each environment separately. Note that for backward compatibility, `buildStart` and `buildEnd` are only called for the client environment without the `perEnvironmentStartEndDuringDev: true` flag. Same for `watchChange` and the `perEnvironmentWatchChangeDuringDev: true` flag.
150150
151151
```js
152152
function PerEnvironmentCountTransformedModulesPlugin() {
@@ -227,6 +227,43 @@ export default defineConfig({
227227
228228
The `applyToEnvironment` hook is called at config time, currently after `configResolved` due to projects in the ecosystem modifying the plugins in it. Environment plugins resolution may be moved before `configResolved` in the future.
229229
230+
## Application-Plugin Communication
231+
232+
`environment.hot` allows plugins to communicate with the code on the application side for a given environment. This is the equivalent of [the Client-server Communication feature](/guide/api-plugin#client-server-communication), but supports environments other than the client environment.
233+
234+
:::warning Note
235+
236+
Note that this feature is only available for environments that supports HMR.
237+
238+
:::
239+
240+
### Managing the Application Instances
241+
242+
Be aware that there might be multiple application instances running in the same environment. For example, if you multiple tabs open in the browser, each tab is a separate application instance and have a separate connection to the server.
243+
244+
When a new connection is established, a `vite:client:connect` event is emitted on the environment's `hot` instance. When the connection is closed, a `vite:client:disconnect` event is emitted.
245+
246+
Each event handler receives the `NormalizedHotChannelClient` as the second argument. The client is an object with a `send` method that can be used to send messages to that specific application instance. The client reference is always the same for the same connection, so you can keep it to track the connection.
247+
248+
### Example Usage
249+
250+
The plugin side:
251+
252+
```js
253+
configureServer(server) {
254+
server.environments.ssr.hot.on('my:greetings', (data, client) => {
255+
// do something with the data,
256+
// and optionally send a response to that application instance
257+
client.send('my:foo:reply', `Hello from server! You said: ${data}`)
258+
})
259+
260+
// broadcast a message to all application instances
261+
server.environments.ssr.hot.send('my:foo', 'Hello from server!')
262+
}
263+
```
264+
265+
The application side is same with the Client-server Communication feature. You can use the `import.meta.hot` object to send messages to the plugin.
266+
230267
## Environment in Build Hooks
231268
232269
In the same way as during dev, plugin hooks also receive the environment instance during build, replacing the `ssr` boolean.

docs/guide/api-environment-runtimes.md

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,27 +316,45 @@ import { createServer, RemoteEnvironmentTransport, DevEnvironment } from 'vite'
316316
function createWorkerEnvironment(name, config, context) {
317317
const worker = new Worker('./worker.js')
318318
const handlerToWorkerListener = new WeakMap()
319+
const client = {
320+
send(payload: HotPayload) {
321+
worker.postMessage(payload)
322+
},
323+
}
319324

320325
const workerHotChannel = {
321326
send: (data) => worker.postMessage(data),
322327
on: (event, handler) => {
323-
if (event === 'connection') return
328+
// client is already connected
329+
if (event === 'vite:client:connect') return
330+
if (event === 'vite:client:disconnect') {
331+
const listener = () => {
332+
handler(undefined, client)
333+
}
334+
handlerToWorkerListener.set(handler, listener)
335+
worker.on('exit', listener)
336+
return
337+
}
324338

325339
const listener = (value) => {
326340
if (value.type === 'custom' && value.event === event) {
327-
const client = {
328-
send(payload) {
329-
worker.postMessage(payload)
330-
},
331-
}
332341
handler(value.data, client)
333342
}
334343
}
335344
handlerToWorkerListener.set(handler, listener)
336345
worker.on('message', listener)
337346
},
338347
off: (event, handler) => {
339-
if (event === 'connection') return
348+
if (event === 'vite:client:connect') return
349+
if (event === 'vite:client:disconnect') {
350+
const listener = handlerToWorkerListener.get(handler)
351+
if (listener) {
352+
worker.off('exit', listener)
353+
handlerToWorkerListener.delete(handler)
354+
}
355+
return
356+
}
357+
340358
const listener = handlerToWorkerListener.get(handler)
341359
if (listener) {
342360
worker.off('message', listener)
@@ -363,6 +381,8 @@ await createServer({
363381

364382
:::
365383

384+
Make sure to implement the `vite:client:connect` / `vite:client:disconnect` events in the `on` / `off` methods when those methods exist. `vite:client:connect` event should be emitted when the connection is established, and `vite:client:disconnect` event should be emitted when the connection is closed. The `HotChannelClient` object passed to the event handler must have the same reference for the same connection.
385+
366386
A different example using an HTTP request to communicate between the runner and the server:
367387

368388
```ts

docs/guide/features.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ Note that:
619619

620620
- This is a Vite-only feature and is not a web or ES standard.
621621
- The glob patterns are treated like import specifiers: they must be either relative (start with `./`) or absolute (start with `/`, resolved relative to project root) or an alias path (see [`resolve.alias` option](/config/shared-options.md#resolve-alias)).
622-
- The glob matching is done via [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby).
622+
- The glob matching is done via [`tinyglobby`](https://github.com/SuperchupuDev/tinyglobby) - check out its documentation for [supported glob patterns](https://superchupu.dev/tinyglobby/comparison).
623623
- You should also be aware that all the arguments in the `import.meta.glob` must be **passed as literals**. You can NOT use variables or expressions in them.
624624

625625
## Dynamic Import

docs/guide/rolldown.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,4 @@ const plugin = {
345345
}
346346
```
347347

348-
This is because [Rolldown supports non-JavaScript modules](https://rolldown.rs/guide/in-depth/module-types) and infers the module type from extensions unless specified.
348+
This is because [Rolldown supports non-JavaScript modules](https://rolldown.rs/in-depth/module-types) and infers the module type from extensions unless specified.

docs/guide/static-deploy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Now the `preview` command will launch the server at `http://localhost:8080`.
6363

6464
2. Go to your GitHub Pages configuration in the repository settings page and choose the source of deployment as "GitHub Actions", this will lead you to create a workflow that builds and deploys your project, a sample workflow that installs dependencies and builds using npm is provided:
6565

66-
<<< ./static-deploy-github-pages.yaml#content
66+
<<< ./static-deploy-github-pages.yaml#content [.github/workflows/deploy.yml]
6767

6868
## GitLab Pages and GitLab CI
6969

docs/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
"docs-serve": "vitepress serve"
1010
},
1111
"devDependencies": {
12-
"@shikijs/vitepress-twoslash": "^3.13.0",
13-
"@types/express": "^5.0.3",
12+
"@shikijs/vitepress-twoslash": "^3.14.0",
13+
"@types/express": "^5.0.4",
1414
"feed": "^5.1.0",
1515
"gsap": "^3.13.0",
1616
"markdown-it-image-size": "^15.0.1",
1717
"oxc-minify": "^0.95.0",
1818
"vitepress": "^2.0.0-alpha.12",
19-
"vitepress-plugin-group-icons": "^1.6.4",
20-
"vitepress-plugin-llms": "^1.8.0",
19+
"vitepress-plugin-group-icons": "^1.6.5",
20+
"vitepress-plugin-llms": "^1.8.1",
2121
"vue": "^3.5.22",
22-
"vue-tsc": "^3.1.1"
22+
"vue-tsc": "^3.1.2"
2323
}
2424
}

0 commit comments

Comments
 (0)