Framework

Vite plugin

vite.config.ts
import verbaly from '@verbaly/vite';

export default { plugins: [verbaly({ sourceLocale: 'es' })] };

Options are the same as the CLI config: sourceLocale, locales, dir, include, exclude, root. Inline options win over the config file.

How it compiles

Dev server

Build

The virtual module

import { t, verbaly, setLocale, getLocale, subscribe } from 'virtual:verbaly';

// SSR: request-scoped instances + locale metadata
import { createRequestInstance, createInstance, loadMessages, locales, sourceLocale } from 'virtual:verbaly';

// 0.17.0: fresh instance, catalog awaited, no flash. One call per request:
const v = await createRequestInstance(locale);

// 0.19.0: raw catalog for a locale (SSR integrations serialize it to the client):
const messages = await loadMessages(locale);

The t/verbaly singleton is for the browser. On the server, createRequestInstance(locale) builds a fresh instance per request and awaits its catalog before returning: the no-FOUC contract in one call. createInstance(options) remains for custom setups (see Server-side).

verbaly.d.ts (generated at the project root) types this module: keys autocomplete and every key's params are enforced. Commit it so fresh clones type-check before the first dev run.

Not on Vite? Use @verbaly/unplugin

Since 0.10.0, @verbaly/unplugin brings the same compiler to webpack 5, Rollup, esbuild and Rspack: the typed virtual:verbaly module, the tagged-template transform and the build gate (failOnMissing: false opts out).

webpack.config.mjs
import { verbaly } from '@verbaly/unplugin';

export default { plugins: [verbaly.webpack({ locales: ['en', 'es'] })] };
// also: verbaly.rollup(…) · verbaly.esbuild(…) · verbaly.rspack(…)

It's build-focused: run npx verbaly extract in your dev loop or CI, since live extraction and HMR remain this Vite plugin's value. ESM-only, like the compiler (use webpack.config.mjs).

Copied to clipboard