# vite-plugin-server

> This vite plugin allows developers to develop a backend server with NodeJS or Deno in the same codebase as the frontend code and get HMR!

Latest version **0.1.2** (published 2022-01-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-server
pnpm add vite-plugin-server
yarn add vite-plugin-server
bun add vite-plugin-server
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2022-01-26 |
| First published | 2022-01-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Sebastian Krüger |
| Maintainers | mathe42 |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-server
- npm.io page: https://npm.io/package/vite-plugin-server

## Dependencies (3)

- [ws](https://npm.io/package/ws.md) ^8.4.2
- [tsup](https://npm.io/package/tsup.md) ^5.11.11
- [node-fetch](https://npm.io/package/node-fetch.md) ^3.1.1

## Recent versions

- 0.1.2 (latest) — 2022-01-26
- 0.1.1 — 2022-01-18
- 0.1.0 — 2022-01-18
- 0.0.0 — 2022-01-18

## README

# Vite-plugin-server

This vite plugin allows developers to develop a backend server with NodeJS or Deno in the same codebase as the frontend code and get HMR!

> _Note:_ This is more or less a hack! Working of this plugin can change from one minor vite version to the next! Please report Bugs! This Plugin is in a alpha stage so expect breaking changes!

## Install
Install this plugin with
```sh
yarn add -D vite-plugin-server
```

In vite.config.js import it like this:

```ts
import { defineConfig } from "vite";
import server from 'vite-plugin-server';

export default defineConfig(({command, mode}) => ({
  build:
    command === "build" && mode === "server"
      ? {
          lib: {
            entry: "./path/to/server/entry.ts",
            formats: ["es"],
            fileName: () => "server.mjs",
          },
          outDir: "server",
        }
      : {},
  plugins: [
    server()
  ]
}))
```

## Deno

For Deno if you did the install step you are ready to go! Just start the vite server and after that start deno with:

```sh
deno run --allow-net -r http://localhost:3000/path/to/deno/entry.ts
```

If the HMR runs into a problem and wants to "reload" the process is ended and you have to manualy restart it or use a tool for that.

## NodeJS

NodeJS is a bit complexer you the latest version (17.4). The needed API is not stable! So this can stop working with a new node relase!

Create a extra file called for example `entry.mjs` and add the folowing code:

```js
import 'http://localhost:3000/path/to/node/entry.ts'
```

Start it with

```sh
node  --experimental-loader vite-plugin-server/node entry.mjs
```

## Build
The server can be build with `vite build --mode server` 

> There is currently a bug where some dev code is included. So this is currently not production ready.


## HMR
There are currently no plugins that enable HMR for different use cases. I will work on a for a Deno REST-API with oak but you basicly have to implement it on your own. Feel free to share your plugins!

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