Skip to content

Vite and Vitest

vibelang-vite compiles .vibe and .vibex modules for Vite (7 and 8) and Vitest (5) using the project's vibelang compiler, serving JavaScript and source maps with diagnostics in the terminal and Vite overlay. Install the packages with Add VibeLang to an existing project first (Yarn projects must install the vite 7 or 8 peer explicitly; see package setup).

Hot reload and type errors in Vite

1. Add the plugin to Vite

Add vibelang() to vite.config.ts:

// TypeScript (.ts)
// vite.config.ts
import { defineConfig } from "vite"
import vibelang from "vibelang-vite"
 
export default defineConfig({ plugins: [vibelang()] })

Workers

Vite builds workers via worker.plugins. Add a factory whenever an app or workspace dependency imports .vibe inside a worker:

// TypeScript (.ts)
import { defineConfig } from "vite"
import vibelang from "vibelang-vite"
 
export default defineConfig({
  plugins: [vibelang()],
  worker: { plugins: () => [vibelang()] }
})

Importing .vibe from vite.config

Vite loads vite.config.ts before initializing plugins. If your config (or its helpers) imports .vibe at runtime, preload vibelang/register and select Vite's native config loader on the CLI (use --config vite.config.vibe if the config itself is .vibe):

NODE_OPTIONS="${NODE_OPTIONS:+$NODE_OPTIONS }--import=vibelang/register" npx vite build --configLoader native

Use the same prefix and --configLoader native for dev and preview. Keep explicit relative extensions and package exports in config helpers (not tsconfig paths); set VIBELANG_PROJECT=tsconfig.node.json if a helper belongs to a different tsconfig, and VIBELANG_REGISTER_DEBUG=1 to trace config loader compiles.

2. Configure tsconfig.json

vibelang-vite compiles with your project's tsconfig.json and automatically enables rewriteRelativeImportExtensions on emit so ./greet.vibe works alongside Vite's allowImportingTsExtensions. (Direct CLI emission still requires "rewriteRelativeImportExtensions": true in tsconfig.json; see CLI setup.)

Project resolution rules:

  • Custom Vite root: Pass vibelang({ project: "../tsconfig.json" }) when Vite's root sits inside the package.
  • Solution configs ("files": [] + references): Each module compiles under the first referenced project containing it, or pass vibelang({ project: "tsconfig.app.json" }).
  • Workspace packages & multi-project layouts: A .vibe module uses its nearest tsconfig.json, then its references, parent configs, and sibling configs in the same package; nested workspace packages always use their own tsconfig.json.
  • Vite client types: Add "types": ["vite/client"] in compilerOptions to use import.meta.glob, import.meta.env, and import.meta.hot in .vibe modules.

3. Add a first module

Create src/greet.vibe:

// src/greet.vibe
export effect function greet(name: string) {
  return `Hello, ${name}!`
}
// Run in an effect function: try Console.log(try greet("Vite"))
// Output: Hello, Vite!

In Vite or Vitest, import it by its source extension (./greet.vibe) so the plugin compiles it. (In a CLI build targeting Node, a .ts importer may use ./greet.js; see CLI setup.) TypeScript sees greet as returning an Effect:

// TypeScript (.ts)
// src/use-greet.ts
import { Effect } from "effect"
import { greet } from "./greet.vibe"
 
export const message = Effect.runSync(greet("Vite"))
// Run: console.log(message)
// Output: Hello, Vite!

Queries and resolution

  • Extension order: vibelang-vite adds .vibe to resolve.extensions (x.ts, x.tsx, x.vibe, x.js), so extensionless imports and directory indexes (./mount → mount/index.vibe) work like TypeScript.
  • Module vs. resource queries: Vite's module queries (?import, ?v=, ?t=, ?worker_file&type=) compile normally. Resource queries (?raw, ?url, or custom plugin queries) pass through untouched.
  • JSX (.vibex): Configure compilerOptions.jsx as for .tsx. The plugin emits virtual .jsx IDs for downstream framework plugins while keeping .vibex names in diagnostics and source maps.

4. Test with Vitest

Tests in .vibe with Vitest

Create tsconfig.test.json so Vitest checks test files excluded from the app build (extend tsconfig.app.json if your app uses one):

{
  "extends": "./tsconfig.json",
  "exclude": []
}

Add the plugin to vitest.config.ts:

// TypeScript (.ts)
// vitest.config.ts
import { defineConfig } from "vitest/config"
import vibelang from "vibelang-vite"
 
export default defineConfig({
  plugins: [vibelang({ project: "tsconfig.test.json" })],
  test: { include: ["src/**/*.test.vibe"] }
})

Create src/greet.test.vibe:

// src/greet.test.vibe
import { assert, it } from "@effect/vitest"
import { greet } from "./greet.vibe"
 
it.effect("greets", () => effect {
  const message = try greet("Vite")
  try Effect.try(() => assert.strictEqual(message, "Hello, Vite!"))
})

Run npx vitest run (no prior build needed):

 Test Files  1 passed (1)
      Tests  1 passed (1)
  • Child processes in tests: Pass vibelang({ project: "tsconfig.test.json", register: true }) to inject vibelang/register into NODE_OPTIONS (and vibelang/bun into BUN_OPTIONS when the path has no spaces) so spawned Node/Bun processes can import .vibe sources.
  • Vitest test.projects: Add vibelang() (with register: true if needed) to each project's own plugins; top-level plugins do not apply to independent projects.
  • Coverage: @vitest/coverage-v8 counts authored .vibe functions and excludes compiler-generated wrappers and error registration.

Node's test runner and Jest

For node --test, write .test.ts files importing .vibe modules, add @types/node and "node" to tsconfig.test.json's types, and run with vibelang/register:

VIBELANG_PROJECT=tsconfig.test.json node --enable-source-maps --import vibelang/register --test src/greet.test.ts

For built-in coverage, keep --enable-source-maps so Node's controller remaps generated offsets to authored .vibe functions (add --test-coverage-functions=100 to require full function coverage):

VIBELANG_PROJECT=tsconfig.test.json node --enable-source-maps --import vibelang/register --test --experimental-test-coverage src/greet.test.ts

No Jest transformer is shipped; use Vitest for .test.vibe suites.

5. Build

Replace tsc with vibelang in package.json:

{
  "scripts": {
    "build": "vibelang && vite build",
    "test": "vitest run"
  }
}

Run npm run build (or bun run build) and npm run test (or bun run test). The build exits 0 and ends with ✓ built in.

Runtime & bundler behavior

AreaBehavior
Shared compilerPlugin instances with matching root, project config, and compiler share one backend and invalidate on edits. Closing the last instance terminates the backend (SIGTERM after 500 ms, SIGKILL after another 500 ms). Set VIBELANG_VITE_DEBUG=1 to trace compiles and invalidations.
DiagnosticsLoaders compile whole-project types but report only the requested module's diagnostics plus project-wide/config errors; unrelated file errors and warnings (e.g. EK38130 from @effect/vitest) never block loading. Run vibelang -p tsconfig.json to check all files.
Pre-bundling.vibe is added to optimizeDeps.extensions so Vite scans compiled imports (such as effect/Schema, effect/Option, and vibelang-runtime) before the first request. With allowJs, JS edits recheck .vibe importers.
Exports & HMRSelects vibelang-source for app/SSR bundles (Vitest keeps its own Node conditions). Existing import.meta.hot.accept handlers keep state; Unicode, spaces, and literal % in filenames preserve source maps and HMR.
Sidecars & declarationsWatcher ignores generated .d.vibe.ts, .d.vibex.ts, and forwarding .d.ts files while their source exists (hand-written .d.ts stays an input). Rolldown/tsdown (dts: true) builds use vibelang-unplugin/rolldown for declaration output.
Cache & virtual IDsVIBELANG_CACHE_DIR stays safe even inside Vite's watched root. Virtual module IDs from other plugins pass through untouched.

Next

Set up your editor: VS Code and Cursor, Neovim, Zed, or other editors. Then verify with step 4 of Set up VibeLang.