{"id":38933896,"url":"https://github.com/rivet-dev/vite-plugin-srvx","last_synced_at":"2026-02-10T03:11:01.909Z","repository":{"id":332240779,"uuid":"1130039403","full_name":"rivet-dev/vite-plugin-srvx","owner":"rivet-dev","description":null,"archived":false,"fork":false,"pushed_at":"2026-01-17T05:55:46.000Z","size":46,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-18T00:23:56.723Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rivet-dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-08T00:12:17.000Z","updated_at":"2026-01-17T04:02:03.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/rivet-dev/vite-plugin-srvx","commit_stats":null,"previous_names":["rivet-dev/vite-plugin-srvx"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/rivet-dev/vite-plugin-srvx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rivet-dev%2Fvite-plugin-srvx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rivet-dev%2Fvite-plugin-srvx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rivet-dev%2Fvite-plugin-srvx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rivet-dev%2Fvite-plugin-srvx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rivet-dev","download_url":"https://codeload.github.com/rivet-dev/vite-plugin-srvx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rivet-dev%2Fvite-plugin-srvx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29289899,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T02:32:08.756Z","status":"ssl_error","status_checked_at":"2026-02-10T02:30:31.937Z","response_time":65,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-01-17T15:46:41.795Z","updated_at":"2026-02-10T03:11:01.904Z","avatar_url":"https://github.com/rivet-dev.png","language":"TypeScript","readme":"# vite-plugin-srvx\n\nA Vite plugin that integrates [srvx](https://srvx.h3.dev/) (Universal Server) with Vite's development server, similar to how `@hono/vite-dev-server` works with Hono.\n\n## Features\n\n- **Automatic index.html serving** - The plugin automatically serves `index.html` on the root path\n- **Hot Module Replacement (HMR)** - Full HMR support for your srvx server\n- **Automatic Vite client script injection** - Vite's dev client is automatically injected into HTML responses\n- **Web Standard APIs** - Use Request/Response APIs that work everywhere\n- **Universal** - Works with Node.js, Deno, and Bun\n- **Lightning fast** - Powered by Vite's blazing fast dev server\n- **Vercel Edge Functions** - Built-in support for deploying to Vercel (auto-detected!)\n\n## Installation\n\n```bash\nnpm install vite-plugin-srvx srvx vite\n```\n\nOr with pnpm:\n\n```bash\npnpm add vite-plugin-srvx srvx vite\n```\n\n## Usage\n\n### 1. Create an index.html file\n\nCreate an `index.html` file in your project root:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\"\u003e\n  \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"\u003e\n  \u003ctitle\u003eMy srvx App\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003ch1\u003eHello from srvx + Vite!\u003c/h1\u003e\n  \u003cscript type=\"module\" src=\"/src/main.ts\"\u003e\u003c/script\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n### 2. Create your srvx server\n\nCreate a `src/server.ts` file for your API routes:\n\n```typescript\nexport default {\n  async fetch(request: Request): Promise\u003cResponse\u003e {\n    const url = new URL(request.url)\n\n    // The plugin automatically serves index.html on '/'\n    // so you only need to handle API routes here\n\n    if (url.pathname === '/api/hello') {\n      return Response.json({\n        message: 'Hello from srvx!',\n        timestamp: new Date().toISOString(),\n      })\n    }\n\n    return new Response('Not Found', { status: 404 })\n  },\n}\n```\n\n### 3. Configure Vite\n\nCreate a `vite.config.ts` file:\n\n```typescript\nimport { defineConfig } from 'vite'\nimport srvx from 'vite-plugin-srvx'\n\nexport default defineConfig({\n  plugins: [\n    ...srvx({\n      entry: './src/server.ts',\n    }),\n  ],\n})\n```\n\n### 4. Run the development server\n\n```bash\nvite\n```\n\nYour srvx server will now run with Vite's dev server! Visit `http://localhost:5173` to see your app:\n- `/` - Automatically serves `index.html`\n- `/api/hello` - Your srvx API endpoint\n- All other routes are handled by your srvx server's fetch handler\n\n## Building for Production\n\nThe plugin uses Vite's mode system to handle client and server builds separately.\n\nAdd these scripts to your `package.json`:\n\n```json\n{\n  \"scripts\": {\n    \"dev\": \"vite\",\n    \"build\": \"vite build \u0026\u0026 vite build --mode server\",\n    \"start\": \"srvx dist/server.js\"\n  }\n}\n```\n\nThen build your app:\n\n```bash\nnpm run build\n```\n\nThis will:\n1. Build your frontend (HTML, CSS, JS) to `dist/public` (first `vite build`)\n2. Build your srvx server to `dist/server.js` (second `vite build --mode server`)\n\nRun your production build:\n\n```bash\nnpm run start\n# or directly: srvx dist/server.js\n```\n\nsrvx automatically serves static files from the `dist/public` directory!\n\n## Options\n\n### Plugin Options\n\n```typescript\ninterface SrvxOptions {\n  // Entry file for your srvx server (default: './src/server.ts')\n  entry?: string\n\n  // Output directory for server build (default: 'dist')\n  outDir?: string\n\n  // Server output filename (default: 'server.js')\n  serverOutFile?: string\n\n  // Target framework for deployment (e.g., 'vercel')\n  // When set to 'vercel' OR when VERCEL=1 env var is set (auto-detected),\n  // outputs to dist/api/index.js for Vercel Edge Functions\n  framework?: 'vercel'\n\n  // Development server options\n  // Patterns to exclude from the srvx handler (will be handled by Vite instead)\n  exclude?: (string | RegExp)[]\n\n  // Whether to inject Vite's client script for HMR (default: true)\n  injectClientScript?: boolean\n\n  // Custom module loader (default: uses Vite's ssrLoadModule)\n  loadModule?: (server: ViteDevServer, entry: string) =\u003e Promise\u003cany\u003e\n}\n```\n\n\u003e **Note:** The plugin returns an array of three plugins (dev server + client build + server build), so use the spread operator: `...srvx({})`\n\n### Example with custom options\n\n```typescript\nimport { defineConfig } from 'vite'\nimport srvx from 'vite-plugin-srvx'\n\nexport default defineConfig(({ mode }) =\u003e ({\n  plugins: [\n    ...srvx({\n      entry: './src/server.ts',\n      outDir: 'build',\n      serverOutFile: 'app.js',\n      exclude: [\n        /.*\\.tsx?$/,\n        /.*\\.css$/,\n        /^\\/@.+$/,\n      ],\n      injectClientScript: true,\n    }),\n  ],\n}))\n```\n\nThen build with:\n```bash\nnpm run build\n# This runs: vite build \u0026\u0026 vite build --mode server\n# - Client build outputs to build/public\n# - Server build outputs to build/app.js\n```\n\nAnd run: `srvx build/app.js` (it will automatically serve static files from `build/public`)\n\n### Using Individual Plugins (Advanced)\n\nIf you need more control, you can import the plugins separately:\n\n```typescript\nimport { defineConfig } from 'vite'\nimport { devServer, clientBuild, srvxBuild } from 'vite-plugin-srvx'\n\nexport default defineConfig(({ mode }) =\u003e ({\n  plugins: [\n    devServer({ entry: './src/server.ts' }),\n    clientBuild({ outDir: 'dist' }),\n    srvxBuild({ entry: './src/server.ts', outDir: 'dist' }),\n  ],\n}))\n```\n\n## How it works\n\n### Development Mode\n\nThe `devServer` plugin creates a Vite middleware that:\n\n1. **Serves index.html on root** - When requesting `/`, the plugin automatically serves and transforms your `index.html` using Vite's `transformIndexHtml` (which handles script injection, etc.)\n2. **Intercepts other HTTP requests** - All non-root requests are passed to your srvx server\n3. **Loads your srvx server module** - Uses Vite's SSR module loader for HMR support\n4. **Converts to Web Standard APIs** - Converts Node.js `IncomingMessage` → Web Standard `Request`\n5. **Calls your fetch handler** - Your srvx server's `fetch` handler processes the request\n6. **Converts the response** - Converts the `Response` back to Node.js `ServerResponse`\n7. **Injects Vite client** - For HTML responses from your server, Vite's client script is injected for HMR\n\n### Production Build\n\nThe plugin uses Vite's mode system with three separate plugins:\n\n1. **Client build** (`vite build`):\n   - `clientBuild` plugin is active (mode !== 'server')\n   - Builds frontend to `dist/public`\n   - `srvxBuild` plugin is inactive\n\n2. **Server build** (`vite build --mode server`):\n   - `srvxBuild` plugin is active (mode === 'server')\n   - Sets `ssr: true` via the `config` hook\n   - Builds server to `dist/server.js`\n   - `clientBuild` plugin is inactive\n\n3. **Run with srvx**:\n   - `srvx dist/server.js`\n   - srvx automatically serves static files from `dist/public`\n\nThis approach follows the same pattern as [@hono/vite-build](https://github.com/honojs/vite-plugins/tree/main/packages/build)\n\nThis gives you the best of both worlds: srvx's universal server API and Vite's lightning-fast development experience!\n\n## Examples\n\nCheck out the [examples](./examples) directory for full working examples:\n- [examples/basic](./examples/basic) - Basic srvx + Vite setup\n- [examples/vercel](./examples/vercel) - Vercel Edge Functions deployment\n\nTo run an example:\n\n```bash\npnpm install\npnpm build\ncd examples/basic  # or examples/vercel\npnpm dev\n```\n\n## Comparison with @hono/vite-dev-server\n\nThis plugin is heavily inspired by `@hono/vite-dev-server` but designed specifically for srvx:\n\n- Similar middleware architecture\n- Same HMR capabilities\n- Compatible API design\n- Works with any framework that uses Web Standard fetch API\n\n## License\n\nMIT\n\n## Credits\n\nInspired by [@hono/vite-dev-server](https://github.com/honojs/vite-plugins/tree/main/packages/dev-server)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frivet-dev%2Fvite-plugin-srvx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frivet-dev%2Fvite-plugin-srvx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frivet-dev%2Fvite-plugin-srvx/lists"}