@@ -428,8 +428,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
428
428
429
429
``` js
430
430
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' })
433
432
// Invalidate modules manually
434
433
const invalidatedModules = new Set ()
435
434
for (const mod of modules) {
@@ -448,8 +447,7 @@ Vite plugins can also provide hooks that serve Vite-specific purposes. These hoo
448
447
449
448
` ` ` js
450
449
handleHotUpdate({ server }) {
451
- // Also use ` server .ws .send ` to support Vite <5.1 if needed
452
- server.hot.send({
450
+ server.ws.send({
453
451
type: 'custom',
454
452
event: 'special-update',
455
453
data: {}
@@ -556,7 +554,7 @@ Since Vite 2.9, we provide some utilities for plugins to help handle the communi
556
554
557
555
### Server to Client
558
556
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 :
560
558
561
559
` ` ` js
562
560
// vite.config.js
@@ -565,9 +563,8 @@ export default defineConfig({
565
563
{
566
564
// ...
567
565
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' })
571
568
})
572
569
},
573
570
},
@@ -603,7 +600,7 @@ if (import.meta.hot) {
603
600
}
604
601
` ` `
605
602
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:
607
604
608
605
` ` ` js
609
606
// vite.config.js
@@ -612,7 +609,7 @@ export default defineConfig({
612
609
{
613
610
// ...
614
611
configureServer(server) {
615
- server.hot .on('my:from-client', (data, client) => {
612
+ server.ws .on('my:from-client', (data, client) => {
616
613
console.log('Message from client:', data.msg) // Hey!
617
614
// reply only to the client (if needed)
618
615
client.send('my:ack', { msg: 'Hi! I got your message!' })
0 commit comments