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).
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 nativeUse 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: Passvibelang({ project: "../tsconfig.json" })when Vite'srootsits inside the package. - Solution configs (
"files": []+references): Each module compiles under the first referenced project containing it, or passvibelang({ project: "tsconfig.app.json" }). - Workspace packages & multi-project layouts: A
.vibemodule uses its nearesttsconfig.json, then itsreferences, parent configs, and sibling configs in the same package; nested workspace packages always use their owntsconfig.json. - Vite client types: Add
"types": ["vite/client"]incompilerOptionsto useimport.meta.glob,import.meta.env, andimport.meta.hotin.vibemodules.
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-viteadds.vibetoresolve.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): ConfigurecompilerOptions.jsxas for.tsx. The plugin emits virtual.jsxIDs for downstream framework plugins while keeping.vibexnames in diagnostics and source maps.
4. Test 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 injectvibelang/registerintoNODE_OPTIONS(andvibelang/bunintoBUN_OPTIONSwhen the path has no spaces) so spawned Node/Bun processes can import.vibesources. - Vitest
test.projects: Addvibelang()(withregister: trueif needed) to each project's ownplugins; top-level plugins do not apply to independent projects. - Coverage:
@vitest/coverage-v8counts authored.vibefunctions and excludes compiler-generated wrappers anderrorregistration.
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.tsFor 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.tsNo 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
| Area | Behavior |
|---|---|
| Shared compiler | Plugin 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. |
| Diagnostics | Loaders 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 & HMR | Selects 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 & declarations | Watcher 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 IDs | VIBELANG_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.