Skip to content
fluenti

Code Splitting

fluenti compile always generates tree-shakeable named exports — every message is a /* @__PURE__ */ annotated export so bundlers can eliminate unused translations. For apps with many locales or large catalogs, code splitting loads locale data on demand.

  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. Configure chunkLoader to dynamically import locale chunks
  4. When setLocale() is called, the chunk is loaded before switching

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

Configure the plugin:

const i18n = createFluentVue({
locale: 'en',
messages: { en },
splitting: true,
chunkLoader: (locale) => import(`./locales/compiled/${locale}.js`),
})
Strategysplitting: 'static'splitting: 'dynamic'
BundleAll locales in bundle, tree-shakenOnly default locale bundled
LoadingSync — no loading statesAsync — needs isLoading handling
Best forFew locales, small catalogsMany locales, large catalogs

Configure in fluenti.config.ts:

import { defineConfig } from '@fluenti/cli'
export default defineConfig({
splitting: 'dynamic',
defaultBuildLocale: 'en',
})
SplittingWhen to useTrade-off
false≤ 3 locales, small catalogSimplest — everything bundled
'static'Known set of locales, moderate catalogLocale loaded at startup, no lazy requests
'dynamic'Many locales or large catalogSmallest initial bundle, async locale switch
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>