Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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.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](./serverEvents/).
### socketEvents
Function to run containing socket.io listener and emitters. Check docs [here](./socketEvents/).

## Additional Usage Examples
### Add listeners

```js
// 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})]
})
```