@@ -428,8 +428,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
428428
429429 ``` js
430430 handleHotUpdate ({ server, modules, timestamp }) {
431- // Also use `server.ws.send` to support Vite <5.1 if needed
432- server .hot .send ({ type: ' full-reload' })
431+ server .ws .send ({ type: ' full-reload' })
433432 // Invalidate modules manually
434433 const invalidatedModules = new Set ()
435434 for (const mod of modules) {
@@ -448,8 +447,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
448447
449448 ` ` ` js
450449 handleHotUpdate({ server }) {
451- // Also use ` server .ws .send ` to support Vite <5.1 if needed
452- server.hot.send({
450+ server.ws.send({
453451 type: 'custom',
454452 event: 'special-update',
455453 data: {}
@@ -556,7 +554,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi
556554
557555### Server to Client
558556
559- 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 :
557+ On the plugin side, we could use ` server.ws.send` to broadcast events to the client :
560558
561559` ` ` js
562560// vite.config.js
@@ -565,9 +563,8 @@ export default defineConfig({
565563 {
566564 // ...
567565 configureServer(server) {
568- // Example: wait for a client to connect before sending a message
569- server.hot.on('connection', () => {
570- server.hot.send('my:greetings', { msg: 'hello' })
566+ server.ws.on('connection', () => {
567+ server.ws.send('my:greetings', { msg: 'hello' })
571568 })
572569 },
573570 },
@@ -603,7 +600,7 @@ if (import.meta.hot) {
603600}
604601` ` `
605602
606- Then use ` server.hot.on ` (since Vite 5.1 ) or ` server. ws.on` and listen to the events on the server side:
603+ Then use ` server.ws.on` and listen to the events on the server side:
607604
608605` ` ` js
609606// vite.config.js
@@ -612,7 +609,7 @@ export default defineConfig({
612609 {
613610 // ...
614611 configureServer(server) {
615- server.hot .on('my:from-client', (data, client) => {
612+ server.ws .on('my:from-client', (data, client) => {
616613 console.log('Message from client:', data.msg) // Hey!
617614 // reply only to the client (if needed)
618615 client.send('my:ack', { msg: 'Hi! I got your message!' })
0 commit comments