Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vite-plugin-socket-io/vite-plugin-socket-io
Plugin to add socket.io to a Vite server
https://github.com/vite-plugin-socket-io/vite-plugin-socket-io
plugin socket socket-io socketio vite vite-plugin
Last synced: about 14 hours ago
JSON representation
Plugin to add socket.io to a Vite server
- Host: GitHub
- URL: https://github.com/vite-plugin-socket-io/vite-plugin-socket-io
- Owner: vite-plugin-socket-io
- Created: 2021-11-19T17:32:58.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-03-21T22:35:54.000Z (10 months ago)
- Last Synced: 2024-12-13T20:38:35.190Z (about 1 month ago)
- Topics: plugin, socket, socket-io, socketio, vite, vite-plugin
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 3
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Vite Plugin - socket.io
## Description
Plugin to add [socket.io](https://socket.io/) to a Vite server## Installation
```
npm i -D vite-plugin-socket-io
```## Basic Usage
```js
// vite.config.jsimport 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](./serverEvents/).
### socketEvents
Function to run containing socket.io listener and emitters. Check docs [here](./socketEvents/).## Additional Usage Examples
### Add listeners```js
// vite.config.jsimport 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})]
})
```