Plugins & Compilers

Vite Plugin

Integrate Taser with Vite using @taserjs/router-plugin/vite. Virtual route resolution, ambient type generation, instant HMR, and standalone builds.

The @taserjs/router-plugin/vite package connects Taser's file routing engine to Vite. It turns your src/routes/ directory into virtual modules, generates TypeScript definitions on save, and runs a high-performance HTTP server during development and production.


Installation

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

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


Basic Configuration

Add the taser() plugin to vite.config.ts:

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

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

Execution Modes

The Vite plugin supports two operational modes:

1. Standalone Mode (Default)

When used without Nitro, Taser operates as a self-contained server application powered directly by Vite:

  • Development: Instant HMR and route discovery with zero rebuild steps.
  • Production: Compiles an optimized server bundle to dist/.

To build and run in production:

vite build
node dist/serve.mjs

2. Nitro Mode (Vite + Nitro)

When paired with nitro/vite, Taser automatically attaches its Nitro module hook:

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

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

In this mode, Nitro handles production artifact packaging according to your chosen nitro.config.ts deployment preset (e.g. Node Server, Cloudflare Workers, Vercel, AWS Lambda).


Plugin Options

The taser() plugin accepts optional configuration:

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

export default defineConfig({
  plugins: [
    taser({
      basePath: "/api/v1",
      routesDir: "src/routes",
      entryPath: "src/taser.ts",
      server: true,
    }),
  ],
});

Configuration Reference

Prop

Type


Virtual Modules

The Vite plugin exposes virtual modules that resolve routing logic without writing intermediate code to disk:

  • #taserjs/virtual/manifest: Dynamically builds the static radix routing manifest tree.
  • #taserjs/virtual/entry: Assembles the root request handler wrapping context and routes.
  • #taserjs/virtual/app: Composes Taser with optional host framework pass-through and 404 handlers.

Ambient Route Types

During development, the plugin watches src/routes/ and generates TypeScript declaration files in .taser/types/.

To ensure your editor recognizes all route types, verify your tsconfig.json includes this directory:

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

Next Steps