Integrations
Vite (unplugin)
Use SayKit with Vite, Rollup, Rolldown, Webpack, Rspack, esbuild, Farm, or Bun
unplugin-saykit is the SayKit plugin for every bundler unplugin supports. Only the import path changes between them.
Install
pnpm add -D unplugin-saykit @saykit/config @saykit/format-po @saykit/transform-js @saykit/transform-jsxUse
import saykit from 'unplugin-saykit/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [saykit()],
});The plugin takes no options; it reads saykit.config.ts.
What it does
It does two things:
- Compiles catalogues. When the build starts, it compiles each catalogue into an ordinary
{locale}.jsmodule, assaykit compiledoes. In a dev server or watch mode it recompiles whenever a catalogue changes, so editingen.porewrites every locale that falls back to it. The bundler loads, splits and hot-reloads those modules like any other. A module that would not change is not rewritten, so the plugin andextract --watchnever trigger reloads for each other. - Rewrites macros in every file a bucket includes, so
say`Hello, ${name}!`becomessay.call({ id: '…', _name: name }).
Keep saykit extract --watch running in development so the source catalogue follows your code.
Notes
- Ordering. The plugin runs with
enforce: 'pre', so it sees macros before other transforms. A plugin that lowers tagged templates must run after it. - Vite works beside
@vitejs/plugin-reactand TanStack Start. Vitest picks the plugin up fromvite.config.ts, which the macros need. - Next.js should use
babel-plugin-saykitinstead.
Next
- Configuration: what the plugin reads
- Babel plugin: when you need Babel instead