From 763d19dc4f90ef6cee6619cb15590e653b712fc1 Mon Sep 17 00:00:00 2001 From: TAKAHASHI Shuuji Date: Fri, 24 May 2024 19:59:35 +0900 Subject: [PATCH] docs: deprecate server.hot (#1431) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit resolve #1430 https://github.com/vitejs/vite/commit/e7d38ab1c45b9d17f182f89d0c129932e2f994eb の反映です。 --- guide/api-plugin.md | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/guide/api-plugin.md b/guide/api-plugin.md index 659a6653..83ba5578 100644 --- a/guide/api-plugin.md +++ b/guide/api-plugin.md @@ -428,8 +428,7 @@ Vite プラグインは Vite 特有の目的を果たすフックを提供する ```js handleHotUpdate({ server, modules, timestamp }) { - // Also use `server.ws.send` to support Vite <5.1 if needed - server.hot.send({ type: 'full-reload' }) + server.ws.send({ type: 'full-reload' }) // Invalidate modules manually const invalidatedModules = new Set() for (const mod of modules) { @@ -448,8 +447,7 @@ Vite プラグインは Vite 特有の目的を果たすフックを提供する ```js handleHotUpdate({ server }) { - // 必要に応じて Vite <5.1 をサポートするために `server.ws.send` も使用 - server.hot.send({ + server.ws.send({ type: 'custom', event: 'special-update', data: {} @@ -556,7 +554,7 @@ Vite の 2.9 から、プラグインによりクライアントとの通信に ### サーバーからクライアントへ -プラグイン側からは `server.hot.send`(Vite 5.1 以降)または `server.ws.send` を使うことで全クライアントへイベントを配信することができます: +プラグイン側からは `server.ws.send` を使うことでクライアントへイベントを配信できます: ```js // vite.config.js @@ -565,9 +563,8 @@ export default defineConfig({ { // ... configureServer(server) { - // 例:メッセージ送信前にクライアントが接続されるのを待つ - server.hot.on('connection', () => { - server.hot.send('my:greetings', { msg: 'hello' }) + server.ws.on('connection', () => { + server.ws.send('my:greetings', { msg: 'hello' }) }) }, }, @@ -603,7 +600,7 @@ if (import.meta.hot) { } ``` -この時、サーバー側では `server.hot.on`(Vite 5.1 以降)または `server.ws.on` を使ってイベントをリッスンします: +この時、サーバー側では `server.ws.on` を使ってイベントをリッスンします: ```js // vite.config.js @@ -612,7 +609,7 @@ export default defineConfig({ { // ... configureServer(server) { - server.hot.on('my:from-client', (data, client) => { + server.ws.on('my:from-client', (data, client) => { console.log('Message from client:', data.msg) // Hey! // クライアントへの返信のみ(必要であれば) client.send('my:ack', { msg: 'Hi! I got your message!' })