2021-11-19 13:03:07 -05:00
2021-11-19 13:03:07 -05:00
2021-11-19 13:03:07 -05:00
2021-11-19 13:03:07 -05:00
2021-11-19 13:03:07 -05:00
2021-11-22 09:51:17 -05:00
2024-03-21 16:32:18 -06:00

Vite Plugin - socket.io

Description

Plugin to add socket.io to a Vite server

Installation

npm i -D vite-plugin-socket-io

Basic Usage

// vite.config.js

import vitePluginSocketIO from 'vite-plugin-socket.io'
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [vitePluginSocketIO()]
})

Options

serverEvents

Function to run when initializing socket.io connection. Check docs here.

socketEvents

Function to run containing socket.io listener and emitters. Check docs here.

Additional Usage Examples

Add listeners

// vite.config.js

import vitePluginSocketIO from 'vite-plugin-socket-io'
import { defineConfig } from 'vite';

const socketEvents = (io, socket) => {
  console.log('socket.io - connection');
  socket.on('disconnect', () => {
    console.log(`socket.io - socket.id \`${socket.id}\` disconnected`)
  })
  socket.on('signin', () => {
    console.log('socket.io - signin')
  })
}

export default defineConfig({
  plugins: [vitePluginSocketIO({socketEvents})]
})
S
Description
Mirror of github.com/RustyRaptor/vite-plugin-socket-io — Plugin to add socket.io to a Vite server
Readme
46 KiB
0 Stars 1 Watchers 0 Forks
Languages
JavaScript 100%