Skip to content

Vite Plugin TApi

@farbenmeer/vite-plugin-tapi bundles a TApi REST API alongside your Vite frontend in a single project. In dev and preview modes the API is served as middleware on the same port as the frontend. For production, vite build emits a deployable server bundle.

Terminal window
pnpm add -D @farbenmeer/vite-plugin-tapi
pnpm add @farbenmeer/tapi srvx
vite.config.ts
import { defineConfig } from "vite";
import tapi from "@farbenmeer/vite-plugin-tapi";
export default defineConfig({
plugins: [tapi()],
});

The plugin expects src/api.ts to export api (an ApiDefinition):

src/api.ts
import { defineApi, defineHandler, TResponse } from "@farbenmeer/tapi/server";
export const api = defineApi().route("/hello", {
GET: defineHandler({ authorize: () => true }, async () => {
return TResponse.json({ message: "hello" });
}),
});

Single Port Dev

Frontend and API are served on the same port in dev and preview — no CORS configuration needed.

Isolated Build Output

vite build writes dist/client/ (static assets) and dist/server/ (server bundle) separately, so secrets never leak to the static host.

Env File Support

.env files are loaded and mirrored into process.env during development, covering server-side libraries that read process.env directly.

Service Worker Ready

Composes cleanly with vite-plugin-pwa to add offline support and tag-based cache revalidation.