Skip to content
fluenti

Code Splitting

fluenti compile always generates tree-shakeable locale modules — every message is a /* @__PURE__ */ annotated export so bundlers can eliminate unused translations. For bundle size optimization and cache tuning, see the Performance guide. Fluenti splits this into two separate concerns:

  • Build-time strategy via splitting in fluenti.config.ts
  • Runtime locale loading via loadMessages() or chunkLoader
  1. Run fluenti compile to generate per-locale ES modules with named exports and @__PURE__ annotations
  2. Each message becomes a tree-shakeable named export — unused messages are removed from the production bundle
  3. Pick a build-time strategy with splitting: 'dynamic' | 'static' | false
  4. If you want async locale switches, configure loadMessages() or chunkLoader
  5. When setLocale() is called, the locale chunk is loaded before switching

Configure the Vite build strategy in fluenti.config.ts:

import { defineConfig } from '@fluenti/cli'
export default defineConfig({
splitting: 'dynamic',
defaultBuildLocale: 'en',
})
StrategyWhat shipsBest for
falseAll locales bundled togetherSmall apps or very small catalogs
'static'One build locale inlined directly into the bundleSSR / SSG when each build only needs one locale
'dynamic'Default build locale in the initial bundle, other locales as separate chunksSPAs or multi-locale apps

Compile your catalogs:

Terminal window
npx fluenti compile

This generates:

  • locales/compiled/en.js — named exports per message with export default re-export
  • locales/compiled/zh-CN.js — same exports, translated
  • locales/compiled/index.js — locale list and lazy loaders

The Vite plugin reads the compiled locale modules automatically; you do not need to import internal virtual modules yourself.

Configure your framework runtime if you want setLocale() to fetch locale chunks on demand:

const i18n = createFluenti({
locale: 'en',
messages: { en },
lazyLocaleLoading: true,
chunkLoader: (locale) => import(`./locales/compiled/${locale}.js`),
})

If you do not configure loadMessages() / chunkLoader, setLocale() only switches between already-loaded catalogs. That is still valid with any build-time splitting strategy.

ModeBehavior
DevAll locales loaded eagerly for instant HMR
BuildOnly defaultBuildLocale is bundled; others are lazy chunks
<template>
<button
v-for="loc in locales"
:key="loc"
@mouseenter="preloadLocale(loc)"
@click="setLocale(loc)"
>
{{ loc }}
</button>
</template>
<script setup>
import { useI18n } from '@fluenti/vue'
const { setLocale, preloadLocale } = useI18n()
const locales = ['en', 'ja', 'zh-CN']
</script>