# vite-plugin-socket-io

> Plugin to add socket.io to a Vite server

Latest version **1.0.2** (published 2021-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-socket-io
pnpm add vite-plugin-socket-io
yarn add vite-plugin-socket-io
bun add vite-plugin-socket-io
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-11-22 |
| First published | 2021-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 3.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Bob McAleavey |
| Maintainers | bobthered |
| Keywords | vite-plugin, socket.io, socket, socketio, vite |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-socket-io
- Repository: https://github.com/vite-plugin-socket-io/vite-plugin-socket-io
- Homepage: https://github.com/vite-plugin-socket-io/vite-plugin-socket-io.git#readme
- Issues: https://github.com/vite-plugin-socket-io/vite-plugin-socket-io.git/issues
- npm.io page: https://npm.io/package/vite-plugin-socket-io

## Dependencies (1)

- [socket.io](https://npm.io/package/socket.io.md) ^4.4.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-11-22
- 1.0.1 — 2021-11-22

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

---
_Source: https://npm.io/package/vite-plugin-socket-io · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
