Plugins & Compilers

Vite Plugin

Integrate Taser.js with Vite using @taserjs/plugin/vite. Manifest generation, HMR, and standalone or Nitro-backed builds.

The @taserjs/plugin/vite package connects Taser.js file routing to Vite. It regenerates src/.taserjs/routes.gen.ts on change, enables HMR for routes, and can run a dedicated HTTP server in development and production.


Installation

Install the router, plugin, Vite, and the srvx server runtime:

bash pnpm add @taserjs/router pnpm add -D @taserjs/plugin @taserjs/cli vite srvx


Basic Configuration

Paths (serverDir, routesDir, outputDir, app) belong in taserjs.config.ts. The Vite plugin turns generation and the optional HTTP server on:

taserjs.config.ts
import { defineConfig } from "@taserjs/cli";

export default defineConfig({
  serverDir: "src",
  routesDir: "routes",
  outputDir: ".taserjs",
  app: "taser.ts",
});
vite.config.ts
import { defineConfig } from "vite";
import { taser } from "@taserjs/plugin/vite";

export default defineConfig({
  plugins: [taser()],
});

Mount URL prefixes with defineTaser().basePath(...) in your app definition, not in the Vite plugin options. Point @taserjs/client at the same prefix with baseUrl.


Execution Modes

1. Standalone Mode (Default)

Without Nitro, Taser.js runs as a self-contained server powered by Vite:

  • Development: Route discovery and HMR with no separate generate step.
  • Production: Optimized server bundle under dist/.
vite build
node dist/serve.mjs

2. Nitro Mode (Vite + Nitro)

Pair taser() with nitro() when Nitro should package the deployment:

vite.config.ts
import { defineConfig } from "vite";
import { nitro } from "nitro/vite";
import { taser } from "@taserjs/plugin/vite";

export default defineConfig({
  plugins: [taser(), nitro()],
});

Nitro uses your nitro.config.ts preset (Node, Cloudflare Workers, Vercel, AWS Lambda, and so on).


Plugin Options

vite.config.ts
import { defineConfig } from "vite";
import { taser } from "@taserjs/plugin/vite";

export default defineConfig({
  plugins: [
    taser({
      server: true,
      serverEntry: "src/server.ts",
      config: "./taserjs.config.ts",
    }),
  ],
});

Prop

Type

Where do routesDir and serverDir go?

Set serverDir, routesDir, outputDir, and app in taserjs.config.ts. The plugin loads that file (or built-in defaults) during generate and watch.


Generated Manifest

During development and builds, the plugin writes src/.taserjs/routes.gen.ts (path follows serverDir + outputDir): compiled app, ambient route types, and the composite manifest for @taserjs/client.

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "strict": true
  },
  "include": ["src/**/*", "vite.config.ts"]
}

Next Steps