@intlayer/docs 8.6.0 → 8.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/doc.cjs.map +1 -1
- package/dist/cjs/generated/docs.entry.cjs +60 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/doc.mjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +60 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/doc.d.ts.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +3 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/cli/index.md +54 -42
- package/docs/ar/cli/init.md +32 -20
- package/docs/ar/cli/standalone.md +91 -0
- package/docs/ar/configuration.md +39 -7
- package/docs/ar/custom_domains.md +250 -0
- package/docs/ar/intlayer_with_tanstack+solid.md +14 -33
- package/docs/ar/intlayer_with_tanstack.md +25 -16
- package/docs/ar/intlayer_with_vanilla.md +506 -0
- package/docs/bn/cli/index.md +195 -0
- package/docs/bn/cli/init.md +96 -0
- package/docs/bn/cli/standalone.md +91 -0
- package/docs/bn/configuration.md +46 -14
- package/docs/bn/custom_domains.md +250 -0
- package/docs/bn/intlayer_with_vanilla.md +506 -0
- package/docs/cs/cli/index.md +195 -0
- package/docs/cs/cli/init.md +96 -0
- package/docs/cs/cli/standalone.md +91 -0
- package/docs/cs/configuration.md +46 -7
- package/docs/cs/custom_domains.md +250 -0
- package/docs/cs/intlayer_with_vanilla.md +506 -0
- package/docs/de/cli/index.md +53 -41
- package/docs/de/cli/standalone.md +91 -0
- package/docs/de/configuration.md +46 -7
- package/docs/de/custom_domains.md +250 -0
- package/docs/de/intlayer_with_tanstack+solid.md +15 -36
- package/docs/de/intlayer_with_tanstack.md +25 -16
- package/docs/de/intlayer_with_vanilla.md +506 -0
- package/docs/en/bundle_optimization.md +288 -23
- package/docs/en/cli/index.md +6 -1
- package/docs/en/cli/init.md +13 -1
- package/docs/en/cli/standalone.md +91 -0
- package/docs/en/configuration.md +46 -7
- package/docs/en/custom_domains.md +245 -0
- package/docs/en/intlayer_with_tanstack+solid.md +15 -36
- package/docs/en/intlayer_with_tanstack.md +25 -16
- package/docs/en/intlayer_with_vanilla.md +506 -0
- package/docs/en-GB/cli/index.md +56 -44
- package/docs/en-GB/cli/init.md +28 -21
- package/docs/en-GB/cli/standalone.md +91 -0
- package/docs/en-GB/configuration.md +53 -14
- package/docs/en-GB/custom_domains.md +250 -0
- package/docs/en-GB/intlayer_with_tanstack+solid.md +15 -36
- package/docs/en-GB/intlayer_with_tanstack.md +25 -16
- package/docs/en-GB/intlayer_with_vanilla.md +506 -0
- package/docs/es/cli/index.md +65 -53
- package/docs/es/cli/init.md +33 -21
- package/docs/es/cli/standalone.md +91 -0
- package/docs/es/configuration.md +39 -1
- package/docs/es/custom_domains.md +250 -0
- package/docs/es/intlayer_with_tanstack+solid.md +15 -36
- package/docs/es/intlayer_with_tanstack.md +25 -16
- package/docs/es/intlayer_with_vanilla.md +506 -0
- package/docs/fr/cli/index.md +43 -31
- package/docs/fr/cli/init.md +37 -25
- package/docs/fr/cli/standalone.md +91 -0
- package/docs/fr/configuration.md +46 -7
- package/docs/fr/custom_domains.md +250 -0
- package/docs/fr/intlayer_with_tanstack+solid.md +15 -36
- package/docs/fr/intlayer_with_tanstack.md +25 -16
- package/docs/fr/intlayer_with_vanilla.md +506 -0
- package/docs/hi/cli/index.md +71 -59
- package/docs/hi/cli/init.md +37 -33
- package/docs/hi/cli/standalone.md +91 -0
- package/docs/hi/configuration.md +39 -7
- package/docs/hi/custom_domains.md +250 -0
- package/docs/hi/intlayer_with_tanstack+solid.md +14 -33
- package/docs/hi/intlayer_with_tanstack.md +25 -16
- package/docs/hi/intlayer_with_vanilla.md +506 -0
- package/docs/id/cli/index.md +59 -47
- package/docs/id/cli/init.md +32 -25
- package/docs/id/cli/standalone.md +91 -0
- package/docs/id/configuration.md +46 -7
- package/docs/id/custom_domains.md +250 -0
- package/docs/id/intlayer_with_tanstack+solid.md +14 -33
- package/docs/id/intlayer_with_tanstack.md +25 -16
- package/docs/id/intlayer_with_vanilla.md +506 -0
- package/docs/it/cli/index.md +58 -41
- package/docs/it/cli/init.md +37 -38
- package/docs/it/cli/standalone.md +91 -0
- package/docs/it/configuration.md +46 -7
- package/docs/it/custom_domains.md +250 -0
- package/docs/it/intlayer_with_tanstack+solid.md +15 -36
- package/docs/it/intlayer_with_tanstack.md +25 -16
- package/docs/it/intlayer_with_vanilla.md +506 -0
- package/docs/ja/cli/index.md +59 -47
- package/docs/ja/cli/init.md +36 -24
- package/docs/ja/cli/standalone.md +91 -0
- package/docs/ja/configuration.md +46 -7
- package/docs/ja/custom_domains.md +250 -0
- package/docs/ja/intlayer_with_tanstack+solid.md +15 -36
- package/docs/ja/intlayer_with_tanstack.md +25 -16
- package/docs/ja/intlayer_with_vanilla.md +506 -0
- package/docs/ko/cli/index.md +58 -46
- package/docs/ko/cli/init.md +39 -35
- package/docs/ko/cli/standalone.md +91 -0
- package/docs/ko/configuration.md +47 -8
- package/docs/ko/custom_domains.md +250 -0
- package/docs/ko/intlayer_with_tanstack+solid.md +15 -36
- package/docs/ko/intlayer_with_tanstack.md +25 -16
- package/docs/ko/intlayer_with_vanilla.md +506 -0
- package/docs/nl/cli/index.md +195 -0
- package/docs/nl/cli/init.md +96 -0
- package/docs/nl/cli/standalone.md +91 -0
- package/docs/nl/configuration.md +46 -7
- package/docs/nl/custom_domains.md +250 -0
- package/docs/nl/intlayer_with_vanilla.md +506 -0
- package/docs/pl/cli/index.md +56 -44
- package/docs/pl/cli/init.md +36 -32
- package/docs/pl/cli/standalone.md +91 -0
- package/docs/pl/configuration.md +46 -7
- package/docs/pl/custom_domains.md +250 -0
- package/docs/pl/intlayer_with_tanstack+solid.md +14 -33
- package/docs/pl/intlayer_with_tanstack.md +25 -16
- package/docs/pl/intlayer_with_vanilla.md +506 -0
- package/docs/pt/cli/index.md +64 -52
- package/docs/pt/cli/init.md +35 -31
- package/docs/pt/cli/standalone.md +91 -0
- package/docs/pt/configuration.md +46 -7
- package/docs/pt/custom_domains.md +250 -0
- package/docs/pt/intlayer_with_tanstack+solid.md +15 -36
- package/docs/pt/intlayer_with_tanstack.md +25 -16
- package/docs/pt/intlayer_with_vanilla.md +506 -0
- package/docs/ru/cli/index.md +54 -42
- package/docs/ru/cli/init.md +31 -27
- package/docs/ru/cli/standalone.md +91 -0
- package/docs/ru/configuration.md +46 -7
- package/docs/ru/custom_domains.md +250 -0
- package/docs/ru/intlayer_with_tanstack+solid.md +15 -36
- package/docs/ru/intlayer_with_tanstack.md +25 -16
- package/docs/ru/intlayer_with_vanilla.md +506 -0
- package/docs/tr/cli/index.md +64 -52
- package/docs/tr/cli/init.md +37 -30
- package/docs/tr/cli/standalone.md +91 -0
- package/docs/tr/configuration.md +46 -7
- package/docs/tr/custom_domains.md +250 -0
- package/docs/tr/intlayer_with_tanstack+solid.md +14 -33
- package/docs/tr/intlayer_with_tanstack.md +25 -16
- package/docs/tr/intlayer_with_vanilla.md +506 -0
- package/docs/uk/cli/index.md +60 -55
- package/docs/uk/cli/init.md +32 -20
- package/docs/uk/cli/standalone.md +91 -0
- package/docs/uk/configuration.md +46 -7
- package/docs/uk/custom_domains.md +250 -0
- package/docs/uk/intlayer_with_tanstack+solid.md +14 -33
- package/docs/uk/intlayer_with_tanstack.md +25 -16
- package/docs/uk/intlayer_with_vanilla.md +506 -0
- package/docs/ur/cli/index.md +195 -0
- package/docs/ur/cli/init.md +96 -0
- package/docs/ur/cli/standalone.md +91 -0
- package/docs/ur/configuration.md +46 -7
- package/docs/ur/custom_domains.md +250 -0
- package/docs/ur/intlayer_with_vanilla.md +506 -0
- package/docs/vi/cli/index.md +72 -61
- package/docs/vi/cli/init.md +33 -21
- package/docs/vi/cli/standalone.md +91 -0
- package/docs/vi/configuration.md +46 -7
- package/docs/vi/custom_domains.md +250 -0
- package/docs/vi/intlayer_with_tanstack+solid.md +14 -33
- package/docs/vi/intlayer_with_tanstack.md +25 -16
- package/docs/vi/intlayer_with_vanilla.md +506 -0
- package/docs/zh/cli/index.md +56 -49
- package/docs/zh/cli/init.md +30 -18
- package/docs/zh/cli/standalone.md +91 -0
- package/docs/zh/configuration.md +46 -7
- package/docs/zh/custom_domains.md +250 -0
- package/docs/zh/intlayer_with_tanstack+solid.md +15 -36
- package/docs/zh/intlayer_with_tanstack.md +25 -16
- package/docs/zh/intlayer_with_vanilla.md +506 -0
- package/package.json +8 -8
- package/src/doc.ts +4 -1
- package/src/generated/docs.entry.ts +60 -0
- package/docs/ar/bundle_optimization.md +0 -185
- package/docs/de/bundle_optimization.md +0 -195
- package/docs/en-GB/bundle_optimization.md +0 -184
- package/docs/es/bundle_optimization.md +0 -194
- package/docs/fr/bundle_optimization.md +0 -184
- package/docs/hi/bundle_optimization.md +0 -185
- package/docs/id/bundle_optimization.md +0 -185
- package/docs/it/bundle_optimization.md +0 -185
- package/docs/ja/bundle_optimization.md +0 -185
- package/docs/ko/bundle_optimization.md +0 -185
- package/docs/pl/bundle_optimization.md +0 -185
- package/docs/pt/bundle_optimization.md +0 -184
- package/docs/ru/bundle_optimization.md +0 -185
- package/docs/tr/bundle_optimization.md +0 -184
- package/docs/uk/bundle_optimization.md +0 -186
- package/docs/vi/bundle_optimization.md +0 -185
- package/docs/zh/bundle_optimization.md +0 -185
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2025-11-25
|
|
3
|
-
updatedAt: 2025-11-25
|
|
4
|
-
title: Mengoptimalkan Ukuran & Performa Bundle i18n
|
|
5
|
-
description: Mengurangi ukuran bundle aplikasi dengan mengoptimalkan konten internasionalisasi (i18n). Pelajari cara memanfaatkan tree shaking dan lazy loading untuk kamus dengan Intlayer.
|
|
6
|
-
keywords:
|
|
7
|
-
- Optimasi Bundle
|
|
8
|
-
- Otomasi Konten
|
|
9
|
-
- Konten Dinamis
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Next.js
|
|
12
|
-
- JavaScript
|
|
13
|
-
- React
|
|
14
|
-
slugs:
|
|
15
|
-
- doc
|
|
16
|
-
- concept
|
|
17
|
-
- bundle-optimization
|
|
18
|
-
history:
|
|
19
|
-
- version: 6.0.0
|
|
20
|
-
date: 2025-11-25
|
|
21
|
-
changes: "Inisialisasi riwayat"
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
# Mengoptimalkan Ukuran & Performa Bundle i18n
|
|
25
|
-
|
|
26
|
-
Salah satu tantangan paling umum dengan solusi i18n tradisional yang mengandalkan file JSON adalah mengelola ukuran konten. Jika pengembang tidak secara manual memisahkan konten ke dalam namespace, pengguna sering kali harus mengunduh terjemahan untuk setiap halaman dan berpotensi setiap bahasa hanya untuk melihat satu halaman saja.
|
|
27
|
-
|
|
28
|
-
Misalnya, sebuah aplikasi dengan 10 halaman yang diterjemahkan ke dalam 10 bahasa mungkin mengakibatkan pengguna mengunduh konten dari 100 halaman, meskipun mereka hanya membutuhkan **satu** (halaman saat ini dalam bahasa saat ini). Hal ini menyebabkan pemborosan bandwidth dan waktu muat yang lebih lambat.
|
|
29
|
-
|
|
30
|
-
> Untuk mendeteksinya, Anda dapat menggunakan bundle analyzer seperti `rollup-plugin-visualizer` (vite), `@next/bundle-analyzer` (next.js), atau `webpack-bundle-analyzer` (React CRA / Angular / dll).
|
|
31
|
-
|
|
32
|
-
**Intlayer menyelesaikan masalah ini melalui optimasi saat build.** Intlayer menganalisis kode Anda untuk mendeteksi kamus mana yang benar-benar digunakan per komponen dan hanya menyuntikkan kembali konten yang diperlukan ke dalam bundle Anda.
|
|
33
|
-
|
|
34
|
-
## Daftar Isi
|
|
35
|
-
|
|
36
|
-
<TOC />
|
|
37
|
-
|
|
38
|
-
## Cara Kerjanya
|
|
39
|
-
|
|
40
|
-
Intlayer menggunakan **pendekatan per-komponen**. Berbeda dengan file JSON global, konten Anda didefinisikan berdampingan atau di dalam komponen Anda. Selama proses build, Intlayer:
|
|
41
|
-
|
|
42
|
-
1. **Menganalisis** kode Anda untuk menemukan panggilan `useIntlayer`.
|
|
43
|
-
2. **Membangun** konten kamus yang sesuai.
|
|
44
|
-
3. **Mengganti** panggilan `useIntlayer` dengan kode yang dioptimalkan berdasarkan konfigurasi Anda.
|
|
45
|
-
|
|
46
|
-
Ini memastikan bahwa:
|
|
47
|
-
|
|
48
|
-
- Jika sebuah komponen tidak diimpor, kontennya tidak disertakan dalam bundle (Eliminasi Kode Mati).
|
|
49
|
-
- Jika sebuah komponen dimuat secara lazy, kontennya juga dimuat secara lazy.
|
|
50
|
-
|
|
51
|
-
## Setup berdasarkan Platform
|
|
52
|
-
|
|
53
|
-
### Next.js
|
|
54
|
-
|
|
55
|
-
Next.js memerlukan plugin `@intlayer/swc` untuk menangani transformasi, karena Next.js menggunakan SWC untuk proses build.
|
|
56
|
-
|
|
57
|
-
> Plugin ini terpasang secara default karena plugin SWC masih bersifat eksperimental untuk Next.js. Hal ini mungkin akan berubah di masa depan.
|
|
58
|
-
|
|
59
|
-
### Vite
|
|
60
|
-
|
|
61
|
-
Vite menggunakan plugin `@intlayer/babel` yang sudah termasuk sebagai dependensi dari `vite-intlayer`. Optimasi ini diaktifkan secara default.
|
|
62
|
-
|
|
63
|
-
### Webpack
|
|
64
|
-
|
|
65
|
-
Untuk mengaktifkan optimasi bundle dengan Intlayer pada Webpack, Anda perlu menginstal dan mengonfigurasi plugin Babel (`@intlayer/babel`) atau SWC (`@intlayer/swc`) yang sesuai.
|
|
66
|
-
|
|
67
|
-
### Expo / Lynx
|
|
68
|
-
|
|
69
|
-
Optimasi bundle **belum tersedia** untuk platform ini. Dukungan akan ditambahkan pada rilis mendatang.
|
|
70
|
-
|
|
71
|
-
## Konfigurasi
|
|
72
|
-
|
|
73
|
-
Anda dapat mengontrol bagaimana Intlayer mengoptimalkan bundle Anda melalui properti `build` di dalam `intlayer.config.ts` Anda.
|
|
74
|
-
|
|
75
|
-
```typescript fileName="intlayer.config.ts"
|
|
76
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
77
|
-
|
|
78
|
-
const config: IntlayerConfig = {
|
|
79
|
-
internationalization: {
|
|
80
|
-
locales: [Locales.ENGLISH, Locales.FRENCH],
|
|
81
|
-
defaultLocale: Locales.ENGLISH,
|
|
82
|
-
},
|
|
83
|
-
dictionary: {},
|
|
84
|
-
build: {
|
|
85
|
-
optimize: true,
|
|
86
|
-
importMode: "static", // atau 'dynamic'
|
|
87
|
-
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default config;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
> Menjaga opsi default untuk `optimize` direkomendasikan dalam sebagian besar kasus.
|
|
95
|
-
|
|
96
|
-
> Lihat dokumentasi konfigurasi untuk detail lebih lanjut: [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/configuration.md)
|
|
97
|
-
|
|
98
|
-
### Opsi Build
|
|
99
|
-
|
|
100
|
-
Opsi berikut tersedia di bawah objek konfigurasi `build`:
|
|
101
|
-
|
|
102
|
-
| Properti | Tipe | Default | Deskripsi |
|
|
103
|
-
| :-------------------- | :------------------------------- | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
-
| **`optimize`** | `boolean` | `undefined` | Mengontrol apakah optimasi build diaktifkan. Jika `true`, Intlayer menggantikan pemanggilan kamus dengan injeksi yang dioptimalkan. Jika `false`, optimasi dinonaktifkan. Idealnya diatur ke `true` pada produksi. |
|
|
105
|
-
| **`importMode`** | `'static' , 'dynamic' , 'fetch'` | `'static'` | **Deprecated**: Use `dictionary.importMode` instead. Menentukan bagaimana kamus dimuat (lihat detail di bawah). |
|
|
106
|
-
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Pola glob yang menentukan file mana yang harus dipindai oleh Intlayer untuk optimasi. Gunakan ini untuk mengecualikan file yang tidak terkait dan mempercepat proses build. |
|
|
107
|
-
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | Mengontrol format output dari kamus yang dibangun. |
|
|
108
|
-
|
|
109
|
-
## Mode Impor
|
|
110
|
-
|
|
111
|
-
Pengaturan `importMode` menentukan bagaimana konten kamus disuntikkan ke dalam komponen Anda.
|
|
112
|
-
|
|
113
|
-
### 1. Mode Statis (`default`)
|
|
114
|
-
|
|
115
|
-
Dalam mode statis, Intlayer menggantikan `useIntlayer` dengan `useDictionary` dan menyuntikkan kamus langsung ke dalam bundle JavaScript.
|
|
116
|
-
|
|
117
|
-
- **Kelebihan:** Rendering instan (sinkron), tanpa permintaan jaringan tambahan selama hidrasi.
|
|
118
|
-
- **Kekurangan:** Bundle menyertakan terjemahan untuk **semua** bahasa yang tersedia untuk komponen tersebut.
|
|
119
|
-
- **Cocok untuk:** Single Page Applications (SPA).
|
|
120
|
-
|
|
121
|
-
**Contoh Kode yang Dioptimalkan:**
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
// Kode Anda
|
|
125
|
-
const content = useIntlayer("my-key");
|
|
126
|
-
|
|
127
|
-
// Kode yang Dioptimalkan (Statis)
|
|
128
|
-
const content = useDictionary({
|
|
129
|
-
key: "my-key",
|
|
130
|
-
content: {
|
|
131
|
-
nodeType: "translation",
|
|
132
|
-
translation: {
|
|
133
|
-
en: "My title",
|
|
134
|
-
fr: "Mon titre",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Mode Dinamis
|
|
141
|
-
|
|
142
|
-
Dalam mode dinamis, Intlayer menggantikan `useIntlayer` dengan `useDictionaryAsync`. Ini menggunakan `import()` (mekanisme mirip Suspense) untuk memuat malas secara spesifik JSON untuk locale saat ini.
|
|
143
|
-
|
|
144
|
-
- **Kelebihan:** **Tree shaking tingkat locale.** Pengguna yang melihat versi bahasa Inggris akan _hanya_ mengunduh kamus bahasa Inggris. Kamus bahasa Prancis tidak pernah dimuat.
|
|
145
|
-
- **Kekurangan:** Memicu permintaan jaringan (pengambilan aset) per komponen selama hidrasi.
|
|
146
|
-
- **Terbaik untuk:** Blok teks besar, artikel, atau aplikasi yang mendukung banyak bahasa di mana ukuran bundle sangat penting.
|
|
147
|
-
|
|
148
|
-
**Contoh Kode yang Dioptimalkan:**
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
// Kode Anda
|
|
152
|
-
const content = useIntlayer("my-key");
|
|
153
|
-
|
|
154
|
-
// Kode yang Dioptimalkan (Dinamis)
|
|
155
|
-
const content = useDictionaryAsync({
|
|
156
|
-
en: () =>
|
|
157
|
-
import(".intlayer/dynamic_dictionary/my-key/en.json").then(
|
|
158
|
-
(mod) => mod.default
|
|
159
|
-
),
|
|
160
|
-
fr: () =>
|
|
161
|
-
import(".intlayer/dynamic_dictionary/my-key/fr.json").then(
|
|
162
|
-
(mod) => mod.default
|
|
163
|
-
),
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
> Saat menggunakan `importMode: 'dynamic'`, jika Anda memiliki 100 komponen yang menggunakan `useIntlayer` pada satu halaman, browser akan mencoba melakukan 100 pengambilan terpisah. Untuk menghindari "air terjun" permintaan ini, kelompokkan konten ke dalam lebih sedikit file `.content` (misalnya, satu kamus per bagian halaman) daripada satu per komponen atom.
|
|
168
|
-
|
|
169
|
-
> Saat ini, `importMode: 'dynamic'` belum sepenuhnya didukung untuk Vue dan Svelte. Disarankan menggunakan `importMode: 'static'` untuk framework ini sampai pembaruan lebih lanjut.
|
|
170
|
-
|
|
171
|
-
### 3. Mode Live
|
|
172
|
-
|
|
173
|
-
Berperilaku mirip dengan mode Dynamic tetapi mencoba mengambil kamus dari Intlayer Live Sync API terlebih dahulu. Jika panggilan API gagal atau konten tidak ditandai untuk pembaruan langsung, maka akan kembali ke impor dinamis.
|
|
174
|
-
|
|
175
|
-
> Lihat dokumentasi CMS untuk detail lebih lanjut: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/id/intlayer_CMS.md)
|
|
176
|
-
|
|
177
|
-
## Ringkasan: Static vs Dynamic
|
|
178
|
-
|
|
179
|
-
| Fitur | Mode Static | Mode Dynamic |
|
|
180
|
-
| :------------------- | :------------------------------------------------- | :---------------------------------------- |
|
|
181
|
-
| **Ukuran Bundle JS** | Lebih besar (termasuk semua bahasa untuk komponen) | Paling kecil (hanya kode, tanpa konten) |
|
|
182
|
-
| **Initial Load** | Instan (Konten ada dalam bundle) | Sedikit penundaan (Mengambil JSON) |
|
|
183
|
-
| **Network Requests** | 0 permintaan tambahan | 1 permintaan per kamus |
|
|
184
|
-
| **Tree Shaking** | Tingkat komponen | Tingkat komponen + tingkat lokal |
|
|
185
|
-
| **Best Use Case** | Komponen UI, Aplikasi kecil | Halaman dengan banyak teks, Banyak Bahasa |
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2025-11-25
|
|
3
|
-
updatedAt: 2025-11-25
|
|
4
|
-
title: Ottimizzazione della Dimensione e delle Prestazioni del Bundle i18n
|
|
5
|
-
description: Riduci la dimensione del bundle dell'applicazione ottimizzando i contenuti di internazionalizzazione (i18n). Scopri come sfruttare il tree shaking e il lazy loading per i dizionari con Intlayer.
|
|
6
|
-
keywords:
|
|
7
|
-
- Ottimizzazione del Bundle
|
|
8
|
-
- Automazione dei Contenuti
|
|
9
|
-
- Contenuti Dinamici
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Next.js
|
|
12
|
-
- JavaScript
|
|
13
|
-
- React
|
|
14
|
-
slugs:
|
|
15
|
-
- doc
|
|
16
|
-
- concept
|
|
17
|
-
- bundle-optimization
|
|
18
|
-
history:
|
|
19
|
-
- version: 6.0.0
|
|
20
|
-
date: 2025-11-25
|
|
21
|
-
changes: "Inizializzazione della cronologia"
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
# Ottimizzazione della Dimensione e delle Prestazioni del Bundle i18n
|
|
25
|
-
|
|
26
|
-
Una delle sfide più comuni con le soluzioni i18n tradizionali basate su file JSON è la gestione della dimensione dei contenuti. Se gli sviluppatori non separano manualmente i contenuti in namespace, gli utenti spesso finiscono per scaricare le traduzioni di ogni pagina e potenzialmente di ogni lingua solo per visualizzare una singola pagina.
|
|
27
|
-
|
|
28
|
-
Ad esempio, un'applicazione con 10 pagine tradotte in 10 lingue potrebbe far sì che un utente scarichi il contenuto di 100 pagine, anche se ha bisogno solo di **una** (la pagina corrente nella lingua corrente). Questo comporta uno spreco di banda e tempi di caricamento più lenti.
|
|
29
|
-
|
|
30
|
-
> Per rilevarlo, puoi utilizzare un bundle analyzer come `rollup-plugin-visualizer` (vite), `@next/bundle-analyzer` (next.js) o `webpack-bundle-analyzer` (React CRA / Angular / ecc).
|
|
31
|
-
|
|
32
|
-
**Intlayer risolve questo problema attraverso l'ottimizzazione in fase di build.** Analizza il tuo codice per rilevare quali dizionari sono effettivamente utilizzati per ogni componente e reinserisce solo il contenuto necessario nel tuo bundle.
|
|
33
|
-
|
|
34
|
-
## Indice
|
|
35
|
-
|
|
36
|
-
<TOC />
|
|
37
|
-
|
|
38
|
-
## Come Funziona
|
|
39
|
-
|
|
40
|
-
Intlayer utilizza un **approccio per componente**. A differenza dei file JSON globali, il tuo contenuto è definito accanto o all'interno dei tuoi componenti. Durante il processo di build, Intlayer:
|
|
41
|
-
|
|
42
|
-
1. **Analizza** il tuo codice per trovare le chiamate a `useIntlayer`.
|
|
43
|
-
2. **Costruisce** il contenuto del dizionario corrispondente.
|
|
44
|
-
3. **Sostituisce** la chiamata a `useIntlayer` con codice ottimizzato basato sulla tua configurazione.
|
|
45
|
-
|
|
46
|
-
Questo garantisce che:
|
|
47
|
-
|
|
48
|
-
- Se un componente non è importato, il suo contenuto non viene incluso nel bundle (Eliminazione del codice morto).
|
|
49
|
-
- Se un componente è caricato in modo lazy, anche il suo contenuto viene caricato in modo lazy.
|
|
50
|
-
|
|
51
|
-
## Configurazione per Piattaforma
|
|
52
|
-
|
|
53
|
-
### Next.js
|
|
54
|
-
|
|
55
|
-
Next.js richiede il plugin `@intlayer/swc` per gestire la trasformazione, poiché Next.js utilizza SWC per le build.
|
|
56
|
-
|
|
57
|
-
> Questo plugin è installato di default perché i plugin SWC sono ancora sperimentali per Next.js. Potrebbe cambiare in futuro.
|
|
58
|
-
|
|
59
|
-
### Vite
|
|
60
|
-
|
|
61
|
-
Vite utilizza il plugin `@intlayer/babel` che è incluso come dipendenza di `vite-intlayer`. L'ottimizzazione è abilitata di default.
|
|
62
|
-
|
|
63
|
-
### Webpack
|
|
64
|
-
|
|
65
|
-
Per abilitare l'ottimizzazione del bundle con Intlayer su Webpack, è necessario installare e configurare il plugin Babel (`@intlayer/babel`) o SWC (`@intlayer/swc`) appropriato.
|
|
66
|
-
|
|
67
|
-
### Expo / Lynx
|
|
68
|
-
|
|
69
|
-
L'ottimizzazione del bundle **non è ancora disponibile** per questa piattaforma. Il supporto sarà aggiunto in una futura release.
|
|
70
|
-
|
|
71
|
-
## Configurazione
|
|
72
|
-
|
|
73
|
-
Puoi controllare come Intlayer ottimizza il tuo bundle tramite la proprietà `build` nel tuo file `intlayer.config.ts`.
|
|
74
|
-
|
|
75
|
-
```typescript fileName="intlayer.config.ts"
|
|
76
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
77
|
-
|
|
78
|
-
const config: IntlayerConfig = {
|
|
79
|
-
internationalization: {
|
|
80
|
-
locales: [Locales.ENGLISH, Locales.FRENCH],
|
|
81
|
-
defaultLocale: Locales.ENGLISH,
|
|
82
|
-
},
|
|
83
|
-
dictionary: {},
|
|
84
|
-
build: {
|
|
85
|
-
optimize: true,
|
|
86
|
-
importMode: "static", // oppure 'dynamic'
|
|
87
|
-
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default config;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
> È consigliato mantenere l'opzione di default per `optimize` nella maggior parte dei casi.
|
|
95
|
-
|
|
96
|
-
> Consulta la documentazione per maggiori dettagli: [Configurazione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/configuration.md)
|
|
97
|
-
|
|
98
|
-
### Opzioni di Build
|
|
99
|
-
|
|
100
|
-
Le seguenti opzioni sono disponibili sotto l'oggetto di configurazione `build`:
|
|
101
|
-
|
|
102
|
-
| Proprietà | Tipo | Predefinito | Descrizione |
|
|
103
|
-
| :-------------------- | :------------------------------- | :------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
-
| **`optimize`** | `boolean` | `undefined` | Controlla se l'ottimizzazione della build è abilitata. Se `true`, Intlayer sostituisce le chiamate al dizionario con inject ottimizzati. Se `false`, l'ottimizzazione è disabilitata. Idealmente impostato a `true` in produzione. |
|
|
105
|
-
| **`importMode`** | `'static' , 'dynamic' , 'fetch'` | `'static'` | **Deprecated**: Use `dictionary.importMode` instead. Determina come vengono caricati i dizionari (vedi dettagli sotto). |
|
|
106
|
-
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Pattern glob che definiscono quali file Intlayer deve scansionare per l'ottimizzazione. Usalo per escludere file non correlati e velocizzare le build. |
|
|
107
|
-
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | Controlla il formato di output dei dizionari costruiti. |
|
|
108
|
-
|
|
109
|
-
## Modalità di Importazione
|
|
110
|
-
|
|
111
|
-
L'impostazione `importMode` determina come il contenuto del dizionario viene iniettato nel tuo componente.
|
|
112
|
-
|
|
113
|
-
### 1. Modalità Statica (`default`)
|
|
114
|
-
|
|
115
|
-
In modalità statica, Intlayer sostituisce `useIntlayer` con `useDictionary` e inietta il dizionario direttamente nel bundle JavaScript.
|
|
116
|
-
|
|
117
|
-
- **Vantaggi:** Rendering istantaneo (sincrono), nessuna richiesta di rete aggiuntiva durante l'hydration.
|
|
118
|
-
- **Svantaggi:** Il bundle include le traduzioni per **tutte** le lingue disponibili per quel componente specifico.
|
|
119
|
-
- **Ideale per:** Single Page Applications (SPA).
|
|
120
|
-
|
|
121
|
-
**Esempio di codice trasformato:**
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
// Il tuo codice
|
|
125
|
-
const content = useIntlayer("my-key");
|
|
126
|
-
|
|
127
|
-
// Codice ottimizzato (Statico)
|
|
128
|
-
const content = useDictionary({
|
|
129
|
-
key: "my-key",
|
|
130
|
-
content: {
|
|
131
|
-
nodeType: "translation",
|
|
132
|
-
translation: {
|
|
133
|
-
en: "My title",
|
|
134
|
-
fr: "Mon titre",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. Modalità Dinamica
|
|
141
|
-
|
|
142
|
-
In modalità dinamica, Intlayer sostituisce `useIntlayer` con `useDictionaryAsync`. Questo utilizza `import()` (meccanismo simile a Suspense) per caricare pigramente specificamente il JSON per la locale corrente.
|
|
143
|
-
|
|
144
|
-
- **Vantaggi:** **Tree shaking a livello di locale.** Un utente che visualizza la versione inglese scaricherà _solo_ il dizionario inglese. Il dizionario francese non viene mai caricato.
|
|
145
|
-
- **Svantaggi:** Genera una richiesta di rete (fetch dell'asset) per ogni componente durante l'hydration.
|
|
146
|
-
- **Ideale per:** Blocchi di testo grandi, articoli o applicazioni che supportano molte lingue dove la dimensione del bundle è critica.
|
|
147
|
-
|
|
148
|
-
**Esempio di codice trasformato:**
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
// Il tuo codice
|
|
152
|
-
const content = useIntlayer("my-key");
|
|
153
|
-
|
|
154
|
-
// Codice ottimizzato (Dinamico)
|
|
155
|
-
const content = useDictionaryAsync({
|
|
156
|
-
en: () =>
|
|
157
|
-
import(".intlayer/dynamic_dictionary/my-key/en.json").then(
|
|
158
|
-
(mod) => mod.default
|
|
159
|
-
),
|
|
160
|
-
fr: () =>
|
|
161
|
-
import(".intlayer/dynamic_dictionary/my-key/fr.json").then(
|
|
162
|
-
(mod) => mod.default
|
|
163
|
-
),
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
> Quando si utilizza `importMode: 'dynamic'`, se si hanno 100 componenti che usano `useIntlayer` in una singola pagina, il browser tenterà 100 richieste separate. Per evitare questa "cascata" di richieste, raggruppare il contenuto in meno file `.content` (ad esempio, un dizionario per sezione della pagina) invece di uno per ogni componente atomico.
|
|
168
|
-
|
|
169
|
-
> Attualmente, `importMode: 'dynamic'` non è completamente supportato per Vue e Svelte. Si consiglia di utilizzare `importMode: 'static'` per questi framework fino a futuri aggiornamenti.
|
|
170
|
-
|
|
171
|
-
### 3. Modalità Live
|
|
172
|
-
|
|
173
|
-
Si comporta in modo simile alla modalità Dynamic ma tenta prima di recuperare i dizionari dall'API Intlayer Live Sync. Se la chiamata API fallisce o il contenuto non è contrassegnato per aggiornamenti live, si ricade sull'importazione dinamica.
|
|
174
|
-
|
|
175
|
-
> Consulta la documentazione CMS per maggiori dettagli: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_CMS.md)
|
|
176
|
-
|
|
177
|
-
## Riepilogo: Static vs Dynamic
|
|
178
|
-
|
|
179
|
-
| Caratteristica | Modalità Static | Modalità Dynamic |
|
|
180
|
-
| :----------------------- | :----------------------------------------------------- | :-------------------------------------------- |
|
|
181
|
-
| **Dimensione Bundle JS** | Più grande (include tutte le lingue per il componente) | Più piccolo (solo codice, nessun contenuto) |
|
|
182
|
-
| **Caricamento Iniziale** | Istantaneo (Il contenuto è nel bundle) | Leggero ritardo (Recupera JSON) |
|
|
183
|
-
| **Richieste di Rete** | 0 richieste aggiuntive | 1 richiesta per dizionario |
|
|
184
|
-
| **Tree Shaking** | A livello di componente | A livello di componente + a livello di lingua |
|
|
185
|
-
| **Caso d'Uso Migliore** | Componenti UI, Piccole App | Pagine con molto testo, Molte lingue |
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
createdAt: 2025-11-25
|
|
3
|
-
updatedAt: 2025-11-25
|
|
4
|
-
title: i18n バンドルサイズとパフォーマンスの最適化
|
|
5
|
-
description: 国際化(i18n)コンテンツを最適化してアプリケーションのバンドルサイズを削減します。Intlayerを使った辞書のツリーシェイキングと遅延読み込みの活用方法を学びましょう。
|
|
6
|
-
keywords:
|
|
7
|
-
- バンドル最適化
|
|
8
|
-
- コンテンツ自動化
|
|
9
|
-
- 動的コンテンツ
|
|
10
|
-
- Intlayer
|
|
11
|
-
- Next.js
|
|
12
|
-
- JavaScript
|
|
13
|
-
- React
|
|
14
|
-
slugs:
|
|
15
|
-
- doc
|
|
16
|
-
- concept
|
|
17
|
-
- bundle-optimization
|
|
18
|
-
history:
|
|
19
|
-
- version: 6.0.0
|
|
20
|
-
date: 2025-11-25
|
|
21
|
-
changes: "初期履歴"
|
|
22
|
-
---
|
|
23
|
-
|
|
24
|
-
# i18n バンドルサイズとパフォーマンスの最適化
|
|
25
|
-
|
|
26
|
-
従来のJSONファイルに依存するi18nソリューションで最も一般的な課題の一つは、コンテンツサイズの管理です。開発者が手動でコンテンツをネームスペースに分割しない場合、ユーザーは単一のページを閲覧するためだけに、すべてのページや場合によってはすべての言語の翻訳をダウンロードしてしまうことがよくあります。
|
|
27
|
-
|
|
28
|
-
例えば、10ページが10言語に翻訳されたアプリケーションでは、ユーザーは実際に必要な**1ページ**(現在の言語の現在のページ)だけでよいにもかかわらず、100ページ分のコンテンツをダウンロードすることになりかねません。これにより、帯域幅の無駄遣いと読み込み時間の遅延が発生します。
|
|
29
|
-
|
|
30
|
-
> これを検出するには、`rollup-plugin-visualizer`(vite)、`@next/bundle-analyzer`(next.js)、`webpack-bundle-analyzer`(React CRA / Angular / など)といったバンドルアナライザーを使用できます。
|
|
31
|
-
|
|
32
|
-
**Intlayerはビルド時の最適化によってこの問題を解決します。** コードを解析して、各コンポーネントで実際に使用されている辞書を検出し、必要なコンテンツのみをバンドルに再注入します。
|
|
33
|
-
|
|
34
|
-
## 目次
|
|
35
|
-
|
|
36
|
-
<TOC />
|
|
37
|
-
|
|
38
|
-
## 仕組み
|
|
39
|
-
|
|
40
|
-
Intlayerは**コンポーネント単位のアプローチ**を採用しています。グローバルなJSONファイルとは異なり、コンテンツはコンポーネントのそばまたは内部に定義されます。ビルドプロセス中にIntlayerは以下を行います:
|
|
41
|
-
|
|
42
|
-
1. コードを**解析**して`useIntlayer`の呼び出しを見つけます。
|
|
43
|
-
2. 対応する辞書コンテンツを**構築**します。
|
|
44
|
-
3. 設定に基づいて`useIntlayer`の呼び出しを最適化されたコードに**置き換え**ます。
|
|
45
|
-
|
|
46
|
-
これにより以下が保証されます:
|
|
47
|
-
|
|
48
|
-
- コンポーネントがインポートされていなければ、そのコンテンツはバンドルに含まれません(デッドコード削除)。
|
|
49
|
-
- コンポーネントがレイジーロードされる場合、そのコンテンツもレイジーロードされます。
|
|
50
|
-
|
|
51
|
-
## プラットフォーム別セットアップ
|
|
52
|
-
|
|
53
|
-
### Next.js
|
|
54
|
-
|
|
55
|
-
Next.js はビルドに SWC を使用しているため、変換を処理するために `@intlayer/swc` プラグインが必要です。
|
|
56
|
-
|
|
57
|
-
> このプラグインは、Next.js における SWC プラグインがまだ実験的なため、デフォルトでインストールされています。将来的に変更される可能性があります。
|
|
58
|
-
|
|
59
|
-
### Vite
|
|
60
|
-
|
|
61
|
-
Vite は `vite-intlayer` の依存として含まれている `@intlayer/babel` プラグインを使用します。最適化はデフォルトで有効になっています。
|
|
62
|
-
|
|
63
|
-
### Webpack
|
|
64
|
-
|
|
65
|
-
Webpack で Intlayer のバンドル最適化を有効にするには、適切な Babel (`@intlayer/babel`) または SWC (`@intlayer/swc`) プラグインをインストールして設定する必要があります。
|
|
66
|
-
|
|
67
|
-
### Expo / Lynx
|
|
68
|
-
|
|
69
|
-
このプラットフォームではバンドル最適化は**まだ利用できません**。将来のリリースでサポートが追加される予定です。
|
|
70
|
-
|
|
71
|
-
## 設定
|
|
72
|
-
|
|
73
|
-
Intlayerがバンドルを最適化する方法は、`intlayer.config.ts`の`build`プロパティで制御できます。
|
|
74
|
-
|
|
75
|
-
```typescript fileName="intlayer.config.ts"
|
|
76
|
-
import { Locales, type IntlayerConfig } from "intlayer";
|
|
77
|
-
|
|
78
|
-
const config: IntlayerConfig = {
|
|
79
|
-
internationalization: {
|
|
80
|
-
locales: [Locales.ENGLISH, Locales.FRENCH],
|
|
81
|
-
defaultLocale: Locales.ENGLISH,
|
|
82
|
-
},
|
|
83
|
-
dictionary: {},
|
|
84
|
-
build: {
|
|
85
|
-
optimize: true,
|
|
86
|
-
importMode: "static", // または 'dynamic'
|
|
87
|
-
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export default config;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
> `optimize`のデフォルトオプションを維持することが、ほとんどの場合で推奨されます。
|
|
95
|
-
|
|
96
|
-
> 詳細はドキュメントの設定をご覧ください: [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)
|
|
97
|
-
|
|
98
|
-
### ビルドオプション
|
|
99
|
-
|
|
100
|
-
`build`構成オブジェクトの下で利用可能なオプションは以下の通りです:
|
|
101
|
-
|
|
102
|
-
| プロパティ | 型 | デフォルト | 説明 |
|
|
103
|
-
| :-------------------- | :------------------------------- | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
104
|
-
| **`optimize`** | `boolean` | `undefined` | ビルド最適化を有効にするかどうかを制御します。`true` の場合、Intlayer は辞書呼び出しを最適化されたインジェクトに置き換えます。`false` の場合、最適化は無効になります。通常は本番環境で `true` に設定します。 |
|
|
105
|
-
| **`importMode`** | `'static' , 'dynamic' , 'fetch'` | `'static'` | **Deprecated**: Use `dictionary.importMode` instead. 辞書の読み込み方法を決定します(詳細は以下を参照)。 |
|
|
106
|
-
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Intlayerが最適化のためにスキャンするファイルを定義するグロブパターン。関連のないファイルを除外し、ビルドを高速化するために使用します。 |
|
|
107
|
-
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | ビルドされた辞書の出力フォーマットを制御します。 |
|
|
108
|
-
|
|
109
|
-
## インポートモード
|
|
110
|
-
|
|
111
|
-
`importMode`設定は、辞書の内容がコンポーネントにどのように注入されるかを決定します。
|
|
112
|
-
|
|
113
|
-
### 1. スタティックモード(`default`)
|
|
114
|
-
|
|
115
|
-
静的モードでは、Intlayerは `useIntlayer` を `useDictionary` に置き換え、辞書を直接JavaScriptバンドルに注入します。
|
|
116
|
-
|
|
117
|
-
- **利点:** 即時レンダリング(同期的)、ハイドレーション時の追加ネットワークリクエストなし。
|
|
118
|
-
- **欠点:** バンドルにはその特定のコンポーネントに対する**すべての**利用可能な言語の翻訳が含まれます。
|
|
119
|
-
- **最適用途:** シングルページアプリケーション(SPA)。
|
|
120
|
-
|
|
121
|
-
**変換後のコード例:**
|
|
122
|
-
|
|
123
|
-
```tsx
|
|
124
|
-
// あなたのコード
|
|
125
|
-
const content = useIntlayer("my-key");
|
|
126
|
-
|
|
127
|
-
// 最適化されたコード(静的)
|
|
128
|
-
const content = useDictionary({
|
|
129
|
-
key: "my-key",
|
|
130
|
-
content: {
|
|
131
|
-
nodeType: "translation",
|
|
132
|
-
translation: {
|
|
133
|
-
en: "My title",
|
|
134
|
-
fr: "Mon titre",
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 2. 動的モード
|
|
141
|
-
|
|
142
|
-
動的モードでは、Intlayerは`useIntlayer`を`useDictionaryAsync`に置き換えます。これは`import()`(Suspenseのような仕組み)を使用して、現在のロケールのJSONを遅延ロードします。
|
|
143
|
-
|
|
144
|
-
- **利点:** **ロケール単位のツリーシェイキング。** 英語版を閲覧しているユーザーは英語の辞書のみをダウンロードし、フランス語の辞書は一切ロードされません。
|
|
145
|
-
- **欠点:** ハイドレーション時にコンポーネントごとにネットワークリクエスト(アセット取得)が発生します。
|
|
146
|
-
- **最適な用途:** 大きなテキストブロック、記事、多言語対応でバンドルサイズが重要なアプリケーション。
|
|
147
|
-
|
|
148
|
-
**変換後のコード例:**
|
|
149
|
-
|
|
150
|
-
```tsx
|
|
151
|
-
// あなたのコード
|
|
152
|
-
const content = useIntlayer("my-key");
|
|
153
|
-
|
|
154
|
-
// 最適化されたコード(動的)
|
|
155
|
-
const content = useDictionaryAsync({
|
|
156
|
-
en: () =>
|
|
157
|
-
import(".intlayer/dynamic_dictionary/my-key/en.json").then(
|
|
158
|
-
(mod) => mod.default
|
|
159
|
-
),
|
|
160
|
-
fr: () =>
|
|
161
|
-
import(".intlayer/dynamic_dictionary/my-key/fr.json").then(
|
|
162
|
-
(mod) => mod.default
|
|
163
|
-
),
|
|
164
|
-
});
|
|
165
|
-
```
|
|
166
|
-
|
|
167
|
-
> `importMode: 'dynamic'` を使用する場合、1ページに `useIntlayer` を使ったコンポーネントが100個あると、ブラウザは100回の個別フェッチを試みます。この「リクエストの滝」を避けるために、コンテンツをより少ない `.content` ファイル(例:ページセクションごとに1つの辞書)にまとめ、アトムコンポーネントごとに分けるのは避けてください。
|
|
168
|
-
|
|
169
|
-
> 現時点で、`importMode: 'dynamic'` は Vue と Svelte で完全にはサポートされていません。これらのフレームワークでは、今後のアップデートまで `importMode: 'static'` の使用を推奨します。
|
|
170
|
-
|
|
171
|
-
### 3. ライブモード
|
|
172
|
-
|
|
173
|
-
動的モードと同様に動作しますが、最初にIntlayer Live Sync APIから辞書を取得しようとします。API呼び出しが失敗した場合やコンテンツがライブ更新用にマークされていない場合は、動的インポートにフォールバックします。
|
|
174
|
-
|
|
175
|
-
> 詳細はCMSドキュメントをご覧ください: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_CMS.md)
|
|
176
|
-
|
|
177
|
-
## まとめ: 静的モード vs 動的モード
|
|
178
|
-
|
|
179
|
-
| 機能 | 静的モード | 動的モード |
|
|
180
|
-
| :------------------------- | :--------------------------------------- | :------------------------------------ |
|
|
181
|
-
| **JSバンドルサイズ** | 大きい(コンポーネントの全言語を含む) | 最小(コードのみ、コンテンツなし) |
|
|
182
|
-
| **初期読み込み** | 即時(コンテンツはバンドル内に含まれる) | わずかな遅延(JSONを取得) |
|
|
183
|
-
| **ネットワークリクエスト** | 追加リクエストなし | 辞書ごとに1リクエスト |
|
|
184
|
-
| **ツリーシェイキング** | コンポーネントレベル | コンポーネントレベル + ロケールレベル |
|
|
185
|
-
| **最適な使用例** | UIコンポーネント、小規模アプリ | テキスト量が多いページ、多言語対応 |
|