vite-plugin-socket-io
v1.0.2
Published
Plugin to add socket.io to a Vite server
Downloads
1,028
Maintainers
Readme
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})]
})