React + Vite Plugin
Kanjou offers a Vite plugin (@kanjou/vite) that integrates deeply with Vite's build pipeline. It automatically generates types on the fly and provides Hot Module Replacement (HMR) when you edit your translation files.
1. Installation
bash
npm install @kanjou/react
npm install -D @kanjou/vitebash
pnpm add @kanjou/react
pnpm add -D @kanjou/vitebash
yarn add @kanjou/react
yarn add -D @kanjou/vitebash
bun add @kanjou/react
bun add -D @kanjou/vite2. Update Vite Config
Add the Kanjou plugin to your vite.config.ts:
typescript
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { kanjou } from '@kanjou/vite'
export default defineConfig({
plugins: [react(), kanjou()],
})Plugin Order
The order of react() and kanjou() in the plugins array does not matter. The Kanjou plugin operates independently by handling virtual module resolution, watching locale files, and triggering type generation and HMR updates without depending on React code transformation hooks.
3. Experience HMR & Auto-Typing
Once the plugin is configured, simply start your Vite dev server:
bash
npm run devAny changes made to your .ts locale files will automatically:
- Re-compile the translation functions.
- Regenerate TypeScript definitions for fully typed
t()usage. - Push updates to the browser via HMR without a full page reload!