You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guide/api-plugin.md
+7-7
Original file line number
Diff line number
Diff line change
@@ -423,11 +423,11 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
423
423
424
424
- Filter and narrow down the affected module list so that the HMR is more accurate.
425
425
426
-
- Return an empty array and perform complete custom HMR handling by sending custom events to the client:
426
+
- Return an empty array and perform complete custom HMR handling by sending custom events to the client (example uses `server.hot` which was introduced in Vite 5.1, it is recommended to also use `server.ws` if you support lower versions):
427
427
428
428
```js
429
429
handleHotUpdate({ server }) {
430
-
server.ws.send({
430
+
server.hot.send({
431
431
type:'custom',
432
432
event:'special-update',
433
433
data: {}
@@ -534,7 +534,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi
534
534
535
535
### Server to Client
536
536
537
-
On the plugin side, we could use `server.ws.send` to broadcast events to all the clients:
537
+
On the plugin side, we could use `server.hot.send` (since Vite 5.1) or `server.ws.send` to broadcast events to all the clients:
538
538
539
539
```js
540
540
// vite.config.js
@@ -544,8 +544,8 @@ export default defineConfig({
544
544
// ...
545
545
configureServer(server) {
546
546
// Example: wait for a client to connect before sending a message
547
-
server.ws.on('connection', () => {
548
-
server.ws.send('my:greetings', { msg: 'hello' })
547
+
server.hot.on('connection', () => {
548
+
server.hot.send('my:greetings', { msg: 'hello' })
549
549
})
550
550
},
551
551
},
@@ -579,7 +579,7 @@ if (import.meta.hot) {
579
579
}
580
580
```
581
581
582
-
Then use `server.ws.on` and listen to the events on the server side:
582
+
Then use `server.hot.on` (since Vite 5.1) or `server.ws.on` and listen to the events on the server side:
0 commit comments