@intlayer/docs 7.3.0 → 7.3.2-canary.0
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/README.md +0 -2
- package/blog/ar/compiler_vs_declarative_i18n.md +1 -2
- package/blog/ar/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/de/compiler_vs_declarative_i18n.md +1 -2
- package/blog/de/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/en/compiler_vs_declarative_i18n.md +1 -2
- package/blog/en/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/en/list_i18n_technologies/frameworks/svelte.md +19 -3
- package/blog/en/list_i18n_technologies/frameworks/vue.md +16 -2
- package/blog/en-GB/compiler_vs_declarative_i18n.md +1 -2
- package/blog/en-GB/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/es/compiler_vs_declarative_i18n.md +1 -2
- package/blog/es/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/fr/compiler_vs_declarative_i18n.md +1 -2
- package/blog/fr/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/hi/compiler_vs_declarative_i18n.md +1 -2
- package/blog/hi/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/id/compiler_vs_declarative_i18n.md +1 -2
- package/blog/id/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/it/compiler_vs_declarative_i18n.md +1 -2
- package/blog/it/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/ja/compiler_vs_declarative_i18n.md +1 -2
- package/blog/ja/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/ko/compiler_vs_declarative_i18n.md +1 -2
- package/blog/ko/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/pl/compiler_vs_declarative_i18n.md +1 -2
- package/blog/pl/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/pt/compiler_vs_declarative_i18n.md +1 -2
- package/blog/pt/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/ru/compiler_vs_declarative_i18n.md +1 -2
- package/blog/ru/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/tr/compiler_vs_declarative_i18n.md +1 -2
- package/blog/tr/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/vi/compiler_vs_declarative_i18n.md +1 -2
- package/blog/vi/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/blog/zh/compiler_vs_declarative_i18n.md +1 -2
- package/blog/zh/list_i18n_technologies/frameworks/flutter.md +0 -22
- package/dist/cjs/generated/docs.entry.cjs +38 -0
- package/dist/cjs/generated/docs.entry.cjs.map +1 -1
- package/dist/esm/generated/docs.entry.mjs +38 -0
- package/dist/esm/generated/docs.entry.mjs.map +1 -1
- package/dist/types/generated/docs.entry.d.ts +2 -0
- package/dist/types/generated/docs.entry.d.ts.map +1 -1
- package/docs/ar/bundle_optimization.md +184 -0
- package/docs/ar/compiler.md +133 -0
- package/docs/ar/vs_code_extension.md +4 -0
- package/docs/de/bundle_optimization.md +194 -0
- package/docs/de/compiler.md +133 -0
- package/docs/de/how_works_intlayer.md +1 -1
- package/docs/de/vs_code_extension.md +4 -0
- package/docs/en/bundle_optimization.md +184 -0
- package/docs/en/compiler.md +133 -0
- package/docs/en/configuration.md +5 -2
- package/docs/en/how_works_intlayer.md +1 -1
- package/docs/en/vs_code_extension.md +7 -0
- package/docs/en-GB/bundle_optimization.md +184 -0
- package/docs/en-GB/compiler.md +133 -0
- package/docs/en-GB/how_works_intlayer.md +1 -1
- package/docs/en-GB/vs_code_extension.md +4 -0
- package/docs/es/bundle_optimization.md +194 -0
- package/docs/es/compiler.md +133 -0
- package/docs/es/how_works_intlayer.md +1 -1
- package/docs/es/vs_code_extension.md +4 -0
- package/docs/fr/bundle_optimization.md +184 -0
- package/docs/fr/compiler.md +133 -0
- package/docs/fr/how_works_intlayer.md +1 -1
- package/docs/fr/vs_code_extension.md +4 -0
- package/docs/hi/bundle_optimization.md +184 -0
- package/docs/hi/compiler.md +133 -0
- package/docs/hi/vs_code_extension.md +4 -0
- package/docs/id/bundle_optimization.md +184 -0
- package/docs/id/compiler.md +133 -0
- package/docs/id/how_works_intlayer.md +1 -1
- package/docs/id/vs_code_extension.md +4 -0
- package/docs/it/bundle_optimization.md +184 -0
- package/docs/it/compiler.md +133 -0
- package/docs/it/how_works_intlayer.md +1 -1
- package/docs/it/vs_code_extension.md +4 -0
- package/docs/ja/bundle_optimization.md +184 -0
- package/docs/ja/compiler.md +133 -0
- package/docs/ja/vs_code_extension.md +4 -0
- package/docs/ko/bundle_optimization.md +184 -0
- package/docs/ko/compiler.md +133 -0
- package/docs/ko/vs_code_extension.md +4 -0
- package/docs/pl/bundle_optimization.md +184 -0
- package/docs/pl/compiler.md +133 -0
- package/docs/pl/how_works_intlayer.md +1 -1
- package/docs/pl/vs_code_extension.md +4 -0
- package/docs/pt/bundle_optimization.md +184 -0
- package/docs/pt/compiler.md +133 -0
- package/docs/pt/how_works_intlayer.md +1 -1
- package/docs/pt/vs_code_extension.md +4 -0
- package/docs/ru/bundle_optimization.md +184 -0
- package/docs/ru/compiler.md +133 -0
- package/docs/ru/vs_code_extension.md +4 -0
- package/docs/tr/bundle_optimization.md +184 -0
- package/docs/tr/compiler.md +133 -0
- package/docs/tr/how_works_intlayer.md +1 -1
- package/docs/tr/vs_code_extension.md +4 -0
- package/docs/vi/bundle_optimization.md +184 -0
- package/docs/vi/compiler.md +133 -0
- package/docs/vi/vs_code_extension.md +4 -0
- package/docs/zh/bundle_optimization.md +184 -0
- package/docs/zh/compiler.md +133 -0
- package/docs/zh/vs_code_extension.md +4 -0
- package/package.json +8 -7
- package/src/generated/docs.entry.ts +38 -0
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
build: {
|
|
84
|
+
optimize: true,
|
|
85
|
+
importMode: "static", // oppure 'dynamic'
|
|
86
|
+
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default config;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> È consigliato mantenere l'opzione di default per `optimize` nella maggior parte dei casi.
|
|
94
|
+
|
|
95
|
+
> Consulta la documentazione per maggiori dettagli: [Configurazione](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/configuration.md)
|
|
96
|
+
|
|
97
|
+
### Opzioni di Build
|
|
98
|
+
|
|
99
|
+
Le seguenti opzioni sono disponibili sotto l'oggetto di configurazione `build`:
|
|
100
|
+
|
|
101
|
+
| Proprietà | Tipo | Predefinito | Descrizione |
|
|
102
|
+
| :-------------------- | :------------------------------ | :------------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| **`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. |
|
|
104
|
+
| **`importMode`** | `'static' , 'dynamic' , 'live'` | `'static'` | Determina come vengono caricati i dizionari (vedi dettagli sotto). |
|
|
105
|
+
| **`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. |
|
|
106
|
+
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | Controlla il formato di output dei dizionari costruiti. |
|
|
107
|
+
|
|
108
|
+
## Modalità di Importazione
|
|
109
|
+
|
|
110
|
+
L'impostazione `importMode` determina come il contenuto del dizionario viene iniettato nel tuo componente.
|
|
111
|
+
|
|
112
|
+
### 1. Modalità Statica (`default`)
|
|
113
|
+
|
|
114
|
+
In modalità statica, Intlayer sostituisce `useIntlayer` con `useDictionary` e inietta il dizionario direttamente nel bundle JavaScript.
|
|
115
|
+
|
|
116
|
+
- **Vantaggi:** Rendering istantaneo (sincrono), nessuna richiesta di rete aggiuntiva durante l'hydration.
|
|
117
|
+
- **Svantaggi:** Il bundle include le traduzioni per **tutte** le lingue disponibili per quel componente specifico.
|
|
118
|
+
- **Ideale per:** Single Page Applications (SPA).
|
|
119
|
+
|
|
120
|
+
**Esempio di codice trasformato:**
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// Il tuo codice
|
|
124
|
+
const content = useIntlayer("my-key");
|
|
125
|
+
|
|
126
|
+
// Codice ottimizzato (Statico)
|
|
127
|
+
const content = useDictionary({
|
|
128
|
+
key: "my-key",
|
|
129
|
+
content: {
|
|
130
|
+
nodeType: "translation",
|
|
131
|
+
translation: {
|
|
132
|
+
en: "My title",
|
|
133
|
+
fr: "Mon titre",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. Modalità Dinamica
|
|
140
|
+
|
|
141
|
+
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.
|
|
142
|
+
|
|
143
|
+
- **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.
|
|
144
|
+
- **Svantaggi:** Genera una richiesta di rete (fetch dell'asset) per ogni componente durante l'hydration.
|
|
145
|
+
- **Ideale per:** Blocchi di testo grandi, articoli o applicazioni che supportano molte lingue dove la dimensione del bundle è critica.
|
|
146
|
+
|
|
147
|
+
**Esempio di codice trasformato:**
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
// Il tuo codice
|
|
151
|
+
const content = useIntlayer("my-key");
|
|
152
|
+
|
|
153
|
+
// Codice ottimizzato (Dinamico)
|
|
154
|
+
const content = useDictionaryAsync({
|
|
155
|
+
en: () =>
|
|
156
|
+
import(".intlayer/dynamic_dictionary/my-key/en.json").then(
|
|
157
|
+
(mod) => mod.default
|
|
158
|
+
),
|
|
159
|
+
fr: () =>
|
|
160
|
+
import(".intlayer/dynamic_dictionary/my-key/fr.json").then(
|
|
161
|
+
(mod) => mod.default
|
|
162
|
+
),
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
> 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.
|
|
167
|
+
|
|
168
|
+
> Attualmente, `importMode: 'dynamic'` non è completamente supportato per Vue e Svelte. Si consiglia di utilizzare `importMode: 'static'` per questi framework fino a futuri aggiornamenti.
|
|
169
|
+
|
|
170
|
+
### 3. Modalità Live
|
|
171
|
+
|
|
172
|
+
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.
|
|
173
|
+
|
|
174
|
+
> Consulta la documentazione CMS per maggiori dettagli: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/intlayer_CMS.md)
|
|
175
|
+
|
|
176
|
+
## Riepilogo: Static vs Dynamic
|
|
177
|
+
|
|
178
|
+
| Caratteristica | Modalità Static | Modalità Dynamic |
|
|
179
|
+
| :----------------------- | :----------------------------------------------------- | :-------------------------------------------- |
|
|
180
|
+
| **Dimensione Bundle JS** | Più grande (include tutte le lingue per il componente) | Più piccolo (solo codice, nessun contenuto) |
|
|
181
|
+
| **Caricamento Iniziale** | Istantaneo (Il contenuto è nel bundle) | Leggero ritardo (Recupera JSON) |
|
|
182
|
+
| **Richieste di Rete** | 0 richieste aggiuntive | 1 richiesta per dizionario |
|
|
183
|
+
| **Tree Shaking** | A livello di componente | A livello di componente + a livello di lingua |
|
|
184
|
+
| **Caso d'Uso Migliore** | Componenti UI, Piccole App | Pagine con molto testo, Molte lingue |
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-09-09
|
|
3
|
+
updatedAt: 2025-09-09
|
|
4
|
+
title: Intlayer Compiler | Estrazione Automatica dei Contenuti per i18n
|
|
5
|
+
description: Automatizza il tuo processo di internazionalizzazione con Intlayer Compiler. Estrai contenuti direttamente dai tuoi componenti per un i18n più veloce ed efficiente in Vite, Next.js e altro.
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- Compiler
|
|
9
|
+
- Internazionalizzazione
|
|
10
|
+
- i18n
|
|
11
|
+
- Automazione
|
|
12
|
+
- Estrazione
|
|
13
|
+
- Velocità
|
|
14
|
+
- Vite
|
|
15
|
+
- Next.js
|
|
16
|
+
- React
|
|
17
|
+
- Vue
|
|
18
|
+
- Svelte
|
|
19
|
+
slugs:
|
|
20
|
+
- doc
|
|
21
|
+
- compiler
|
|
22
|
+
history:
|
|
23
|
+
- version: 7.3.1
|
|
24
|
+
date: 2025-11-27
|
|
25
|
+
changes: Rilascio Compiler
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Intlayer Compiler | Estrazione Automatica dei Contenuti per i18n
|
|
29
|
+
|
|
30
|
+
## Cos'è Intlayer Compiler?
|
|
31
|
+
|
|
32
|
+
Il **Intlayer Compiler** è uno strumento potente progettato per automatizzare il processo di internazionalizzazione (i18n) nelle tue applicazioni. Scansiona il tuo codice sorgente (JSX, TSX, Vue, Svelte) alla ricerca di dichiarazioni di contenuto, le estrae e genera automaticamente i file di dizionario necessari. Questo ti permette di mantenere i contenuti co-localizzati con i tuoi componenti mentre Intlayer gestisce la sincronizzazione e la gestione dei dizionari.
|
|
33
|
+
|
|
34
|
+
## Perché Usare Intlayer Compiler?
|
|
35
|
+
|
|
36
|
+
- **Automazione**: Elimina il copia-incolla manuale dei contenuti nei dizionari.
|
|
37
|
+
- **Velocità**: Estrazione dei contenuti ottimizzata per garantire che il processo di build rimanga veloce.
|
|
38
|
+
- **Esperienza Sviluppatore**: Mantieni le dichiarazioni di contenuto esattamente dove vengono utilizzate, migliorando la manutenibilità.
|
|
39
|
+
- **Aggiornamenti in tempo reale**: Supporta Hot Module Replacement (HMR) per un feedback immediato durante lo sviluppo.
|
|
40
|
+
|
|
41
|
+
Consulta il post sul blog [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/it/compiler_vs_declarative_i18n.md) per un confronto più approfondito.
|
|
42
|
+
|
|
43
|
+
## Perché non usare Intlayer Compiler?
|
|
44
|
+
|
|
45
|
+
Sebbene il compiler offra un'esperienza eccellente "funziona subito", introduce anche alcuni compromessi di cui dovresti essere consapevole:
|
|
46
|
+
|
|
47
|
+
- **Ambiguità euristica**: Il compiler deve indovinare cosa è contenuto orientato all'utente rispetto alla logica dell'applicazione (ad esempio, `className="active"`, codici di stato, ID prodotto). In codebase complesse, questo può portare a falsi positivi o stringhe mancate che richiedono annotazioni manuali ed eccezioni.
|
|
48
|
+
- **Estrazione solo statica**: L'estrazione basata sul compiler si basa sull'analisi statica. Le stringhe che esistono solo in fase di esecuzione (codici di errore API, campi CMS, ecc.) non possono essere scoperte o tradotte dal compiler da solo, quindi hai ancora bisogno di una strategia i18n di runtime complementare.
|
|
49
|
+
|
|
50
|
+
Per un confronto architetturale più approfondito, consulta il post sul blog [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/it/compiler_vs_declarative_i18n.md).
|
|
51
|
+
|
|
52
|
+
Come alternativa, per automatizzare il tuo processo i18n mantenendo il pieno controllo del tuo contenuto, Intlayer fornisce anche un comando di auto-estrazione `intlayer transform` (vedi [documentazione CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/cli/transform.md)), o il comando `Intlayer: extract content to Dictionary` dall'estensione Intlayer VS Code (vedi [documentazione estensione VS Code](https://github.com/aymericzip/intlayer/blob/main/docs/docs/it/vs_code_extension.md)).
|
|
53
|
+
|
|
54
|
+
## Utilizzo
|
|
55
|
+
|
|
56
|
+
### Vite
|
|
57
|
+
|
|
58
|
+
Per le applicazioni basate su Vite (React, Vue, Svelte, ecc.), il modo più semplice per utilizzare il compiler è tramite il plugin `vite-intlayer`.
|
|
59
|
+
|
|
60
|
+
#### Installazione
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install vite-intlayer
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Configurazione
|
|
67
|
+
|
|
68
|
+
Aggiorna il tuo `vite.config.ts` per includere il plugin `intlayerCompiler`:
|
|
69
|
+
|
|
70
|
+
```ts fileName="vite.config.ts"
|
|
71
|
+
import { defineConfig } from "vite";
|
|
72
|
+
import { intlayer, intlayerCompiler } from "vite-intlayer";
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
plugins: [
|
|
76
|
+
intlayer(),
|
|
77
|
+
intlayerCompiler(), // Aggiunge il plugin del compiler
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Supporto per Framework
|
|
83
|
+
|
|
84
|
+
Il plugin Vite rileva e gestisce automaticamente diversi tipi di file:
|
|
85
|
+
|
|
86
|
+
- **React / JSX / TSX**: Gestito nativamente.
|
|
87
|
+
- **Vue**: Richiede `@intlayer/vue-compiler`.
|
|
88
|
+
- **Svelte**: Richiede `@intlayer/svelte-compiler`.
|
|
89
|
+
|
|
90
|
+
Assicurati di installare il pacchetto compiler appropriato per il tuo framework:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Per Vue
|
|
94
|
+
npm install @intlayer/vue-compiler
|
|
95
|
+
|
|
96
|
+
# Per Svelte
|
|
97
|
+
npm install @intlayer/svelte-compiler
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Next.js (Babel)
|
|
101
|
+
|
|
102
|
+
Per Next.js o altre applicazioni basate su Webpack che utilizzano Babel, puoi configurare il compiler usando il plugin `@intlayer/babel`.
|
|
103
|
+
|
|
104
|
+
#### Installazione
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install @intlayer/babel
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Configurazione
|
|
111
|
+
|
|
112
|
+
Aggiorna il tuo `babel.config.js` (o `babel.config.json`) per includere il plugin di estrazione. Forniamo un helper `getExtractPluginOptions` per caricare automaticamente la tua configurazione Intlayer.
|
|
113
|
+
|
|
114
|
+
```js fileName="babel.config.js"
|
|
115
|
+
const {
|
|
116
|
+
intlayerExtractBabelPlugin,
|
|
117
|
+
intlayerOptimizeBabelPlugin,
|
|
118
|
+
getExtractPluginOptions,
|
|
119
|
+
getOptimizePluginOptions,
|
|
120
|
+
} = require("@intlayer/babel");
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
presets: ["next/babel"],
|
|
124
|
+
plugins: [
|
|
125
|
+
// Extract content from components into dictionaries
|
|
126
|
+
[intlayerExtractBabelPlugin, getExtractPluginOptions()],
|
|
127
|
+
// Optimize imports by replacing useIntlayer with direct dictionary imports
|
|
128
|
+
[intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Questa configurazione garantisce che il contenuto dichiarato nei tuoi componenti venga estratto automaticamente e utilizzato per generare i dizionari durante il processo di build.
|
|
@@ -141,7 +141,7 @@ Il pacchetto `vue-intlayer` è utilizzato per interpretare i dizionari di Intlay
|
|
|
141
141
|
|
|
142
142
|
Il pacchetto `nuxt-intlayer` è un modulo Nuxt per rendere utilizzabili i dizionari Intlayer nelle applicazioni Nuxt. Integra funzionalità essenziali per far funzionare Intlayer in un ambiente Nuxt, come il middleware per la traduzione, il routing e la configurazione del file `nuxt.config.js`.
|
|
143
143
|
|
|
144
|
-
### svelte-intlayer
|
|
144
|
+
### svelte-intlayer
|
|
145
145
|
|
|
146
146
|
Il pacchetto `svelte-intlayer` è utilizzato per interpretare i dizionari di Intlayer e renderli utilizzabili nelle applicazioni Svelte.
|
|
147
147
|
|
|
@@ -42,6 +42,10 @@ Link all'estensione: [https://marketplace.visualstudio.com/items?itemName=Intlay
|
|
|
42
42
|
|
|
43
43
|
## Funzionalità
|
|
44
44
|
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
- **Estrai Contenuto** – Estrai contenuto dai tuoi componenti React / Vue / Svelte
|
|
48
|
+
|
|
45
49
|

|
|
46
50
|
|
|
47
51
|
- **Navigazione Istantanea** – Passa rapidamente al file di contenuto corretto cliccando su una chiave `useIntlayer`.
|
|
@@ -0,0 +1,184 @@
|
|
|
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
|
+
build: {
|
|
84
|
+
optimize: true,
|
|
85
|
+
importMode: "static", // または 'dynamic'
|
|
86
|
+
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default config;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> `optimize`のデフォルトオプションを維持することが、ほとんどの場合で推奨されます。
|
|
94
|
+
|
|
95
|
+
> 詳細はドキュメントの設定をご覧ください: [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/configuration.md)
|
|
96
|
+
|
|
97
|
+
### ビルドオプション
|
|
98
|
+
|
|
99
|
+
`build`構成オブジェクトの下で利用可能なオプションは以下の通りです:
|
|
100
|
+
|
|
101
|
+
| プロパティ | 型 | デフォルト | 説明 |
|
|
102
|
+
| :-------------------- | :------------------------------ | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| **`optimize`** | `boolean` | `undefined` | ビルド最適化を有効にするかどうかを制御します。`true` の場合、Intlayer は辞書呼び出しを最適化されたインジェクトに置き換えます。`false` の場合、最適化は無効になります。通常は本番環境で `true` に設定します。 |
|
|
104
|
+
| **`importMode`** | `'static' , 'dynamic' , 'live'` | `'static'` | 辞書の読み込み方法を決定します(詳細は以下を参照)。 |
|
|
105
|
+
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Intlayerが最適化のためにスキャンするファイルを定義するグロブパターン。関連のないファイルを除外し、ビルドを高速化するために使用します。 |
|
|
106
|
+
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | ビルドされた辞書の出力フォーマットを制御します。 |
|
|
107
|
+
|
|
108
|
+
## インポートモード
|
|
109
|
+
|
|
110
|
+
`importMode`設定は、辞書の内容がコンポーネントにどのように注入されるかを決定します。
|
|
111
|
+
|
|
112
|
+
### 1. スタティックモード(`default`)
|
|
113
|
+
|
|
114
|
+
静的モードでは、Intlayerは `useIntlayer` を `useDictionary` に置き換え、辞書を直接JavaScriptバンドルに注入します。
|
|
115
|
+
|
|
116
|
+
- **利点:** 即時レンダリング(同期的)、ハイドレーション時の追加ネットワークリクエストなし。
|
|
117
|
+
- **欠点:** バンドルにはその特定のコンポーネントに対する**すべての**利用可能な言語の翻訳が含まれます。
|
|
118
|
+
- **最適用途:** シングルページアプリケーション(SPA)。
|
|
119
|
+
|
|
120
|
+
**変換後のコード例:**
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// あなたのコード
|
|
124
|
+
const content = useIntlayer("my-key");
|
|
125
|
+
|
|
126
|
+
// 最適化されたコード(静的)
|
|
127
|
+
const content = useDictionary({
|
|
128
|
+
key: "my-key",
|
|
129
|
+
content: {
|
|
130
|
+
nodeType: "translation",
|
|
131
|
+
translation: {
|
|
132
|
+
en: "My title",
|
|
133
|
+
fr: "Mon titre",
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 2. 動的モード
|
|
140
|
+
|
|
141
|
+
動的モードでは、Intlayerは`useIntlayer`を`useDictionaryAsync`に置き換えます。これは`import()`(Suspenseのような仕組み)を使用して、現在のロケールのJSONを遅延ロードします。
|
|
142
|
+
|
|
143
|
+
- **利点:** **ロケール単位のツリーシェイキング。** 英語版を閲覧しているユーザーは英語の辞書のみをダウンロードし、フランス語の辞書は一切ロードされません。
|
|
144
|
+
- **欠点:** ハイドレーション時にコンポーネントごとにネットワークリクエスト(アセット取得)が発生します。
|
|
145
|
+
- **最適な用途:** 大きなテキストブロック、記事、多言語対応でバンドルサイズが重要なアプリケーション。
|
|
146
|
+
|
|
147
|
+
**変換後のコード例:**
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
// あなたのコード
|
|
151
|
+
const content = useIntlayer("my-key");
|
|
152
|
+
|
|
153
|
+
// 最適化されたコード(動的)
|
|
154
|
+
const content = useDictionaryAsync({
|
|
155
|
+
en: () =>
|
|
156
|
+
import(".intlayer/dynamic_dictionary/my-key/en.json").then(
|
|
157
|
+
(mod) => mod.default
|
|
158
|
+
),
|
|
159
|
+
fr: () =>
|
|
160
|
+
import(".intlayer/dynamic_dictionary/my-key/fr.json").then(
|
|
161
|
+
(mod) => mod.default
|
|
162
|
+
),
|
|
163
|
+
});
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
> `importMode: 'dynamic'` を使用する場合、1ページに `useIntlayer` を使ったコンポーネントが100個あると、ブラウザは100回の個別フェッチを試みます。この「リクエストの滝」を避けるために、コンテンツをより少ない `.content` ファイル(例:ページセクションごとに1つの辞書)にまとめ、アトムコンポーネントごとに分けるのは避けてください。
|
|
167
|
+
|
|
168
|
+
> 現時点で、`importMode: 'dynamic'` は Vue と Svelte で完全にはサポートされていません。これらのフレームワークでは、今後のアップデートまで `importMode: 'static'` の使用を推奨します。
|
|
169
|
+
|
|
170
|
+
### 3. ライブモード
|
|
171
|
+
|
|
172
|
+
動的モードと同様に動作しますが、最初にIntlayer Live Sync APIから辞書を取得しようとします。API呼び出しが失敗した場合やコンテンツがライブ更新用にマークされていない場合は、動的インポートにフォールバックします。
|
|
173
|
+
|
|
174
|
+
> 詳細はCMSドキュメントをご覧ください: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/intlayer_CMS.md)
|
|
175
|
+
|
|
176
|
+
## まとめ: 静的モード vs 動的モード
|
|
177
|
+
|
|
178
|
+
| 機能 | 静的モード | 動的モード |
|
|
179
|
+
| :------------------------- | :--------------------------------------- | :------------------------------------ |
|
|
180
|
+
| **JSバンドルサイズ** | 大きい(コンポーネントの全言語を含む) | 最小(コードのみ、コンテンツなし) |
|
|
181
|
+
| **初期読み込み** | 即時(コンテンツはバンドル内に含まれる) | わずかな遅延(JSONを取得) |
|
|
182
|
+
| **ネットワークリクエスト** | 追加リクエストなし | 辞書ごとに1リクエスト |
|
|
183
|
+
| **ツリーシェイキング** | コンポーネントレベル | コンポーネントレベル + ロケールレベル |
|
|
184
|
+
| **最適な使用例** | UIコンポーネント、小規模アプリ | テキスト量が多いページ、多言語対応 |
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-09-09
|
|
3
|
+
updatedAt: 2025-09-09
|
|
4
|
+
title: Intlayer コンパイラー | i18n のための自動コンテンツ抽出
|
|
5
|
+
description: Intlayer コンパイラーで国際化プロセスを自動化しましょう。コンポーネントから直接コンテンツを抽出し、Vite、Next.js などでより高速かつ効率的な i18n を実現します。
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- コンパイラー
|
|
9
|
+
- 国際化
|
|
10
|
+
- i18n
|
|
11
|
+
- 自動化
|
|
12
|
+
- 抽出
|
|
13
|
+
- 速度
|
|
14
|
+
- Vite
|
|
15
|
+
- Next.js
|
|
16
|
+
- React
|
|
17
|
+
- Vue
|
|
18
|
+
- Svelte
|
|
19
|
+
slugs:
|
|
20
|
+
- doc
|
|
21
|
+
- compiler
|
|
22
|
+
history:
|
|
23
|
+
- version: 7.3.1
|
|
24
|
+
date: 2025-11-27
|
|
25
|
+
changes: コンパイラーリリース
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Intlayer コンパイラー | i18n のための自動コンテンツ抽出
|
|
29
|
+
|
|
30
|
+
## Intlayer コンパイラーとは?
|
|
31
|
+
|
|
32
|
+
**Intlayer コンパイラー**は、アプリケーションの国際化(i18n)プロセスを自動化するために設計された強力なツールです。ソースコード(JSX、TSX、Vue、Svelte)内のコンテンツ宣言をスキャンし、それらを抽出して必要な辞書ファイルを自動的に生成します。これにより、コンテンツをコンポーネントと共に配置したままにでき、Intlayer が辞書の管理と同期を担当します。
|
|
33
|
+
|
|
34
|
+
## なぜ Intlayer コンパイラーを使うのか?
|
|
35
|
+
|
|
36
|
+
- **自動化**: コンテンツを辞書に手動でコピー&ペーストする手間を排除します。
|
|
37
|
+
- **高速化**: 最適化されたコンテンツ抽出により、ビルドプロセスの高速化を実現します。
|
|
38
|
+
- **開発者体験**: コンテンツ宣言を使用箇所にそのまま保持し、保守性を向上させます。
|
|
39
|
+
- **ライブアップデート**: 開発中に即時フィードバックを得られるホットモジュールリプレースメント(HMR)をサポートします。
|
|
40
|
+
|
|
41
|
+
より詳しい比較については、[Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ja/compiler_vs_declarative_i18n.md) のブログ記事をご覧ください。
|
|
42
|
+
|
|
43
|
+
## Intlayer コンパイラーを使わない理由
|
|
44
|
+
|
|
45
|
+
コンパイラーは優れた「そのまま動作する」体験を提供しますが、いくつかのトレードオフも導入します:
|
|
46
|
+
|
|
47
|
+
- **ヒューリスティックの曖昧さ**:コンパイラーは、ユーザー向けコンテンツとアプリケーションロジック(例:`className="active"`、ステータスコード、製品ID)を推測する必要があります。複雑なコードベースでは、これにより誤検出や見逃された文字列が発生し、手動での注釈と例外処理が必要になる場合があります。
|
|
48
|
+
- **静的抽出のみ**:コンパイラーベースの抽出は静的解析に依存しています。実行時のみ存在する文字列(APIエラーコード、CMSフィールドなど)は、コンパイラー単独では発見または翻訳できないため、補完的なランタイムi18n戦略が必要です。
|
|
49
|
+
|
|
50
|
+
より深いアーキテクチャの比較については、ブログ記事[Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/ja/compiler_vs_declarative_i18n.md)を参照してください。
|
|
51
|
+
|
|
52
|
+
代替として、コンテンツの完全な制御を維持しながらi18nプロセスを自動化するために、Intlayerは自動抽出コマンド `intlayer transform`([CLIドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/cli/transform.md)を参照)またはIntlayer VS Code拡張機能の `Intlayer: extract content to Dictionary` コマンド([VS Code拡張機能ドキュメント](https://github.com/aymericzip/intlayer/blob/main/docs/docs/ja/vs_code_extension.md)を参照)も提供しています。
|
|
53
|
+
|
|
54
|
+
## 使い方
|
|
55
|
+
|
|
56
|
+
### Vite
|
|
57
|
+
|
|
58
|
+
Viteベースのアプリケーション(React、Vue、Svelteなど)では、`vite-intlayer` プラグインを使うのが最も簡単な方法です。
|
|
59
|
+
|
|
60
|
+
#### インストール
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install vite-intlayer
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### 設定
|
|
67
|
+
|
|
68
|
+
`vite.config.ts` を更新して `intlayerCompiler` プラグインを含めます:
|
|
69
|
+
|
|
70
|
+
```ts fileName="vite.config.ts"
|
|
71
|
+
import { defineConfig } from "vite";
|
|
72
|
+
import { intlayer, intlayerCompiler } from "vite-intlayer";
|
|
73
|
+
|
|
74
|
+
export default defineConfig({
|
|
75
|
+
plugins: [
|
|
76
|
+
intlayer(),
|
|
77
|
+
intlayerCompiler(), // コンパイラプラグインを追加
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### フレームワークサポート
|
|
83
|
+
|
|
84
|
+
Viteプラグインは自動的に異なるファイルタイプを検出し処理します:
|
|
85
|
+
|
|
86
|
+
- **React / JSX / TSX**: ネイティブに対応。
|
|
87
|
+
- **Vue**: `@intlayer/vue-compiler` が必要です。
|
|
88
|
+
- **Svelte**: `@intlayer/svelte-compiler` が必要です。
|
|
89
|
+
|
|
90
|
+
使用しているフレームワークに応じて、適切なコンパイラパッケージをインストールしてください:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Vue用
|
|
94
|
+
npm install @intlayer/vue-compiler
|
|
95
|
+
|
|
96
|
+
# Svelte用
|
|
97
|
+
npm install @intlayer/svelte-compiler
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Next.js (Babel)
|
|
101
|
+
|
|
102
|
+
Next.jsやその他のWebpackベースのBabelを使用するアプリケーションでは、`@intlayer/babel`プラグインを使ってコンパイラを設定できます。
|
|
103
|
+
|
|
104
|
+
#### インストール
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install @intlayer/babel
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### 設定
|
|
111
|
+
|
|
112
|
+
`babel.config.js`(または `babel.config.json`)を更新して、抽出プラグインを含めます。Intlayerの設定を自動的に読み込むためのヘルパー `getExtractPluginOptions` を提供しています。
|
|
113
|
+
|
|
114
|
+
```js fileName="babel.config.js"
|
|
115
|
+
const {
|
|
116
|
+
intlayerExtractBabelPlugin,
|
|
117
|
+
intlayerOptimizeBabelPlugin,
|
|
118
|
+
getExtractPluginOptions,
|
|
119
|
+
getOptimizePluginOptions,
|
|
120
|
+
} = require("@intlayer/babel");
|
|
121
|
+
|
|
122
|
+
module.exports = {
|
|
123
|
+
presets: ["next/babel"],
|
|
124
|
+
plugins: [
|
|
125
|
+
// Extract content from components into dictionaries
|
|
126
|
+
[intlayerExtractBabelPlugin, getExtractPluginOptions()],
|
|
127
|
+
// Optimize imports by replacing useIntlayer with direct dictionary imports
|
|
128
|
+
[intlayerOptimizeBabelPlugin, getOptimizePluginOptions()],
|
|
129
|
+
],
|
|
130
|
+
};
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
この設定により、コンポーネント内で宣言されたコンテンツが自動的に抽出され、ビルドプロセス中に辞書の生成に使用されます。
|