@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: Optimising i18n Bundle Size & Performance
|
|
5
|
+
description: Reduce application bundle size by optimising internationalisation (i18n) content. Learn how to leverage tree shaking and lazy loading for dictionaries with Intlayer.
|
|
6
|
+
keywords:
|
|
7
|
+
- Bundle Optimisation
|
|
8
|
+
- Content Automation
|
|
9
|
+
- Dynamic Content
|
|
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: Init history
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Optimising i18n Bundle Size & Performance
|
|
25
|
+
|
|
26
|
+
One of the most common challenges with traditional i18n solutions relying on JSON files is managing content size. If developers do not manually separate content into namespaces, users often end up downloading translations for every page and potentially every language just to view a single page.
|
|
27
|
+
|
|
28
|
+
For example, an application with 10 pages translated into 10 languages might result in a user downloading the content of 100 pages, even though they only need **one** (the current page in the current language). This leads to wasted bandwidth and slower load times.
|
|
29
|
+
|
|
30
|
+
> To detect this, you can use bundle analysers such as `rollup-plugin-visualizer` (vite), `@next/bundle-analyser` (next.js), or `webpack-bundle-analyser` (React CRA / Angular / etc).
|
|
31
|
+
|
|
32
|
+
**Intlayer solves this problem through build-time optimisation.** It analyses your code to detect which dictionaries are actually used per component and reinjects only the necessary content into your bundle.
|
|
33
|
+
|
|
34
|
+
## Table of Contents
|
|
35
|
+
|
|
36
|
+
<TOC />
|
|
37
|
+
|
|
38
|
+
## How It Works
|
|
39
|
+
|
|
40
|
+
Intlayer uses a **per-component approach**. Unlike global JSON files, your content is defined alongside or within your components. During the build process, Intlayer:
|
|
41
|
+
|
|
42
|
+
1. **Analyses** your code to find `useIntlayer` calls.
|
|
43
|
+
2. **Builds** the corresponding dictionary content.
|
|
44
|
+
3. **Replaces** the `useIntlayer` call with optimised code based on your configuration.
|
|
45
|
+
|
|
46
|
+
This ensures that:
|
|
47
|
+
|
|
48
|
+
- If a component is not imported, its content is not included in the bundle (Dead Code Elimination).
|
|
49
|
+
- If a component is lazy-loaded, its content is also lazy-loaded.
|
|
50
|
+
|
|
51
|
+
## Setup by Platform
|
|
52
|
+
|
|
53
|
+
### Next.js
|
|
54
|
+
|
|
55
|
+
Next.js requires the `@intlayer/swc` plugin to handle the transformation, as Next.js uses SWC for builds.
|
|
56
|
+
|
|
57
|
+
> This plugin is installed by default because SWC plugins are still experimental for Next.js. It may change in the future.
|
|
58
|
+
|
|
59
|
+
### Vite
|
|
60
|
+
|
|
61
|
+
Vite uses the `@intlayer/babel` plugin which is included as a dependency of `vite-intlayer`. The optimisation is enabled by default.
|
|
62
|
+
|
|
63
|
+
### Webpack
|
|
64
|
+
|
|
65
|
+
To enable bundle optimisation with Intlayer on Webpack, you need to install and configure the appropriate Babel (`@intlayer/babel`) or SWC (`@intlayer/swc`) plugin.
|
|
66
|
+
|
|
67
|
+
### Expo / Lynx
|
|
68
|
+
|
|
69
|
+
Bundle optimisation is **not available yet** for this platform. Support will be added in a future release.
|
|
70
|
+
|
|
71
|
+
## Configuration
|
|
72
|
+
|
|
73
|
+
You can control how Intlayer optimises your bundle via the `build` property in your `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", // or 'dynamic'
|
|
86
|
+
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default config;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> Keeping the default option for `optimize` is recommended in the vast majority of cases.
|
|
94
|
+
|
|
95
|
+
> See doc configuration for more details: [Configuration](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/configuration.md)
|
|
96
|
+
|
|
97
|
+
### Build Options
|
|
98
|
+
|
|
99
|
+
The following options are available under the `build` configuration object:
|
|
100
|
+
|
|
101
|
+
| Property | Type | Default | Description |
|
|
102
|
+
| :-------------------- | :------------------------------ | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| **`optimize`** | `boolean` | `undefined` | Controls whether build optimisation is enabled. If `true`, Intlayer replaces dictionary calls with optimised injects. If `false`, optimisation is disabled. Ideally set to `true` in production. |
|
|
104
|
+
| **`importMode`** | `'static' , 'dynamic' , 'live'` | `'static'` | Determines how dictionaries are loaded (see details below). |
|
|
105
|
+
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Glob patterns defining which files Intlayer should scan for optimisation. Use this to exclude unrelated files and speed up builds. |
|
|
106
|
+
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | Controls the output format of the built dictionaries. |
|
|
107
|
+
|
|
108
|
+
## Import Modes
|
|
109
|
+
|
|
110
|
+
The `importMode` setting dictates how the dictionary content is injected into your component.
|
|
111
|
+
|
|
112
|
+
### 1. Static Mode (`default`)
|
|
113
|
+
|
|
114
|
+
In static mode, Intlayer replaces `useIntlayer` with `useDictionary` and injects the dictionary directly into the JavaScript bundle.
|
|
115
|
+
|
|
116
|
+
- **Pros:** Instant rendering (synchronous), zero extra network requests during hydration.
|
|
117
|
+
- **Cons:** The bundle includes translations for **all** available languages for that specific component.
|
|
118
|
+
- **Best for:** Single Page Applications (SPA).
|
|
119
|
+
|
|
120
|
+
**Transformed Code Example:**
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// Your code
|
|
124
|
+
const content = useIntlayer("my-key");
|
|
125
|
+
|
|
126
|
+
// Optimised code (Static)
|
|
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. Dynamic Mode
|
|
140
|
+
|
|
141
|
+
In dynamic mode, Intlayer replaces `useIntlayer` with `useDictionaryAsync`. This uses `import()` (Suspense-like mechanism) to lazy-load specifically the JSON for the current locale.
|
|
142
|
+
|
|
143
|
+
- **Pros:** **Locale-level tree shaking.** A user viewing the English version will _only_ download the English dictionary. The French dictionary is never loaded.
|
|
144
|
+
- **Cons:** Triggers a network request (asset fetch) per component during hydration.
|
|
145
|
+
- **Best for:** Large text blocks, articles, or applications supporting many languages where bundle size is critical.
|
|
146
|
+
|
|
147
|
+
**Transformed Code Example:**
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
// Your code
|
|
151
|
+
const content = useIntlayer("my-key");
|
|
152
|
+
|
|
153
|
+
// Optimised code (Dynamic)
|
|
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
|
+
> When using `importMode: 'dynamic'`, if you have 100 components using `useIntlayer` on a single page, the browser will attempt 100 separate fetches. To avoid this "waterfall" of requests, group content into fewer `.content` files (e.g., one dictionary per page section) rather than one per atom component.
|
|
167
|
+
|
|
168
|
+
> Currently, `importMode: 'dynamic'` is not fully supported for Vue and Svelte. It is recommended to use `importMode: 'static'` for these frameworks until further updates.
|
|
169
|
+
|
|
170
|
+
### 3. Live Mode
|
|
171
|
+
|
|
172
|
+
Behaves similarly to Dynamic mode but attempts to fetch dictionaries from the Intlayer Live Sync API first. If the API call fails or the content is not marked for live updates, it falls back to the dynamic import.
|
|
173
|
+
|
|
174
|
+
> See CMS documentation for more details: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/intlayer_CMS.md)
|
|
175
|
+
|
|
176
|
+
## Summary: Static vs Dynamic
|
|
177
|
+
|
|
178
|
+
| Feature | Static Mode | Dynamic Mode |
|
|
179
|
+
| :------------------- | :-------------------------------------------- | :----------------------------------- |
|
|
180
|
+
| **JS Bundle Size** | Larger (includes all langs for the component) | Smallest (only code, no content) |
|
|
181
|
+
| **Initial Load** | Instant (Content is in bundle) | Slight delay (Fetches JSON) |
|
|
182
|
+
| **Network Requests** | 0 extra requests | 1 request per dictionary |
|
|
183
|
+
| **Tree Shaking** | Component-level | Component-level + Locale-level |
|
|
184
|
+
| **Best Use Case** | UI Components, Small Apps | Pages with much text, Many Languages |
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-09-09
|
|
3
|
+
updatedAt: 2025-09-09
|
|
4
|
+
title: Intlayer Compiler | Automated Content Extraction for i18n
|
|
5
|
+
description: Automate your internationalisation process with the Intlayer Compiler. Extract content directly from your components for faster, more efficient i18n in Vite, Next.js, and more.
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- Compiler
|
|
9
|
+
- Internationalisation
|
|
10
|
+
- i18n
|
|
11
|
+
- Automation
|
|
12
|
+
- Extraction
|
|
13
|
+
- Speed
|
|
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: Release Compiler
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Intlayer Compiler | Automated Content Extraction for i18n
|
|
29
|
+
|
|
30
|
+
## What is the Intlayer Compiler?
|
|
31
|
+
|
|
32
|
+
The **Intlayer Compiler** is a powerful tool designed to automate the process of internationalisation (i18n) in your applications. It scans your source code (JSX, TSX, Vue, Svelte) for content declarations, extracts them, and automatically generates the necessary dictionary files. This allows you to keep your content co-located with your components while Intlayer handles the management and synchronisation of your dictionaries.
|
|
33
|
+
|
|
34
|
+
## Why Use the Intlayer Compiler?
|
|
35
|
+
|
|
36
|
+
- **Automation**: Eliminates manual copy-pasting of content into dictionaries.
|
|
37
|
+
- **Speed**: Optimised content extraction ensuring your build process remains fast.
|
|
38
|
+
- **Developer Experience**: Keep content declarations right where they are used, improving maintainability.
|
|
39
|
+
- **Live Updates**: Supports Hot Module Replacement (HMR) for instant feedback during development.
|
|
40
|
+
|
|
41
|
+
See the [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/compiler_vs_declarative_i18n.md) blog post for a deeper comparison.
|
|
42
|
+
|
|
43
|
+
## Why not use the Intlayer Compiler?
|
|
44
|
+
|
|
45
|
+
Whilst the compiler offers an excellent "just works" experience, it also introduces some trade-offs you should be aware of:
|
|
46
|
+
|
|
47
|
+
- **Heuristic ambiguity**: The compiler must guess what is user-facing content vs. application logic (e.g., `className="active"`, status codes, product IDs). In complex codebases, this can lead to false positives or missed strings that require manual annotations and exceptions.
|
|
48
|
+
- **Static-only extraction**: Compiler-based extraction relies on static analysis. Strings that only exist at runtime (API error codes, CMS fields, etc.) cannot be discovered or translated by the compiler alone, so you still need a complementary runtime i18n strategy.
|
|
49
|
+
|
|
50
|
+
For a deeper architectural comparison, see the blog post [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/en/compiler_vs_declarative_i18n.md).
|
|
51
|
+
|
|
52
|
+
As an alternative, to automate your i18n process whilst keeping full control of your content, Intlayer also provides an auto-extraction command `intlayer transform` (see [CLI documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/cli/transform.md)), or the `Intlayer: extract content to Dictionary` command from the Intlayer VS Code extension (see [VS Code extension documentation](https://github.com/aymericzip/intlayer/blob/main/docs/docs/en-GB/vs_code_extension.md)).
|
|
53
|
+
|
|
54
|
+
## Usage
|
|
55
|
+
|
|
56
|
+
### Vite
|
|
57
|
+
|
|
58
|
+
For Vite-based applications (React, Vue, Svelte, etc.), the easiest way to use the compiler is through the `vite-intlayer` plugin.
|
|
59
|
+
|
|
60
|
+
#### Installation
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install vite-intlayer
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Configuration
|
|
67
|
+
|
|
68
|
+
Update your `vite.config.ts` to include the `intlayerCompiler` plugin:
|
|
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(), // Adds the compiler plugin
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Framework Support
|
|
83
|
+
|
|
84
|
+
The Vite plugin automatically detects and handles different file types:
|
|
85
|
+
|
|
86
|
+
- **React / JSX / TSX**: Handled natively.
|
|
87
|
+
- **Vue**: Requires `@intlayer/vue-compiler`.
|
|
88
|
+
- **Svelte**: Requires `@intlayer/svelte-compiler`.
|
|
89
|
+
|
|
90
|
+
Make sure to install the appropriate compiler package for your framework:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# For Vue
|
|
94
|
+
npm install @intlayer/vue-compiler
|
|
95
|
+
|
|
96
|
+
# For Svelte
|
|
97
|
+
npm install @intlayer/svelte-compiler
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Next.js (Babel)
|
|
101
|
+
|
|
102
|
+
For Next.js or other Webpack-based applications using Babel, you can configure the compiler using the `@intlayer/babel` plugin.
|
|
103
|
+
|
|
104
|
+
#### Installation
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install @intlayer/babel
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Configuration
|
|
111
|
+
|
|
112
|
+
Update your `babel.config.js` (or `babel.config.json`) to include the extraction plugin. We provide a helper `getExtractPluginOptions` to load your Intlayer configuration automatically.
|
|
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
|
+
This configuration ensures that content declared in your components is automatically extracted and used to generate dictionaries during your build process.
|
|
@@ -139,7 +139,7 @@ The `vue-intlayer` package is used to interpret Intlayer dictionaries and make t
|
|
|
139
139
|
|
|
140
140
|
The `nuxt-intlayer` package is a Nuxt module to make Intlayer dictionaries usable in Nuxt applications. It integrates essential features to make Intlayer work in a Nuxt environment, such as translation middleware, routing, or the `nuxt.config.js` file configuration.
|
|
141
141
|
|
|
142
|
-
### svelte-intlayer
|
|
142
|
+
### svelte-intlayer
|
|
143
143
|
|
|
144
144
|
The `svelte-intlayer` package is used to interpret Intlayer dictionaries and make them usable in Svelte applications.
|
|
145
145
|
|
|
@@ -42,6 +42,10 @@ Extension link: [https://marketplace.visualstudio.com/items?itemName=Intlayer.in
|
|
|
42
42
|
|
|
43
43
|
## Features
|
|
44
44
|
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
- **Extract Content** – Extract content from your React / Vue / Svelte components
|
|
48
|
+
|
|
45
49
|

|
|
46
50
|
|
|
47
51
|
- **Instant Navigation** – Quickly jump to the correct content file when clicking on a `useIntlayer` key.
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-11-25
|
|
3
|
+
updatedAt: 2025-11-25
|
|
4
|
+
title: Optimización del Tamaño y Rendimiento del Bundle i18n
|
|
5
|
+
description: Reduce el tamaño del bundle de la aplicación optimizando el contenido de internacionalización (i18n). Aprende a aprovechar tree shaking y lazy loading para diccionarios con Intlayer.
|
|
6
|
+
keywords:
|
|
7
|
+
- Optimización de Bundle
|
|
8
|
+
- Automatización de Contenido
|
|
9
|
+
- Contenido Dinámico
|
|
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: Historial inicial
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
# Optimización del Tamaño y Rendimiento del Bundle i18n
|
|
25
|
+
|
|
26
|
+
Uno de los desafíos más comunes con las soluciones tradicionales de i18n que dependen de archivos JSON es gestionar el tamaño del contenido. Si los desarrolladores no separan manualmente el contenido en namespaces, los usuarios a menudo terminan descargando las traducciones de todas las páginas y potencialmente de todos los idiomas solo para ver una sola página.
|
|
27
|
+
|
|
28
|
+
Por ejemplo, una aplicación con 10 páginas traducidas a 10 idiomas podría hacer que un usuario descargue el contenido de 100 páginas, aunque solo necesite **una** (la página actual en el idioma actual). Esto conduce a un desperdicio de ancho de banda y tiempos de carga más lentos.
|
|
29
|
+
|
|
30
|
+
> Para detectarlo, puedes usar analizadores de bundle como `rollup-plugin-visualizer` (vite), `@next/bundle-analyzer` (next.js) o `webpack-bundle-analyzer` (React CRA / Angular / etc).
|
|
31
|
+
|
|
32
|
+
**Intlayer resuelve este problema mediante la optimización en tiempo de compilación.** Analiza tu código para detectar qué diccionarios se usan realmente por componente y reinserta solo el contenido necesario en tu bundle.
|
|
33
|
+
|
|
34
|
+
## Tabla de Contenidos
|
|
35
|
+
|
|
36
|
+
<TOC />
|
|
37
|
+
|
|
38
|
+
## Cómo Funciona
|
|
39
|
+
|
|
40
|
+
Intlayer utiliza un **enfoque por componente**. A diferencia de los archivos JSON globales, tu contenido se define junto a tus componentes o dentro de ellos. Durante el proceso de compilación, Intlayer:
|
|
41
|
+
|
|
42
|
+
1. **Analiza** tu código para encontrar llamadas a `useIntlayer`.
|
|
43
|
+
2. **Construye** el contenido del diccionario correspondiente.
|
|
44
|
+
3. **Reemplaza** la llamada a `useIntlayer` con código optimizado basado en tu configuración.
|
|
45
|
+
|
|
46
|
+
Esto garantiza que:
|
|
47
|
+
|
|
48
|
+
- Si un componente no se importa, su contenido no se incluye en el bundle (Eliminación de Código Muerto).
|
|
49
|
+
- Si un componente se carga de forma lazy, su contenido también se carga de forma lazy.
|
|
50
|
+
|
|
51
|
+
## Configuración por Plataforma
|
|
52
|
+
|
|
53
|
+
### Next.js
|
|
54
|
+
|
|
55
|
+
Next.js requiere el plugin `@intlayer/swc` para manejar la transformación, ya que Next.js utiliza SWC para las compilaciones.
|
|
56
|
+
|
|
57
|
+
> Este plugin está instalado por defecto porque los plugins SWC aún son experimentales para Next.js. Esto podría cambiar en el futuro.
|
|
58
|
+
|
|
59
|
+
### Vite
|
|
60
|
+
|
|
61
|
+
Vite utiliza el plugin `@intlayer/babel` que está incluido como dependencia de `vite-intlayer`. La optimización está habilitada por defecto.
|
|
62
|
+
|
|
63
|
+
### Webpack
|
|
64
|
+
|
|
65
|
+
Para habilitar la optimización del bundle con Intlayer en Webpack, necesitas instalar y configurar el plugin adecuado de Babel (`@intlayer/babel`) o SWC (`@intlayer/swc`).
|
|
66
|
+
|
|
67
|
+
### Expo / Lynx
|
|
68
|
+
|
|
69
|
+
La optimización del bundle **no está disponible aún** para esta plataforma. El soporte será añadido en una versión futura.
|
|
70
|
+
|
|
71
|
+
## Configuración
|
|
72
|
+
|
|
73
|
+
Puedes controlar cómo Intlayer optimiza tu bundle a través de la propiedad `build` en tu archivo `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", // o 'dynamic'
|
|
86
|
+
traversePattern: ["**/*.{js,ts,mjs,cjs,jsx,tsx}", "!**/node_modules/**"],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export default config;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
> Se recomienda mantener la opción por defecto para `optimize` en la mayoría de los casos.
|
|
94
|
+
|
|
95
|
+
> Consulta la documentación de configuración para más detalles: [Configuración](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/configuration.md)
|
|
96
|
+
|
|
97
|
+
### Opciones de Build
|
|
98
|
+
|
|
99
|
+
Las siguientes opciones están disponibles bajo el objeto de configuración `build`:
|
|
100
|
+
|
|
101
|
+
| Propiedad | Tipo | Valor por defecto | Descripción |
|
|
102
|
+
| :-------------------- | :------------------------------ | :------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
103
|
+
| **`optimize`** | `boolean` | `undefined` | Controla si la optimización de la build está habilitada. Si es `true`, Intlayer reemplaza las llamadas al diccionario con inyecciones optimizadas. Si es `false`, la optimización está deshabilitada. Idealmente se debe establecer en `true` en producción. |
|
|
104
|
+
| **`importMode`** | `'static' , 'dynamic' , 'live'` | `'static'` | Determina cómo se cargan los diccionarios (ver detalles a continuación). |
|
|
105
|
+
| **`traversePattern`** | `string[]` | `['**/*.{js,ts,jsx,tsx}', ...]` | Patrones glob que definen qué archivos Intlayer debe escanear para la optimización. Úsalo para excluir archivos no relacionados y acelerar las builds. |
|
|
106
|
+
| **`outputFormat`** | `'esm', 'cjs'` | `'esm', 'cjs'` | Controla el formato de salida de los diccionarios construidos. |
|
|
107
|
+
|
|
108
|
+
## Modos de Importación
|
|
109
|
+
|
|
110
|
+
La configuración `importMode` dicta cómo se inyecta el contenido del diccionario en tu componente.
|
|
111
|
+
|
|
112
|
+
### 1. Modo Estático (`default`)
|
|
113
|
+
|
|
114
|
+
En modo estático, Intlayer reemplaza `useIntlayer` por `useDictionary` e inyecta el diccionario directamente en el bundle de JavaScript.
|
|
115
|
+
|
|
116
|
+
- **Ventajas:** Renderizado instantáneo (síncrono), sin solicitudes de red adicionales durante la hidratación.
|
|
117
|
+
- **Desventajas:** El bundle incluye traducciones para **todos** los idiomas disponibles para ese componente específico.
|
|
118
|
+
- **Ideal para:** Aplicaciones de una sola página (SPA).
|
|
119
|
+
|
|
120
|
+
**Ejemplo de código transformado:**
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
// Tu código
|
|
124
|
+
const content = useIntlayer("my-key");
|
|
125
|
+
|
|
126
|
+
// Código optimizado (Estático)
|
|
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. Modo Dinámico
|
|
140
|
+
|
|
141
|
+
En modo dinámico, Intlayer reemplaza `useIntlayer` por `useDictionaryAsync`. Esto utiliza `import()` (mecanismo similar a Suspense) para cargar perezosamente específicamente el JSON para la localidad actual.
|
|
142
|
+
|
|
143
|
+
- **Ventajas:** **Eliminación de código a nivel de localidad.** Un usuario que vea la versión en inglés solo descargará el diccionario en inglés. El diccionario en francés nunca se carga.
|
|
144
|
+
- **Desventajas:** Genera una solicitud de red (descarga de recurso) por componente durante la hidratación.
|
|
145
|
+
- **Ideal para:** Bloques grandes de texto, artículos o aplicaciones que soportan muchos idiomas donde el tamaño del bundle es crítico.
|
|
146
|
+
|
|
147
|
+
**Ejemplo de código transformado:**
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
// Tu código
|
|
151
|
+
const content = useIntlayer("my-key");
|
|
152
|
+
|
|
153
|
+
// Código optimizado (Dinámico)
|
|
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
|
+
> Al usar `importMode: 'dynamic'`, si tienes 100 componentes usando `useIntlayer` en una sola página, el navegador intentará realizar 100 solicitudes separadas. Para evitar esta "cascada" de peticiones, agrupa el contenido en menos archivos `.content` (por ejemplo, un diccionario por sección de página) en lugar de uno por componente átomo.
|
|
167
|
+
|
|
168
|
+
> Actualmente, `importMode: 'dynamic'` no está completamente soportado para Vue y Svelte. Se recomienda usar `importMode: 'static'` para estos frameworks hasta futuras actualizaciones.
|
|
169
|
+
|
|
170
|
+
### 3. Modo Live
|
|
171
|
+
|
|
172
|
+
Se comporta de manera similar al modo Dinámico, pero intenta obtener primero los diccionarios desde la API de Intlayer Live Sync. Si la llamada a la API falla o el contenido no está marcado para actualizaciones en vivo, vuelve a la importación dinámica.
|
|
173
|
+
|
|
174
|
+
> Consulta la documentación del CMS para más detalles: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_CMS.md)
|
|
175
|
+
|
|
176
|
+
## Resumen: Estático vs Dinámico
|
|
177
|
+
|
|
178
|
+
| Característica | Modo Estático | Modo Dinámico |
|
|
179
|
+
| :----------------------- | :-------------------------------------------------------- | :--------------------------------------- |
|
|
180
|
+
| **Tamaño del Bundle JS** | Más grande (incluye todos los idiomas para el componente) | Más pequeño (solo código, sin contenido) |
|
|
181
|
+
|
|
182
|
+
Se comporta de manera similar al modo Dinámico pero intenta obtener los diccionarios primero desde la API de Intlayer Live Sync. Si la llamada a la API falla o el contenido no está marcado para actualizaciones en vivo, vuelve a la importación dinámica.
|
|
183
|
+
|
|
184
|
+
> Consulte la documentación del CMS para más detalles: [CMS](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/intlayer_CMS.md)
|
|
185
|
+
|
|
186
|
+
## Resumen: Estático vs Dinámico
|
|
187
|
+
|
|
188
|
+
| Característica | Modo Estático | Modo Dinámico |
|
|
189
|
+
| :----------------------- | :-------------------------------------------------------- | :---------------------------------------- |
|
|
190
|
+
| **Tamaño del Bundle JS** | Más grande (incluye todos los idiomas para el componente) | Más pequeño (solo código, sin contenido) |
|
|
191
|
+
| **Carga Inicial** | Instantánea (El contenido está en el bundle) | Ligera demora (Obtiene JSON) |
|
|
192
|
+
| **Solicitudes de Red** | 0 solicitudes adicionales | 1 solicitud por diccionario |
|
|
193
|
+
| **Tree Shaking** | A nivel de componente | A nivel de componente + a nivel de idioma |
|
|
194
|
+
| **Mejor Caso de Uso** | Componentes UI, Aplicaciones pequeñas | Páginas con mucho texto, Muchos idiomas |
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
---
|
|
2
|
+
createdAt: 2025-09-09
|
|
3
|
+
updatedAt: 2025-09-09
|
|
4
|
+
title: Intlayer Compiler | Extracción Automática de Contenido para i18n
|
|
5
|
+
description: Automatiza tu proceso de internacionalización con el Intlayer Compiler. Extrae contenido directamente de tus componentes para una i18n más rápida y eficiente en Vite, Next.js y más.
|
|
6
|
+
keywords:
|
|
7
|
+
- Intlayer
|
|
8
|
+
- Compiler
|
|
9
|
+
- Internacionalización
|
|
10
|
+
- i18n
|
|
11
|
+
- Automatización
|
|
12
|
+
- Extracción
|
|
13
|
+
- Velocidad
|
|
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: Lanzamiento del Compiler
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
# Intlayer Compiler | Extracción Automática de Contenido para i18n
|
|
29
|
+
|
|
30
|
+
## ¿Qué es el Intlayer Compiler?
|
|
31
|
+
|
|
32
|
+
El **Intlayer Compiler** es una herramienta poderosa diseñada para automatizar el proceso de internacionalización (i18n) en tus aplicaciones. Escanea tu código fuente (JSX, TSX, Vue, Svelte) en busca de declaraciones de contenido, las extrae y genera automáticamente los archivos de diccionario necesarios. Esto te permite mantener tu contenido junto a tus componentes mientras Intlayer se encarga de la gestión y sincronización de tus diccionarios.
|
|
33
|
+
|
|
34
|
+
## ¿Por qué usar el Intlayer Compiler?
|
|
35
|
+
|
|
36
|
+
- **Automatización**: Elimina el copiado manual de contenido en los diccionarios.
|
|
37
|
+
- **Velocidad**: Extracción de contenido optimizada que asegura que tu proceso de build siga siendo rápido.
|
|
38
|
+
- **Experiencia del desarrollador**: Mantén las declaraciones de contenido justo donde se usan, mejorando la mantenibilidad.
|
|
39
|
+
- **Actualizaciones en vivo**: Soporta Hot Module Replacement (HMR) para retroalimentación instantánea durante el desarrollo.
|
|
40
|
+
|
|
41
|
+
Consulta el artículo del blog [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/es/compiler_vs_declarative_i18n.md) para una comparación más profunda.
|
|
42
|
+
|
|
43
|
+
## ¿Por qué no usar el Intlayer Compiler?
|
|
44
|
+
|
|
45
|
+
Si bien el compilador ofrece una excelente experiencia de "funciona sin más", también introduce algunos compromisos de los que debes ser consciente:
|
|
46
|
+
|
|
47
|
+
- **Ambigüedad heurística**: El compilador debe adivinar qué es contenido orientado al usuario frente a la lógica de la aplicación (por ejemplo, `className="active"`, códigos de estado, IDs de productos). En bases de código complejas, esto puede llevar a falsos positivos o cadenas omitidas que requieren anotaciones manuales y excepciones.
|
|
48
|
+
- **Extracción solo estática**: La extracción basada en compilador se basa en análisis estático. Las cadenas que solo existen en tiempo de ejecución (códigos de error de API, campos CMS, etc.) no pueden ser descubiertas o traducidas por el compilador solo, por lo que aún necesitas una estrategia i18n de tiempo de ejecución complementaria.
|
|
49
|
+
|
|
50
|
+
Para una comparación arquitectónica más profunda, consulta el artículo del blog [Compiler vs. Declarative i18n](https://github.com/aymericzip/intlayer/blob/main/docs/blog/es/compiler_vs_declarative_i18n.md).
|
|
51
|
+
|
|
52
|
+
Como alternativa, para automatizar tu proceso i18n mientras mantienes el control total de tu contenido, Intlayer también proporciona un comando de auto-extracción `intlayer transform` (consulta la [documentación CLI](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/cli/transform.md)), o el comando `Intlayer: extract content to Dictionary` de la extensión Intlayer VS Code (consulta la [documentación de la extensión VS Code](https://github.com/aymericzip/intlayer/blob/main/docs/docs/es/vs_code_extension.md)).
|
|
53
|
+
|
|
54
|
+
## Uso
|
|
55
|
+
|
|
56
|
+
### Vite
|
|
57
|
+
|
|
58
|
+
Para aplicaciones basadas en Vite (React, Vue, Svelte, etc.), la forma más sencilla de usar el compilador es a través del plugin `vite-intlayer`.
|
|
59
|
+
|
|
60
|
+
#### Instalación
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
npm install vite-intlayer
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Configuración
|
|
67
|
+
|
|
68
|
+
Actualiza tu `vite.config.ts` para incluir el 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(), // Añade el plugin del compilador
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
#### Soporte de Framework
|
|
83
|
+
|
|
84
|
+
El plugin de Vite detecta y maneja automáticamente diferentes tipos de archivos:
|
|
85
|
+
|
|
86
|
+
- **React / JSX / TSX**: Manejado de forma nativa.
|
|
87
|
+
- **Vue**: Requiere `@intlayer/vue-compiler`.
|
|
88
|
+
- **Svelte**: Requiere `@intlayer/svelte-compiler`.
|
|
89
|
+
|
|
90
|
+
Asegúrate de instalar el paquete de compilador adecuado para tu framework:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
# Para Vue
|
|
94
|
+
npm install @intlayer/vue-compiler
|
|
95
|
+
|
|
96
|
+
# Para Svelte
|
|
97
|
+
npm install @intlayer/svelte-compiler
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Next.js (Babel)
|
|
101
|
+
|
|
102
|
+
Para Next.js u otras aplicaciones basadas en Webpack que usan Babel, puedes configurar el compilador usando el plugin `@intlayer/babel`.
|
|
103
|
+
|
|
104
|
+
#### Instalación
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
npm install @intlayer/babel
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Configuración
|
|
111
|
+
|
|
112
|
+
Actualiza tu `babel.config.js` (o `babel.config.json`) para incluir el plugin de extracción. Proporcionamos un helper `getExtractPluginOptions` para cargar automáticamente tu configuración de 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
|
+
Esta configuración asegura que el contenido declarado en tus componentes se extraiga automáticamente y se utilice para generar diccionarios durante tu proceso de compilación.
|