• Stars
    star
    469
  • Rank 93,595 (Top 2 %)
  • Language
    TypeScript
  • Created about 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Develop server-side applications with Vite

Va vite!

vavite is a set of tools for developing and building server-side applications with Vite.

Vite, despite being a frontend tool, has support for transpiling server-side code. The feature is intended for building server-side rendering (SSR) applications. But there's no reason why it can't be leveraged for building server-side applications that are not necessarily related to SSR. vavite lets you do that, but also vastly simplifies the SSR workflow.

Vite's official SSR guide describes a workflow where Vite's development server is used as a middleware function in a server application made with a Connect compatible Node.js framework (like Express). If your server-side code needs transpilation (e.g. for TypeScript), you're required to use another set of tools (say ts-node and nodemon) for development and building. vavite enables you to use Vite itself to transpile your server-side code.

System requirements

Examples

All examples have "type": "module" in their package.json.

  • For Vite v2, remove it to use CommonJS (CJS).
  • If you want to use CommonJS with Vite v3, add legacy.buildSsrCjsExternalHeuristics: true to your Vite config.

Packages

vavite is the main package that should work for most workflows but it is built on a set of lower level tools that you can use independently:

  • @vavite/connect is a Vite plugin that turns the official SSR workflow around: Instead of mounting Vite's dev server into your application as a middleware function, you write your application in the form of a middleware function (with the (req, res, next) signature) and mount it into Vite's dev server. For production, you can provide a custom server entry or it can build a standalone Node.js server application for you. This workflow is best if you're only interested in handling requests and you don't need control over the server entry during development.

  • If you do need control over your server entry even during development, @vavite/reloader is a Vite plugin that provides live reloading capabilities for applications written with any Node.js server framework. It should be usable with any framework that allows you to provide your own http.Server instance. Note that this is a less reliable method and some things don't work on some operating systems.

  • @vavite/expose-vite-dev-server is a plugin that provides access to Vite's dev server by simply importing it. It's useful for accessing server methods like ssrFixStacktrace and transformIndexHtml during development using either @vavite/connect or @vavite/reloader.

  • Building an SSR application with Vite involves at least two invocations of Vite's build command: once for the client and once for the server. @vavite/multibuild provides a JavaScript API for orchestrating multiple Vite builds and @vavite/multibuild-cli is a drop-in replacement for the vite build CLI command for invoking multiple builds.

  • @vavite/node-loader is a Vite plugin that makes it possible to debug SSR code with full support for sourcemaps and breakpoints. It uses a Node ESM loader behind the scenes.

More Repositories

1

vite-rsc

Vite RSC experiments
TypeScript
153
star
2

detype

Remove the types, keep the formatting
TypeScript
80
star
3

vite-plugin-cjs-interop

Vite plugin to unwrap default imports from CJS dependencies during SSR
TypeScript
68
star
4

esbuild-plugin-polyfill-node

ESBuild plugin to polyfill Node.js built-ins geared towards edge environments.
TypeScript
53
star
5

smf

WIP: Vite metaframework walkthrough
TypeScript
28
star
6

php-tag

PHP-in-JS: a silly experiment
TypeScript
15
star
7

haydi

A wannabe Vite for Deno
TypeScript
15
star
8

en-vogue

Zero-runtime CSS-in-JS with static CSS extraction
TypeScript
14
star
9

vite-plugin-mdx

MDX plugin for Vite
TypeScript
13
star
10

eslint-import-resolver-exports

package.json#exports resolver for eslint-plugin-import
JavaScript
12
star
11

knave

Client-side navigation done right
TypeScript
11
star
12

create-vike

Generates Vike application boilerplate
TypeScript
9
star
13

sfotty-pie

A set of tools related to the 6502 microprocessor
TypeScript
8
star
14

h

A JSX-based toy framework for streaming SSR in 80 lines of code.
TypeScript
6
star
15

svelte-kit-node-loader

Node ESM loader with SvelteKit
TypeScript
2
star
16

rsc-things

Several components for testing React Server Components
TypeScript
2
star
17

cyco130

2
star
18

multipart-parser-benchmark

Simple benchmark for web stream multipart parsers
JavaScript
2
star
19

bare-routes

A bare-bones React client-side page router that delegates the actual routing and page loading to user code and only handles history manipulation
TypeScript
1
star
20

rakkas-mantine

TypeScript
1
star
21

vavite-vps-loader

Vite loader experiment with VPS
TypeScript
1
star
22

who-said-that

Adds a prefix that identifies the currently running npm script to every line of its output
TypeScript
1
star
23

rakkas-socket-io-hack

Hacky way to socket.io with Rakkas
TypeScript
1
star
24

vite-loader-poc

A proof-of-concept Node ESM loader using Vite
JavaScript
1
star