From fe482220a874919e30df12bbbf8c8b85a3502db2 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 12:23:20 +0900 Subject: [PATCH 1/6] fix(deps): update all non-major dependencies (#21008) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com> --- package.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 6a95a1d6..ace62005 100644 --- a/package.json +++ b/package.json @@ -9,15 +9,15 @@ "docs-serve": "vitepress serve" }, "devDependencies": { - "@shikijs/vitepress-twoslash": "^3.13.0", - "@types/express": "^5.0.3", + "@shikijs/vitepress-twoslash": "^3.14.0", + "@types/express": "^5.0.4", "feed": "^5.1.0", "gsap": "^3.13.0", "markdown-it-image-size": "^15.0.1", "vitepress": "^2.0.0-alpha.12", - "vitepress-plugin-group-icons": "^1.6.4", - "vitepress-plugin-llms": "^1.8.0", + "vitepress-plugin-group-icons": "^1.6.5", + "vitepress-plugin-llms": "^1.8.1", "vue": "^3.5.22", - "vue-tsc": "^3.1.1" + "vue-tsc": "^3.1.2" } } From 8b6c4ea7b58dd70b54831e4253f7ff8eec2dd7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Mon, 27 Oct 2025 20:21:22 +0900 Subject: [PATCH 2/6] feat: add vite client connect events (#20978) --- guide/api-environment-plugins.md | 37 +++++++++++++++++++++++++++++++ guide/api-environment-runtimes.md | 34 ++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 7 deletions(-) diff --git a/guide/api-environment-plugins.md b/guide/api-environment-plugins.md index 7a888cc2..ebe35341 100644 --- a/guide/api-environment-plugins.md +++ b/guide/api-environment-plugins.md @@ -227,6 +227,43 @@ export default defineConfig({ 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. +## Application-Plugin Communication + +`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. + +:::warning Note + +Note that this feature is only available for environments that supports HMR. + +::: + +### Managing the Application Instances + +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. + +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. + +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. + +### Example Usage + +The plugin side: + +```js +configureServer(server) { + server.environments.ssr.hot.on('my:greetings', (data, client) => { + // do something with the data, + // and optionally send a response to that application instance + client.send('my:foo:reply', `Hello from server! You said: ${data}`) + }) + + // broadcast a message to all application instances + server.environments.ssr.hot.send('my:foo', 'Hello from server!') +} +``` + +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. + ## Environment in Build Hooks In the same way as during dev, plugin hooks also receive the environment instance during build, replacing the `ssr` boolean. diff --git a/guide/api-environment-runtimes.md b/guide/api-environment-runtimes.md index b887b1ad..e09076a0 100644 --- a/guide/api-environment-runtimes.md +++ b/guide/api-environment-runtimes.md @@ -316,19 +316,28 @@ import { createServer, RemoteEnvironmentTransport, DevEnvironment } from 'vite' function createWorkerEnvironment(name, config, context) { const worker = new Worker('./worker.js') const handlerToWorkerListener = new WeakMap() + const client = { + send(payload: HotPayload) { + worker.postMessage(payload) + }, + } const workerHotChannel = { send: (data) => worker.postMessage(data), on: (event, handler) => { - if (event === 'connection') return + // client is already connected + if (event === 'vite:client:connect') return + if (event === 'vite:client:disconnect') { + const listener = () => { + handler(undefined, client) + } + handlerToWorkerListener.set(handler, listener) + worker.on('exit', listener) + return + } const listener = (value) => { if (value.type === 'custom' && value.event === event) { - const client = { - send(payload) { - worker.postMessage(payload) - }, - } handler(value.data, client) } } @@ -336,7 +345,16 @@ function createWorkerEnvironment(name, config, context) { worker.on('message', listener) }, off: (event, handler) => { - if (event === 'connection') return + if (event === 'vite:client:connect') return + if (event === 'vite:client:disconnect') { + const listener = handlerToWorkerListener.get(handler) + if (listener) { + worker.off('exit', listener) + handlerToWorkerListener.delete(handler) + } + return + } + const listener = handlerToWorkerListener.get(handler) if (listener) { worker.off('message', listener) @@ -363,6 +381,8 @@ await createServer({ ::: +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. + A different example using an HTTP request to communicate between the runner and the server: ```ts From 93e0fe19a66a2baab70ae2ab9be107a636baa2e1 Mon Sep 17 00:00:00 2001 From: Beverly Nguyen Date: Mon, 27 Oct 2025 20:26:06 +0900 Subject: [PATCH 3/6] docs(static-deploy): add workflow file location for GitHub Pages (#21004) --- .vitepress/config.ts | 6 +++++- guide/static-deploy.md | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.vitepress/config.ts b/.vitepress/config.ts index 7e11cfea..bc9f1aff 100644 --- a/.vitepress/config.ts +++ b/.vitepress/config.ts @@ -486,7 +486,11 @@ export default defineConfig({ languages: ['ts', 'js', 'json'], codeTransformers: [transformerTwoslash()], config(md) { - md.use(groupIconMdPlugin) + md.use(groupIconMdPlugin, { + titleBar: { + includeSnippet: true, + }, + }) md.use(markdownItImageSize, { publicDir: path.resolve(import.meta.dirname, '../public'), }) diff --git a/guide/static-deploy.md b/guide/static-deploy.md index 6de7c37b..d56f245d 100644 --- a/guide/static-deploy.md +++ b/guide/static-deploy.md @@ -63,7 +63,7 @@ Now the `preview` command will launch the server at `http://localhost:8080`. 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: - <<< ./static-deploy-github-pages.yaml#content + <<< ./static-deploy-github-pages.yaml#content [.github/workflows/deploy.yml] ## GitLab Pages and GitLab CI From 4932528a1ee790ca17435b194b04cf43e5f10fa8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0?= Date: Mon, 27 Oct 2025 20:35:50 +0900 Subject: [PATCH 4/6] feat: add `perEnvironmentWatchChangeDuringDev` (#20996) --- guide/api-environment-plugins.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guide/api-environment-plugins.md b/guide/api-environment-plugins.md index ebe35341..5b196963 100644 --- a/guide/api-environment-plugins.md +++ b/guide/api-environment-plugins.md @@ -146,7 +146,7 @@ The hook can choose to: ## Per-environment State in Plugins -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` 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. +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` 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. ```js function PerEnvironmentCountTransformedModulesPlugin() { From 745c90a90225b682986264c242b2bda637e8047d Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Tue, 28 Oct 2025 20:35:36 +0800 Subject: [PATCH 5/6] resolved deps --- package.json | 34 +------ pnpm-lock.yaml | 258 +++++++++++++++++-------------------------------- 2 files changed, 96 insertions(+), 196 deletions(-) diff --git a/package.json b/package.json index 6bd3fb2f..c99f75d5 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,4 @@ { -<<<<<<< HEAD "name": "vite-docs-cn", "version": "1.0.0", "description": "Vite.js documentation Chinese translation.", @@ -9,9 +8,9 @@ "private": true, "license": "CC BY-NC-SA 4.0", "devDependencies": { - "@shikijs/vitepress-twoslash": "^3.13.0", + "@shikijs/vitepress-twoslash": "^3.14.0", "@type-challenges/utils": "^0.1.1", - "@types/express": "^5.0.3", + "@types/express": "^5.0.4", "@types/node": "^20.9.2", "chalk": "^4.1.2", "feed": "^5.1.0", @@ -21,10 +20,10 @@ "markdown-it-image-size": "^15.0.1", "vite": "^7.0.4", "vitepress": "^2.0.0-alpha.7", - "vitepress-plugin-group-icons": "^1.6.4", - "vitepress-plugin-llms": "^1.8.0", + "vitepress-plugin-group-icons": "^1.6.5", + "vitepress-plugin-llms": "^1.8.1", "vue": "^3.5.22", - "vue-tsc": "^3.1.1", + "vue-tsc": "^3.1.2", "yorkie": "^2.0.0" }, "packageManager": "pnpm@9.6.0", @@ -40,27 +39,4 @@ "gitHooks": { "commit-msg": "node scripts/verifyCommit.js" } -======= - "name": "@vitejs/monorepo-docs", - "private": true, - "type": "module", - "scripts": { - "typecheck": "vue-tsc", - "docs": "vitepress dev", - "docs-build": "vitepress build", - "docs-serve": "vitepress serve" - }, - "devDependencies": { - "@shikijs/vitepress-twoslash": "^3.14.0", - "@types/express": "^5.0.4", - "feed": "^5.1.0", - "gsap": "^3.13.0", - "markdown-it-image-size": "^15.0.1", - "vitepress": "^2.0.0-alpha.12", - "vitepress-plugin-group-icons": "^1.6.5", - "vitepress-plugin-llms": "^1.8.1", - "vue": "^3.5.22", - "vue-tsc": "^3.1.2" - } ->>>>>>> 4932528a1ee790ca17435b194b04cf43e5f10fa8 } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f6622697..f7b90d43 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -9,14 +9,14 @@ importers: .: devDependencies: '@shikijs/vitepress-twoslash': - specifier: ^3.13.0 - version: 3.13.0(typescript@5.4.5) + specifier: ^3.14.0 + version: 3.14.0(typescript@5.4.5) '@type-challenges/utils': specifier: ^0.1.1 version: 0.1.1 '@types/express': - specifier: ^5.0.3 - version: 5.0.3 + specifier: ^5.0.4 + version: 5.0.5 '@types/node': specifier: ^20.9.2 version: 20.12.12 @@ -45,17 +45,17 @@ importers: specifier: ^2.0.0-alpha.7 version: 2.0.0-alpha.7(@algolia/client-search@5.20.0)(@types/node@20.12.12)(postcss@8.5.6)(search-insights@2.13.0)(typescript@5.4.5) vitepress-plugin-group-icons: - specifier: ^1.6.4 - version: 1.6.4(markdown-it@14.1.0)(vite@7.0.4(@types/node@20.12.12)) + specifier: ^1.6.5 + version: 1.6.5(vite@7.0.4(@types/node@20.12.12)) vitepress-plugin-llms: - specifier: ^1.8.0 - version: 1.8.0 + specifier: ^1.8.1 + version: 1.8.1 vue: specifier: ^3.5.22 version: 3.5.22(typescript@5.4.5) vue-tsc: - specifier: ^3.1.1 - version: 3.1.1(typescript@5.4.5) + specifier: ^3.1.2 + version: 3.1.2(typescript@5.4.5) yorkie: specifier: ^2.0.0 version: 2.0.0 @@ -148,20 +148,11 @@ packages: resolution: {integrity: sha512-D2hP9eA+Sqx1kBZgzxZh0y1trbuU+JoDkiEwqhQ36nodYqJwyEIhPSdMNd7lOm/4io72luTPWH20Yda0xOuUow==} engines: {node: '>=6.9.0'} - '@babel/parser@7.28.3': - resolution: {integrity: sha512-7+Ey1mAgYqFAx2h0RuoxcQT5+MlG3GTV0TQrgr7/ZliKsm/MNDxVVutlWaziMq7wJNAz8MTqz55XLpWvva6StA==} - engines: {node: '>=6.0.0'} - hasBin: true - '@babel/parser@7.28.4': resolution: {integrity: sha512-yZbBqeM6TkpP9du/I2pUZnJsRMGGvOuIrhjzC1AwHwW+6he4mni6Bp/m8ijn0iOuZuPI2BfkCoSRunpyjnrQKg==} engines: {node: '>=6.0.0'} hasBin: true - '@babel/types@7.28.2': - resolution: {integrity: sha512-ruv7Ae4J5dUYULmeXw1gmb7rYRz57OWCPM57pHojnLq/3Z1CK2lNSLTCVjxVk1F/TZHwOZZrOWi0ur95BbLxNQ==} - engines: {node: '>=6.9.0'} - '@babel/types@7.28.4': resolution: {integrity: sha512-bkFqkLhh3pMBUQQkpVgWDWq/lqzc2678eUyDlTBhRqhCHFguYYGM0Efga7tYk4TogG/3x0EEl66/OQ+WGbWB/Q==} engines: {node: '>=6.9.0'} @@ -504,32 +495,32 @@ packages: cpu: [x64] os: [win32] - '@shikijs/core@3.13.0': - resolution: {integrity: sha512-3P8rGsg2Eh2qIHekwuQjzWhKI4jV97PhvYjYUzGqjvJfqdQPz+nMlfWahU24GZAyW1FxFI1sYjyhfh5CoLmIUA==} + '@shikijs/core@3.14.0': + resolution: {integrity: sha512-qRSeuP5vlYHCNUIrpEBQFO7vSkR7jn7Kv+5X3FO/zBKVDGQbcnlScD3XhkrHi/R8Ltz0kEjvFR9Szp/XMRbFMw==} '@shikijs/core@3.7.0': resolution: {integrity: sha512-yilc0S9HvTPyahHpcum8eonYrQtmGTU0lbtwxhA6jHv4Bm1cAdlPFRCJX4AHebkCm75aKTjjRAW+DezqD1b/cg==} - '@shikijs/engine-javascript@3.13.0': - resolution: {integrity: sha512-Ty7xv32XCp8u0eQt8rItpMs6rU9Ki6LJ1dQOW3V/56PKDcpvfHPnYFbsx5FFUP2Yim34m/UkazidamMNVR4vKg==} + '@shikijs/engine-javascript@3.14.0': + resolution: {integrity: sha512-3v1kAXI2TsWQuwv86cREH/+FK9Pjw3dorVEykzQDhwrZj0lwsHYlfyARaKmn6vr5Gasf8aeVpb8JkzeWspxOLQ==} '@shikijs/engine-javascript@3.7.0': resolution: {integrity: sha512-0t17s03Cbv+ZcUvv+y33GtX75WBLQELgNdVghnsdhTgU3hVcWcMsoP6Lb0nDTl95ZJfbP1mVMO0p3byVh3uuzA==} - '@shikijs/engine-oniguruma@3.13.0': - resolution: {integrity: sha512-O42rBGr4UDSlhT2ZFMxqM7QzIU+IcpoTMzb3W7AlziI1ZF7R8eS2M0yt5Ry35nnnTX/LTLXFPUjRFCIW+Operg==} + '@shikijs/engine-oniguruma@3.14.0': + resolution: {integrity: sha512-TNcYTYMbJyy+ZjzWtt0bG5y4YyMIWC2nyePz+CFMWqm+HnZZyy9SWMgo8Z6KBJVIZnx8XUXS8U2afO6Y0g1Oug==} '@shikijs/engine-oniguruma@3.7.0': resolution: {integrity: sha512-5BxcD6LjVWsGu4xyaBC5bu8LdNgPCVBnAkWTtOCs/CZxcB22L8rcoWfv7Hh/3WooVjBZmFtyxhgvkQFedPGnFw==} - '@shikijs/langs@3.13.0': - resolution: {integrity: sha512-672c3WAETDYHwrRP0yLy3W1QYB89Hbpj+pO4KhxK6FzIrDI2FoEXNiNCut6BQmEApYLfuYfpgOZaqbY+E9b8wQ==} + '@shikijs/langs@3.14.0': + resolution: {integrity: sha512-DIB2EQY7yPX1/ZH7lMcwrK5pl+ZkP/xoSpUzg9YC8R+evRCCiSQ7yyrvEyBsMnfZq4eBzLzBlugMyTAf13+pzg==} '@shikijs/langs@3.7.0': resolution: {integrity: sha512-1zYtdfXLr9xDKLTGy5kb7O0zDQsxXiIsw1iIBcNOO8Yi5/Y1qDbJ+0VsFoqTlzdmneO8Ij35g7QKF8kcLyznCQ==} - '@shikijs/themes@3.13.0': - resolution: {integrity: sha512-Vxw1Nm1/Od8jyA7QuAenaV78BG2nSr3/gCGdBkLpfLscddCkzkL36Q5b67SrLLfvAJTOUzW39x4FHVCFriPVgg==} + '@shikijs/themes@3.14.0': + resolution: {integrity: sha512-fAo/OnfWckNmv4uBoUu6dSlkcBc+SA1xzj5oUSaz5z3KqHtEbUypg/9xxgJARtM6+7RVm0Q6Xnty41xA1ma1IA==} '@shikijs/themes@3.7.0': resolution: {integrity: sha512-VJx8497iZPy5zLiiCTSIaOChIcKQwR0FebwE9S3rcN0+J/GTWwQ1v/bqhTbpbY3zybPKeO8wdammqkpXc4NVjQ==} @@ -537,19 +528,19 @@ packages: '@shikijs/transformers@3.7.0': resolution: {integrity: sha512-VplaqIMRNsNOorCXJHkbF5S0pT6xm8Z/s7w7OPZLohf8tR93XH0krvUafpNy/ozEylrWuShJF0+ftEB+wFRwGA==} - '@shikijs/twoslash@3.13.0': - resolution: {integrity: sha512-OmNKNoZ8Hevt4VKQHfJL+hrsrqLSnW/Nz7RMutuBqXBCIYZWk80HnF9pcXEwRmy9MN0MGRmZCW2rDDP8K7Bxkw==} + '@shikijs/twoslash@3.14.0': + resolution: {integrity: sha512-Eh8Kg9ZZF+kY5zLFrnkA8iFNWZ8L25g2B5sviHwyx6G38pVDSIBpNmchHnx5qS8lUCNtt/Os3S5VmC0JBEDz+A==} peerDependencies: typescript: '>=5.5.0' - '@shikijs/types@3.13.0': - resolution: {integrity: sha512-oM9P+NCFri/mmQ8LoFGVfVyemm5Hi27330zuOBp0annwJdKH1kOLndw3zCtAVDehPLg9fKqoEx3Ht/wNZxolfw==} + '@shikijs/types@3.14.0': + resolution: {integrity: sha512-bQGgC6vrY8U/9ObG1Z/vTro+uclbjjD/uG58RvfxKZVD5p9Yc1ka3tVyEFy7BNJLzxuWyHH5NWynP9zZZS59eQ==} '@shikijs/types@3.7.0': resolution: {integrity: sha512-MGaLeaRlSWpnP0XSAum3kP3a8vtcTsITqoEPYdt3lQG3YCdQH4DnEhodkYcNMcU0uW0RffhoD1O3e0vG5eSBBg==} - '@shikijs/vitepress-twoslash@3.13.0': - resolution: {integrity: sha512-YwL/Wsyl1Vfg9wcWFJbpqKn7vySaCKNsSxYL3v5J/z+7Qm+fu15JXrtqEJbT8h/STWeaO7pnR6npgoPQEj8Ewg==} + '@shikijs/vitepress-twoslash@3.14.0': + resolution: {integrity: sha512-kH8LyK2h6taXsCKQdKSoccWzo3hg/rYmK05gE0pr14W3fn5wlnqXU3RDZGoToLbHR4uUdeGRiw+MEikemVImDQ==} '@shikijs/vscode-textmate@10.0.2': resolution: {integrity: sha512-83yeghZ2xxin3Nj8z1NMd/NCuca+gsYXswywDy5bHvwlWL8tpTQmzGeUuHd9FC3E/SBEMvzJRwWEOz5gGes9Qg==} @@ -572,8 +563,8 @@ packages: '@types/express-serve-static-core@5.0.6': resolution: {integrity: sha512-3xhRnjJPkULekpSzgtoNYYcTWgEZkp4myc+Saevii5JPnHNvHMRlBSHDbs7Bh1iPPoVTERHEZXyhyLbMEsExsA==} - '@types/express@5.0.3': - resolution: {integrity: sha512-wGA0NX93b19/dZC1J18tKWVIYWyyF2ZjT9vin/NRu0qzzvfVzWjs04iq2rQ3H65vCTQYlRqs3YHfY7zjdV+9Kw==} + '@types/express@5.0.5': + resolution: {integrity: sha512-LuIQOcb6UmnF7C1PCFmEU1u2hmiHL43fgFQX67sN3H4Z+0Yk0Neo++mFsBjhOAuLzvlQeqAAkeDOZrJs9rzumQ==} '@types/hast@3.0.4': resolution: {integrity: sha512-WPs+bbQw5aCj+x6laNGWLH3wviHtoCv/P3+otBhbOhJgG8qtpdAMlTCxLtsTWA7LH1Oh/bFCHsBn0TPS5m30EQ==} @@ -644,15 +635,9 @@ packages: '@volar/typescript@2.4.23': resolution: {integrity: sha512-lAB5zJghWxVPqfcStmAP1ZqQacMpe90UrP5RJ3arDyrhy4aCUQqmxPPLB2PWDKugvylmO41ljK7vZ+t6INMTag==} - '@vue/compiler-core@3.5.21': - resolution: {integrity: sha512-8i+LZ0vf6ZgII5Z9XmUvrCyEzocvWT+TeR2VBUVlzIH6Tyv57E20mPZ1bCS+tbejgUgmjrEh7q/0F0bibskAmw==} - '@vue/compiler-core@3.5.22': resolution: {integrity: sha512-jQ0pFPmZwTEiRNSb+i9Ow/I/cHv2tXYqsnHKKyCQ08irI2kdF5qmYedmF8si8mA7zepUFmJ2hqzS8CQmNOWOkQ==} - '@vue/compiler-dom@3.5.21': - resolution: {integrity: sha512-jNtbu/u97wiyEBJlJ9kmdw7tAr5Vy0Aj5CgQmo+6pxWNQhXZDPsRr1UWPN4v3Zf82s2H3kF51IbzZ4jMWAgPlQ==} - '@vue/compiler-dom@3.5.22': resolution: {integrity: sha512-W8RknzUM1BLkypvdz10OVsGxnMAuSIZs9Wdx1vzA3mL5fNMN15rhrSCLiTm6blWeACwUwizzPVqGJgOGBEN/hA==} @@ -662,9 +647,6 @@ packages: '@vue/compiler-ssr@3.5.22': resolution: {integrity: sha512-GdgyLvg4R+7T8Nk2Mlighx7XGxq/fJf9jaVofc3IL0EPesTE86cP/8DD1lT3h1JeZr2ySBvyqKQJgbS54IX1Ww==} - '@vue/compiler-vue2@2.7.16': - resolution: {integrity: sha512-qYC3Psj9S/mfu9uVi5WvNZIzq+xnXMhOwbTFKKDD7b1lhpnn71jXSFdTQ+WsIEk0ONCd7VV2IMm7ONl6tbQ86A==} - '@vue/devtools-api@7.7.7': resolution: {integrity: sha512-lwOnNBH2e7x1fIIbVT7yF5D+YWhqELm55/4ZKf45R9T8r9dE2AIOy8HKjfqzGsoTHFbWbr337O4E0A0QADnjBg==} @@ -674,16 +656,16 @@ packages: '@vue/devtools-shared@7.7.7': resolution: {integrity: sha512-+udSj47aRl5aKb0memBvcUG9koarqnxNM5yjuREvqwK6T3ap4mn3Zqqc17QrBFTqSMjr3HK1cvStEZpMDpfdyw==} - '@vue/language-core@3.0.7': - resolution: {integrity: sha512-0sqqyqJ0Gn33JH3TdIsZLCZZ8Gr4kwlg8iYOnOrDDkJKSjFurlQY/bEFQx5zs7SX2C/bjMkmPYq/NiyY1fTOkw==} + '@vue/language-core@3.1.1': + resolution: {integrity: sha512-qjMY3Q+hUCjdH+jLrQapqgpsJ0rd/2mAY02lZoHG3VFJZZZKLjAlV+Oo9QmWIT4jh8+Rx8RUGUi++d7T9Wb6Mw==} peerDependencies: typescript: '*' peerDependenciesMeta: typescript: optional: true - '@vue/language-core@3.1.1': - resolution: {integrity: sha512-qjMY3Q+hUCjdH+jLrQapqgpsJ0rd/2mAY02lZoHG3VFJZZZKLjAlV+Oo9QmWIT4jh8+Rx8RUGUi++d7T9Wb6Mw==} + '@vue/language-core@3.1.2': + resolution: {integrity: sha512-PyFDCqpdfYUT+oMLqcc61oHfJlC6yjhybaefwQjRdkchIihToOEpJ2Wu/Ebq2yrnJdd1EsaAvZaXVAqcxtnDxQ==} peerDependencies: typescript: '*' peerDependenciesMeta: @@ -707,9 +689,6 @@ packages: '@vue/shared@3.5.17': resolution: {integrity: sha512-CabR+UN630VnsJO/jHWYBC1YVXyMq94KKp6iF5MQgZJs5I8cmjw6oVMO1oDbtBkENSHSSn/UadWlW/OAgdmKrg==} - '@vue/shared@3.5.21': - resolution: {integrity: sha512-+2k1EQpnYuVuu3N7atWyG3/xoFWIVJZq4Mz8XNOdScFI0etES75fbny/oU4lKWk/577P1zmg0ioYvpGEDZ3DLw==} - '@vue/shared@3.5.22': resolution: {integrity: sha512-F4yc6palwq3TT0u+FYf0Ns4Tfl9GRFURDN2gWG7L1ecIaS/4fCIuFOjMTnCyjsu/OK6vaDKLCrGAa+KvvH+h4w==} @@ -777,9 +756,6 @@ packages: resolution: {integrity: sha512-groO71Fvi5SWpxjI9Ia+chy0QBwT61mg6yxJV27f5YFf+Mw+STT75K6SHySpP8Co5LsCrtsbCH5dJZSRtkSKaQ==} engines: {node: '>= 14.0.0'} - alien-signals@2.0.6: - resolution: {integrity: sha512-P3TxJSe31bUHBiblg59oU1PpaWPtmxF9GhJ/cB7OkgJ0qN/ifFSKUI25/v8ZhsT+lIG6ac8DpTOplXxORX6F3Q==} - alien-signals@3.0.0: resolution: {integrity: sha512-JHoRJf18Y6HN4/KZALr3iU+0vW9LKG+8FMThQlbn4+gv8utsLIkwpomjElGPccGeNwh0FI2HN6BLnyFLo6OyLQ==} @@ -855,18 +831,6 @@ packages: csstype@3.1.3: resolution: {integrity: sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==} - de-indent@1.0.2: - resolution: {integrity: sha512-e/1zu3xH5MQryN2zdVaF0OrdNLUbvWxzMbi+iNA6Bky7l1RoP8a2fIbRocyHclXt/arDrrR6lL3TqFD9pMQTsg==} - - debug@4.4.0: - resolution: {integrity: sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==} - engines: {node: '>=6.0'} - peerDependencies: - supports-color: '*' - peerDependenciesMeta: - supports-color: - optional: true - debug@4.4.3: resolution: {integrity: sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==} engines: {node: '>=6.0'} @@ -999,10 +963,6 @@ packages: hast-util-whitespace@3.0.0: resolution: {integrity: sha512-88JUN06ipLwsnv+dVn+OIYOvAuvBMy/Qoi6O7mQHxdPXpjy+Cd6xRkWwux7DKO+4sYILtLBRIKgsdpS2gQc7qw==} - he@1.2.0: - resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} - hasBin: true - hookable@5.5.3: resolution: {integrity: sha512-Yc+BQe8SvoXH1643Qez1zqLRmbA5rCL+sSmk6TVos0LWVfNIB7PGncdlId77WzLGSIB5KaWgTaNTs2lNVEI6VQ==} @@ -1081,6 +1041,9 @@ packages: magic-string@0.30.19: resolution: {integrity: sha512-2N21sPY9Ws53PZvsEpVtNuSW+ScYbQdp4b9qUaL+9QkHUrGFKo56Lg9Emg5s9V/qrtNBmiR01sYhUOwu3H+VOw==} + magic-string@0.30.21: + resolution: {integrity: sha512-vd2F4YUyEXKGcLHoq+TEyCjxueSeHnFxyyjNp80yg0XV4vUhnDer/lvvlqM/arB5bXQN5K2/3oinyCRyx8T2CQ==} + mark.js@8.11.1: resolution: {integrity: sha512-1I+1qpDt4idfgLQG+BNWmrqku+7/2bi5nLf4YwF8y8zXvmfiTBY3PV3ZibfrjBueCByROpuBjLLFCajqkgYoLQ==} @@ -1283,9 +1246,6 @@ packages: path-to-regexp@8.3.0: resolution: {integrity: sha512-7jdwVIRtsP8MYpdXSwOS0YdD0Du+qOoF/AEPIt88PcCFrZCzx41oxku1jD88hZBwbNUIEfpqvuhjFaMAqMTWnA==} - pathe@2.0.2: - resolution: {integrity: sha512-15Ztpk+nov8DR524R4BF7uEuzESgzUEAV4Ah7CUMNGXdE5ELuvxElxGXndBl32vMSsWa1jpNf22Z+Er3sKwq+w==} - pathe@2.0.3: resolution: {integrity: sha512-WUjGcAqP1gQacoQe+OBJsFA7Ld4DyXuUIjZ5cc75cLHvJ7dtNsTugphxIADwspS+AraAUePCKrSVtPLFj/F88w==} @@ -1384,8 +1344,8 @@ packages: resolution: {integrity: sha512-wpoSFAxys6b2a2wHZ1XpDSgD7N9iVjg29Ph9uV/uaP9Ex/KXlkTZTeddxDPSYQpgvzKLGJke2UU0AzoGCjNIvQ==} engines: {node: '>=0.10.0'} - shiki@3.13.0: - resolution: {integrity: sha512-aZW4l8Og16CokuCLf8CF8kq+KK2yOygapU5m3+hoGw0Mdosc6fPitjM+ujYarppj5ZIKGyPDPP1vqmQhr+5/0g==} + shiki@3.14.0: + resolution: {integrity: sha512-J0yvpLI7LSig3Z3acIuDLouV5UCKQqu8qOArwMx+/yPVC3WRMgrP67beaG8F+j4xfEWE0eVC4GeBCIXeOPra1g==} shiki@3.7.0: resolution: {integrity: sha512-ZcI4UT9n6N2pDuM2n3Jbk0sR4Swzq43nLPgS/4h0E3B/NrFn2HKElrDtceSf8Zx/OWYOo7G1SAtBLypCp+YXqg==} @@ -1558,14 +1518,16 @@ packages: yaml: optional: true - vitepress-plugin-group-icons@1.6.4: - resolution: {integrity: sha512-YCFH0G2zTX/me51wooWy4SvaaA6VKjIxLoWDU9ON4rFx9907Yf9ZpCpa4JpwloVuvm5+82fqLXSuZ98EJ92UUQ==} + vitepress-plugin-group-icons@1.6.5: + resolution: {integrity: sha512-+pg4+GKDq2fLqKb1Sat5p1p4SuIZ5tEPxu8HjpwoeecZ/VaXKy6Bdf0wyjedjaTAyZQzXbvyavJegqAcQ+B0VA==} peerDependencies: - markdown-it: '>=14' vite: '>=3' + peerDependenciesMeta: + vite: + optional: true - vitepress-plugin-llms@1.8.0: - resolution: {integrity: sha512-JQR2j+4OpB0GlmXSJCdTHYIx4AcOZ0LVLRwQVId1wvNRRRGTVs17S5YkBNV0oj8t0zTgJ+TE61f58CJC8CTe4w==} + vitepress-plugin-llms@1.8.1: + resolution: {integrity: sha512-Bxf7tbCvfNyANMip2cSydBQ14mV3c1t+1kqTd26CgMjehYtD7s4ANQ465OMLxw1apnT37PCktyXdLi3TWWihQA==} vitepress@2.0.0-alpha.7: resolution: {integrity: sha512-75xXvCWymnSgA7BFt1BmiXnusl4aeV4sM6DpIo9sf2OvkNER3cMLWN6xqZrLGu3SNaQccfS5u3ikCqAnA4p70w==} @@ -1590,8 +1552,8 @@ packages: peerDependencies: vue: ^3.0.0 - vue-tsc@3.1.1: - resolution: {integrity: sha512-fyixKxFniOVgn+L/4+g8zCG6dflLLt01Agz9jl3TO45Bgk87NZJRmJVPsiK+ouq3LB91jJCbOV+pDkzYTxbI7A==} + vue-tsc@3.1.2: + resolution: {integrity: sha512-3fd4DY0rFczs5f+VB3OhcLU83V6+3Puj2yLBe0Ak65k7ERk+STVNKaOAi0EBo6Lc15UiJB6LzU6Mxy4+h/pKew==} hasBin: true peerDependencies: typescript: '>=5.0.0' @@ -1762,19 +1724,10 @@ snapshots: '@babel/helper-validator-identifier@7.27.1': {} - '@babel/parser@7.28.3': - dependencies: - '@babel/types': 7.28.2 - '@babel/parser@7.28.4': dependencies: '@babel/types': 7.28.4 - '@babel/types@7.28.2': - dependencies: - '@babel/helper-string-parser': 7.27.1 - '@babel/helper-validator-identifier': 7.27.1 - '@babel/types@7.28.4': dependencies: '@babel/helper-string-parser': 7.27.1 @@ -2008,9 +1961,9 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.44.0': optional: true - '@shikijs/core@3.13.0': + '@shikijs/core@3.14.0': dependencies: - '@shikijs/types': 3.13.0 + '@shikijs/types': 3.14.0 '@shikijs/vscode-textmate': 10.0.2 '@types/hast': 3.0.4 hast-util-to-html: 9.0.5 @@ -2022,9 +1975,9 @@ snapshots: '@types/hast': 3.0.4 hast-util-to-html: 9.0.5 - '@shikijs/engine-javascript@3.13.0': + '@shikijs/engine-javascript@3.14.0': dependencies: - '@shikijs/types': 3.13.0 + '@shikijs/types': 3.14.0 '@shikijs/vscode-textmate': 10.0.2 oniguruma-to-es: 4.3.3 @@ -2034,9 +1987,9 @@ snapshots: '@shikijs/vscode-textmate': 10.0.2 oniguruma-to-es: 4.3.3 - '@shikijs/engine-oniguruma@3.13.0': + '@shikijs/engine-oniguruma@3.14.0': dependencies: - '@shikijs/types': 3.13.0 + '@shikijs/types': 3.14.0 '@shikijs/vscode-textmate': 10.0.2 '@shikijs/engine-oniguruma@3.7.0': @@ -2044,17 +1997,17 @@ snapshots: '@shikijs/types': 3.7.0 '@shikijs/vscode-textmate': 10.0.2 - '@shikijs/langs@3.13.0': + '@shikijs/langs@3.14.0': dependencies: - '@shikijs/types': 3.13.0 + '@shikijs/types': 3.14.0 '@shikijs/langs@3.7.0': dependencies: '@shikijs/types': 3.7.0 - '@shikijs/themes@3.13.0': + '@shikijs/themes@3.14.0': dependencies: - '@shikijs/types': 3.13.0 + '@shikijs/types': 3.14.0 '@shikijs/themes@3.7.0': dependencies: @@ -2065,16 +2018,16 @@ snapshots: '@shikijs/core': 3.7.0 '@shikijs/types': 3.7.0 - '@shikijs/twoslash@3.13.0(typescript@5.4.5)': + '@shikijs/twoslash@3.14.0(typescript@5.4.5)': dependencies: - '@shikijs/core': 3.13.0 - '@shikijs/types': 3.13.0 + '@shikijs/core': 3.14.0 + '@shikijs/types': 3.14.0 twoslash: 0.3.4(typescript@5.4.5) typescript: 5.4.5 transitivePeerDependencies: - supports-color - '@shikijs/types@3.13.0': + '@shikijs/types@3.14.0': dependencies: '@shikijs/vscode-textmate': 10.0.2 '@types/hast': 3.0.4 @@ -2084,18 +2037,18 @@ snapshots: '@shikijs/vscode-textmate': 10.0.2 '@types/hast': 3.0.4 - '@shikijs/vitepress-twoslash@3.13.0(typescript@5.4.5)': + '@shikijs/vitepress-twoslash@3.14.0(typescript@5.4.5)': dependencies: - '@shikijs/twoslash': 3.13.0(typescript@5.4.5) + '@shikijs/twoslash': 3.14.0(typescript@5.4.5) floating-vue: 5.2.2(vue@3.5.22(typescript@5.4.5)) lz-string: 1.5.0 - magic-string: 0.30.19 + magic-string: 0.30.21 markdown-it: 14.1.0 mdast-util-from-markdown: 2.0.2 mdast-util-gfm: 3.1.0 mdast-util-to-hast: 13.2.0 ohash: 2.0.11 - shiki: 3.13.0 + shiki: 3.14.0 twoslash: 0.3.4(typescript@5.4.5) twoslash-vue: 0.3.4(typescript@5.4.5) vue: 3.5.22(typescript@5.4.5) @@ -2130,7 +2083,7 @@ snapshots: '@types/range-parser': 1.2.7 '@types/send': 0.17.4 - '@types/express@5.0.3': + '@types/express@5.0.5': dependencies: '@types/body-parser': 1.19.5 '@types/express-serve-static-core': 5.0.6 @@ -2184,7 +2137,7 @@ snapshots: '@typescript/vfs@1.6.1(typescript@5.4.5)': dependencies: - debug: 4.4.0 + debug: 4.4.3 typescript: 5.4.5 transitivePeerDependencies: - supports-color @@ -2209,14 +2162,6 @@ snapshots: path-browserify: 1.0.1 vscode-uri: 3.1.0 - '@vue/compiler-core@3.5.21': - dependencies: - '@babel/parser': 7.28.3 - '@vue/shared': 3.5.21 - entities: 4.5.0 - estree-walker: 2.0.2 - source-map-js: 1.2.1 - '@vue/compiler-core@3.5.22': dependencies: '@babel/parser': 7.28.4 @@ -2225,11 +2170,6 @@ snapshots: estree-walker: 2.0.2 source-map-js: 1.2.1 - '@vue/compiler-dom@3.5.21': - dependencies: - '@vue/compiler-core': 3.5.21 - '@vue/shared': 3.5.21 - '@vue/compiler-dom@3.5.22': dependencies: '@vue/compiler-core': 3.5.22 @@ -2252,11 +2192,6 @@ snapshots: '@vue/compiler-dom': 3.5.22 '@vue/shared': 3.5.22 - '@vue/compiler-vue2@2.7.16': - dependencies: - de-indent: 1.0.2 - he: 1.2.0 - '@vue/devtools-api@7.7.7': dependencies: '@vue/devtools-kit': 7.7.7 @@ -2275,20 +2210,19 @@ snapshots: dependencies: rfdc: 1.4.1 - '@vue/language-core@3.0.7(typescript@5.4.5)': + '@vue/language-core@3.1.1(typescript@5.4.5)': dependencies: '@volar/language-core': 2.4.23 - '@vue/compiler-dom': 3.5.21 - '@vue/compiler-vue2': 2.7.16 - '@vue/shared': 3.5.21 - alien-signals: 2.0.6 + '@vue/compiler-dom': 3.5.22 + '@vue/shared': 3.5.22 + alien-signals: 3.0.0 muggle-string: 0.4.1 path-browserify: 1.0.1 picomatch: 4.0.2 optionalDependencies: typescript: 5.4.5 - '@vue/language-core@3.1.1(typescript@5.4.5)': + '@vue/language-core@3.1.2(typescript@5.4.5)': dependencies: '@volar/language-core': 2.4.23 '@vue/compiler-dom': 3.5.22 @@ -2324,8 +2258,6 @@ snapshots: '@vue/shared@3.5.17': {} - '@vue/shared@3.5.21': {} - '@vue/shared@3.5.22': {} '@vueuse/core@13.4.0(vue@3.5.22(typescript@5.4.5))': @@ -2367,8 +2299,6 @@ snapshots: '@algolia/requester-fetch': 5.20.0 '@algolia/requester-node-http': 5.20.0 - alien-signals@2.0.6: {} - alien-signals@3.0.0: {} ansi-regex@5.0.1: {} @@ -2441,12 +2371,6 @@ snapshots: csstype@3.1.3: {} - de-indent@1.0.2: {} - - debug@4.4.0: - dependencies: - ms: 2.1.3 - debug@4.4.3: dependencies: ms: 2.1.3 @@ -2589,8 +2513,6 @@ snapshots: dependencies: '@types/hast': 3.0.4 - he@1.2.0: {} - hookable@5.5.3: {} hookified@1.12.1: {} @@ -2653,6 +2575,10 @@ snapshots: dependencies: '@jridgewell/sourcemap-codec': 1.5.5 + magic-string@0.30.21: + dependencies: + '@jridgewell/sourcemap-codec': 1.5.5 + mark.js@8.11.1: {} markdown-it-image-size@15.0.1(markdown-it@14.1.0): @@ -2926,7 +2852,7 @@ snapshots: micromark@4.0.0: dependencies: '@types/debug': 4.1.12 - debug: 4.4.0 + debug: 4.4.3 decode-named-character-reference: 1.0.2 devlop: 1.1.0 micromark-core-commonmark: 2.0.1 @@ -2960,7 +2886,7 @@ snapshots: mlly@1.7.4: dependencies: acorn: 8.14.0 - pathe: 2.0.2 + pathe: 2.0.3 pkg-types: 1.3.1 ufo: 1.5.4 @@ -3000,8 +2926,6 @@ snapshots: path-to-regexp@8.3.0: {} - pathe@2.0.2: {} - pathe@2.0.3: {} perfect-debounce@1.0.0: {} @@ -3014,7 +2938,7 @@ snapshots: dependencies: confbox: 0.1.8 mlly: 1.7.4 - pathe: 2.0.2 + pathe: 2.0.3 pkg-types@2.3.0: dependencies: @@ -3132,14 +3056,14 @@ snapshots: shebang-regex@1.0.0: {} - shiki@3.13.0: + shiki@3.14.0: dependencies: - '@shikijs/core': 3.13.0 - '@shikijs/engine-javascript': 3.13.0 - '@shikijs/engine-oniguruma': 3.13.0 - '@shikijs/langs': 3.13.0 - '@shikijs/themes': 3.13.0 - '@shikijs/types': 3.13.0 + '@shikijs/core': 3.14.0 + '@shikijs/engine-javascript': 3.14.0 + '@shikijs/engine-oniguruma': 3.14.0 + '@shikijs/langs': 3.14.0 + '@shikijs/themes': 3.14.0 + '@shikijs/types': 3.14.0 '@shikijs/vscode-textmate': 10.0.2 '@types/hast': 3.0.4 @@ -3220,7 +3144,7 @@ snapshots: twoslash-vue@0.3.4(typescript@5.4.5): dependencies: - '@vue/language-core': 3.0.7(typescript@5.4.5) + '@vue/language-core': 3.1.1(typescript@5.4.5) twoslash: 0.3.4(typescript@5.4.5) twoslash-protocol: 0.3.4 typescript: 5.4.5 @@ -3305,17 +3229,17 @@ snapshots: '@types/node': 20.12.12 fsevents: 2.3.3 - vitepress-plugin-group-icons@1.6.4(markdown-it@14.1.0)(vite@7.0.4(@types/node@20.12.12)): + vitepress-plugin-group-icons@1.6.5(vite@7.0.4(@types/node@20.12.12)): dependencies: '@iconify-json/logos': 1.2.9 '@iconify-json/vscode-icons': 1.2.32 '@iconify/utils': 3.0.2 - markdown-it: 14.1.0 + optionalDependencies: vite: 7.0.4(@types/node@20.12.12) transitivePeerDependencies: - supports-color - vitepress-plugin-llms@1.8.0: + vitepress-plugin-llms@1.8.1: dependencies: gray-matter: 4.0.3 markdown-it: 14.1.0 @@ -3391,10 +3315,10 @@ snapshots: dependencies: vue: 3.5.22(typescript@5.4.5) - vue-tsc@3.1.1(typescript@5.4.5): + vue-tsc@3.1.2(typescript@5.4.5): dependencies: '@volar/typescript': 2.4.23 - '@vue/language-core': 3.1.1(typescript@5.4.5) + '@vue/language-core': 3.1.2(typescript@5.4.5) typescript: 5.4.5 vue@3.5.22(typescript@5.4.5): From dc313a14c3a289ab004556fafd1fcf76287f88a2 Mon Sep 17 00:00:00 2001 From: Kylin <1159469891@qq.com> Date: Tue, 28 Oct 2025 21:25:54 +0800 Subject: [PATCH 6/6] docs: update content --- guide/api-environment-plugins.md | 38 ++++++++++++------------------- guide/api-environment-runtimes.md | 8 ++----- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/guide/api-environment-plugins.md b/guide/api-environment-plugins.md index b1131f62..efbde571 100644 --- a/guide/api-environment-plugins.md +++ b/guide/api-environment-plugins.md @@ -146,11 +146,7 @@ interface HotUpdateOptions { ## 插件中的基于环境的状态 {#per-environment-state-in-plugins} -<<<<<<< HEAD -鉴于相同的插件实例会被用于不同的环境,插件的状态需要以 `this.environment` 作为键来存储。这与生态系统中已使用的模式相同,即使用 `ssr` 布尔值作为键来避免混合客户端和 SSR 模块状态的方式。可以使用 `Map` 来分别为每个环境保存其对应的状态。注意:为了保持向后兼容性,在未设置 `perEnvironmentStartEndDuringDev: true` 标志时,`buildStart` 和 `buildEnd` 仅会针对客户端环境被调用。 -======= -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` 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. ->>>>>>> 4932528a1ee790ca17435b194b04cf43e5f10fa8 +鉴于相同的插件实例会被用于不同的环境,插件的状态需要以 `this.environment` 作为键来存储。这与生态系统中已使用的模式相同,即使用 `ssr` 布尔值作为键来避免混合客户端和 SSR 模块状态的方式。可以使用 `Map` 来分别为每个环境保存其对应的状态。注意:为了保持向后兼容性,在未设置 `perEnvironmentStartEndDuringDev: true` 标志时,`buildStart` 和 `buildEnd` 仅会针对客户端环境被调用。同样的规则也适用于 `watchChange` 和 `perEnvironmentWatchChangeDuringDev: true` 标志。 ```js function PerEnvironmentCountTransformedModulesPlugin() { @@ -231,48 +227,44 @@ export default defineConfig({ `applyToEnvironment` 钩子在配置时调用,目前在 `configResolved` 之后调用,因为生态系统中的项目正在修改其中的插件。未来,环境插件解析可能会移至 `configResolved` 之前。 -<<<<<<< HEAD -## 构建钩子中的环境 {#environment-in-build-hooks} -======= -## Application-Plugin Communication +## 应用程序-插件通信 {#application-plugin-communication} -`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. +`environment.hot` 允许插件与给定环境的应用程序端代码进行通信。这相当于[客户端-服务器通信功能](/guide/api-plugin#client-server-communication),但支持除客户端环境以外的其他环境。 :::warning Note -Note that this feature is only available for environments that supports HMR. +请注意,此功能仅适用于支持 HMR 的环境。 ::: -### Managing the Application Instances +### 管理应用程序实例 {#managing-the-application-instances} -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. +需要注意的是,在同一环境中可能有多个应用程序实例在运行。例如,如果你在浏览器中打开了多个标签页,每个标签页都是一个独立的应用程序实例,并且与服务器有独立的连接。 -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. +当建立新连接时,会在环境的 `hot` 实例上触发 `vite:client:connect` 事件。当连接关闭时,会触发 `vite:client:disconnect` 事件。 -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. +每个事件处理程序都会接收到 `NormalizedHotChannelClient` 作为第二个参数。客户端是一个具有 `send` 方法的对象,可用于向该特定应用程序实例发送消息。对于同一连接,客户端引用始终相同,因此你可以保留它来跟踪连接。 -### Example Usage +### 使用示例 {#example-usage} -The plugin side: +插件端: ```js configureServer(server) { server.environments.ssr.hot.on('my:greetings', (data, client) => { - // do something with the data, - // and optionally send a response to that application instance + // 处理数据, + // 并可选择向该应用程序实例发送响应 client.send('my:foo:reply', `Hello from server! You said: ${data}`) }) - // broadcast a message to all application instances + // 向所有应用程序实例广播消息 server.environments.ssr.hot.send('my:foo', 'Hello from server!') } ``` -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. +应用程序端与客户端-服务器通信功能相同。您可以使用 `import.meta.hot` 对象向插件发送消息。 -## Environment in Build Hooks ->>>>>>> 4932528a1ee790ca17435b194b04cf43e5f10fa8 +## 构建钩子中的环境 {#environment-in-build-hooks} 与开发期间一样,插件钩子在构建期间也接收环境实例,取代了 `ssr` 布尔值。 这同样适用于 `renderChunk`、`generateBundle` 和其他仅在构建时使用的钩子。 diff --git a/guide/api-environment-runtimes.md b/guide/api-environment-runtimes.md index 9a0ecaa3..d1af0526 100644 --- a/guide/api-environment-runtimes.md +++ b/guide/api-environment-runtimes.md @@ -381,13 +381,9 @@ await createServer({ ::: -<<<<<<< HEAD -使用 HTTP 请求在运行程序和服务器之间进行通信的另一个示例: -======= -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. +请确保在 `on` / `off` 方法存在时实现 `vite:client:connect` / `vite:client:disconnect` 事件。当连接建立时应触发 `vite:client:connect` 事件,当连接关闭时应触发 `vite:client:disconnect` 事件。传递给事件处理程序的 `HotChannelClient` 对象对于同一连接必须具有相同的引用。 -A different example using an HTTP request to communicate between the runner and the server: ->>>>>>> 4932528a1ee790ca17435b194b04cf43e5f10fa8 +使用 HTTP 请求在运行程序和服务器之间进行通信的另一个示例: ```ts import { ESModulesEvaluator, ModuleRunner } from 'vite/module-runner'