@zohodesk/client_build_tool 0.0.11-exp.15.1 → 0.0.11-exp.15.4
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 -204
- package/docs/I18N_NUMERIC_INDEXING_PLUGIN.md +225 -0
- package/lib/schemas/defaultConfigValues.js +9 -12
- package/lib/schemas/defaultConfigValuesOnly.js +1 -18
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js +124 -0
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +210 -143
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +47 -12
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/propertiesUtils.js +19 -1
- package/lib/shared/bundler/webpack/jsLoaders.js +9 -4
- package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +12 -3
- package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +28 -14
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nIndexingPlugin.js +42 -0
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericHtmlInjector.js +92 -0
- package/lib/shared/bundler/webpack/plugins.js +6 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/README_backup.md +0 -202
- package/init/README.md +0 -170
- package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +0 -49
- package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +0 -96
- package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +0 -84
- package/lib/shared/bundler/webpack/utils/propertiesParser.js +0 -81
package/README.md
CHANGED
|
@@ -98,207 +98,3 @@ fixes :-
|
|
|
98
98
|
|
|
99
99
|
- preload plc undefined url fixed
|
|
100
100
|
|
|
101
|
-
# Changelog and Release Notes
|
|
102
|
-
|
|
103
|
-
- remove babel-plugin-module-resolver dependencies
|
|
104
|
-
|
|
105
|
-
**Adjustments:-**
|
|
106
|
-
- Public Folder configuration is separated for development and production
|
|
107
|
-
|
|
108
|
-
**Bug Fix:-**
|
|
109
|
-
- Fixed the issue where the build log was not visible when `stats (bundle integrity)` was enabled. The problem was resolved by adding an error check in the `bundleIntegrity plugin`.
|
|
110
|
-
- Removed the babel-plugin-module-resolver dependency to resolve the alias resolution issue in the application.
|
|
111
|
-
- Fixed the issue where a space in the variable name causes it to return an undefined value.
|
|
112
|
-
- Fixed the URL path generation issue that occurred while using context in the development setup.
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# v0.0.11
|
|
117
|
-
|
|
118
|
-
# v0.0.10 (12-05-2025)
|
|
119
|
-
**Feature:-**
|
|
120
|
-
- `alias` support for `build:es` and `build:lib`
|
|
121
|
-
- Add babel-plugin-module-resolver dependencies
|
|
122
|
-
- Modify getBabelPlugin to include module resolver with aliases
|
|
123
|
-
|
|
124
|
-
**Bug Fix:-**
|
|
125
|
-
- Enhance runBabelForTSFile to handle both .tsx and .ts file extensions
|
|
126
|
-
- Update mockApiHandler to ensure mock function is called correctly
|
|
127
|
-
|
|
128
|
-
**Change:-**
|
|
129
|
-
- Refactor defaultConfigValues.js to include cli options for enableRTLSplit
|
|
130
|
-
|
|
131
|
-
## v0.0.9
|
|
132
|
-
|
|
133
|
-
**Feature:-**
|
|
134
|
-
- externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
|
|
135
|
-
- to use externals, we use the following pattern in `app > externals` :
|
|
136
|
-
|
|
137
|
-
For example
|
|
138
|
-
```
|
|
139
|
-
externals: {
|
|
140
|
-
<key> : <value>
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## v0.0.6 (4-09-2023)
|
|
145
|
-
|
|
146
|
-
**Feature:-**
|
|
147
|
-
- Generating bundle integrity report json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
|
|
148
|
-
- Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
|
|
149
|
-
- added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
|
|
150
|
-
only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
|
|
151
|
-
- added support for glob pattern for custom chunks split logic.
|
|
152
|
-
- added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
|
|
153
|
-
|
|
154
|
-
**Change:-**
|
|
155
|
-
- i18n name not generated issue fix.
|
|
156
|
-
- public path not correctly set issue fix.
|
|
157
|
-
- changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
|
|
158
|
-
## v0.0.5 (6-08-2023)
|
|
159
|
-
|
|
160
|
-
**Changes:--**
|
|
161
|
-
- Typo fix in i18nRuntimeDealerPlugin.js
|
|
162
|
-
- fixing some bugs in resolvers.js file
|
|
163
|
-
|
|
164
|
-
## v0.0.3 (1-08-2023)
|
|
165
|
-
|
|
166
|
-
**Changes:--**
|
|
167
|
-
- `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
|
|
168
|
-
- unwanted files deleted from build
|
|
169
|
-
|
|
170
|
-
**Issue Fix:--**
|
|
171
|
-
- The issue with the source map not being created in the build has been fixed."
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
## v0.0.2 (28-04-2023)
|
|
175
|
-
|
|
176
|
-
**Features:-**
|
|
177
|
-
|
|
178
|
-
- `devModeContentHashAllowedTypes` support added for some project there will be a need for hash even though they run dev mode. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#devModeContentHashAllowedTypes)
|
|
179
|
-
- `devLikeHash` support for disable content hash for file names in production mode. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#devLikeHash)
|
|
180
|
-
- `disableReactDevWarning` disable react dev warning such as prop-type warnings will be removed in dev mode build or server. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#disableReactDevWarning) can be enabled via `--disable_react_dev_warning` too.
|
|
181
|
-
- `statsLogConfig` support to customize default webpack log after build finished. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#statsLogConfig) can be enabled via `--disable_react_dev_warning` too.
|
|
182
|
-
- `enableChunkHash` renamed as `enableFileNameHashing`
|
|
183
|
-
|
|
184
|
-
- `pre_processor` command to run the preprocessor.js file.preProcessor runs in build, start, buildEs, buildLib commands bu default. and we have watch mode support as well with the option (`-w`)
|
|
185
|
-
- `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
|
|
186
|
-
- `removeAttribute` option changes as `babelCustomizations.removeAttribute`
|
|
187
|
-
- `removePropTypes` support for remove the prop types package in the output build.
|
|
188
|
-
- `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
|
|
189
|
-
- `manifestJson` default value set as false.
|
|
190
|
-
- `customAttributes` support for add attributes to html, link , script tag in the output build.
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
## v0.0.1 (18-04-2023)
|
|
194
|
-
|
|
195
|
-
First Release
|
|
196
|
-
**Features:-**
|
|
197
|
-
|
|
198
|
-
- 'start' command to run react app
|
|
199
|
-
- 'build' command to create build for react app
|
|
200
|
-
- 'build:lib' command to create lib for react library
|
|
201
|
-
- 'build:es' command to create es for react library
|
|
202
|
-
- 'templates' command to create es for react library
|
|
203
|
-
# Changelog and Release Notes
|
|
204
|
-
|
|
205
|
-
- remove babel-plugin-module-resolver dependencies
|
|
206
|
-
|
|
207
|
-
**Adjustments:-**
|
|
208
|
-
- Public Folder configuration is separated for development and production
|
|
209
|
-
|
|
210
|
-
**Bug Fix:-**
|
|
211
|
-
- Fixed the issue where the build log was not visible when `stats (bundle integrity)` was enabled. The problem was resolved by adding an error check in the `bundleIntegrity plugin`.
|
|
212
|
-
- Removed the babel-plugin-module-resolver dependency to resolve the alias resolution issue in the application.
|
|
213
|
-
- Fixed the issue where a space in the variable name causes it to return an undefined value.
|
|
214
|
-
- Fixed the URL path generation issue that occurred while using context in the development setup.
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
# v0.0.11
|
|
219
|
-
|
|
220
|
-
# v0.0.10 (12-05-2025)
|
|
221
|
-
**Feature:-**
|
|
222
|
-
- `alias` support for `build:es` and `build:lib`
|
|
223
|
-
- Add babel-plugin-module-resolver dependencies
|
|
224
|
-
- Modify getBabelPlugin to include module resolver with aliases
|
|
225
|
-
|
|
226
|
-
**Bug Fix:-**
|
|
227
|
-
- Enhance runBabelForTSFile to handle both .tsx and .ts file extensions
|
|
228
|
-
- Update mockApiHandler to ensure mock function is called correctly
|
|
229
|
-
|
|
230
|
-
**Change:-**
|
|
231
|
-
- Refactor defaultConfigValues.js to include cli options for enableRTLSplit
|
|
232
|
-
|
|
233
|
-
## v0.0.9
|
|
234
|
-
|
|
235
|
-
**Feature:-**
|
|
236
|
-
- externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
|
|
237
|
-
- to use externals, we use the following pattern in `app > externals` :
|
|
238
|
-
|
|
239
|
-
For example
|
|
240
|
-
```
|
|
241
|
-
externals: {
|
|
242
|
-
<key> : <value>
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
## v0.0.6 (4-09-2023)
|
|
247
|
-
|
|
248
|
-
**Feature:-**
|
|
249
|
-
- Generating bundle integrity report json file for the build assets only in production mode. To use this feature we need to add `stats > enable` or cli flags `enable_stats`.
|
|
250
|
-
- Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
|
|
251
|
-
- added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
|
|
252
|
-
only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
|
|
253
|
-
- added support for glob pattern for custom chunks split logic.
|
|
254
|
-
- added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
|
|
255
|
-
|
|
256
|
-
**Change:-**
|
|
257
|
-
- i18n name not generated issue fix.
|
|
258
|
-
- public path not correctly set issue fix.
|
|
259
|
-
- changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
|
|
260
|
-
## v0.0.5 (6-08-2023)
|
|
261
|
-
|
|
262
|
-
**Changes:--**
|
|
263
|
-
- Typo fix in i18nRuntimeDealerPlugin.js
|
|
264
|
-
- fixing some bugs in resolvers.js file
|
|
265
|
-
|
|
266
|
-
## v0.0.3 (1-08-2023)
|
|
267
|
-
|
|
268
|
-
**Changes:--**
|
|
269
|
-
- `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
|
|
270
|
-
- unwanted files deleted from build
|
|
271
|
-
|
|
272
|
-
**Issue Fix:--**
|
|
273
|
-
- The issue with the source map not being created in the build has been fixed."
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
## v0.0.2 (28-04-2023)
|
|
277
|
-
|
|
278
|
-
**Features:-**
|
|
279
|
-
|
|
280
|
-
- `devModeContentHashAllowedTypes` support added for some project there will be a need for hash even though they run dev mode. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#devModeContentHashAllowedTypes)
|
|
281
|
-
- `devLikeHash` support for disable content hash for file names in production mode. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#devLikeHash)
|
|
282
|
-
- `disableReactDevWarning` disable react dev warning such as prop-type warnings will be removed in dev mode build or server. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#disableReactDevWarning) can be enabled via `--disable_react_dev_warning` too.
|
|
283
|
-
- `statsLogConfig` support to customize default webpack log after build finished. for details [details](https://zgit.csez.zohocorpin.com/zohodesk/react-cli/-/blob/3.0.0/packages/client_build_tool/ConfigurationDocumentation.md#statsLogConfig) can be enabled via `--disable_react_dev_warning` too.
|
|
284
|
-
- `enableChunkHash` renamed as `enableFileNameHashing`
|
|
285
|
-
|
|
286
|
-
- `pre_processor` command to run the preprocessor.js file.preProcessor runs in build, start, buildEs, buildLib commands bu default. and we have watch mode support as well with the option (`-w`)
|
|
287
|
-
- `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
|
|
288
|
-
- `removeAttribute` option changes as `babelCustomizations.removeAttribute`
|
|
289
|
-
- `removePropTypes` support for remove the prop types package in the output build.
|
|
290
|
-
- `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
|
|
291
|
-
- `manifestJson` default value set as false.
|
|
292
|
-
- `customAttributes` support for add attributes to html, link , script tag in the output build.
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
## v0.0.1 (18-04-2023)
|
|
296
|
-
|
|
297
|
-
First Release
|
|
298
|
-
**Features:-**
|
|
299
|
-
|
|
300
|
-
- 'start' command to run react app
|
|
301
|
-
- 'build' command to create build for react app
|
|
302
|
-
- 'build:lib' command to create lib for react library
|
|
303
|
-
- 'build:es' command to create es for react library
|
|
304
|
-
- 'templates' command to create es for react library
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# I18n Numeric Indexing Plugin Documentation
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
The I18nNumericIndexPlugin is a webpack plugin that implements lazy loading for i18n translations with numeric indexing to reduce bundle size. It separates translations into multiple chunks that load on-demand.
|
|
5
|
+
|
|
6
|
+
## Features
|
|
7
|
+
|
|
8
|
+
### 1. **Numeric Indexing**
|
|
9
|
+
- Replaces string keys with numeric IDs (e.g., "support.label.home" → "1")
|
|
10
|
+
- Reduces bundle size by ~40%
|
|
11
|
+
- Maintains backward compatibility
|
|
12
|
+
|
|
13
|
+
### 2. **Custom Group Support**
|
|
14
|
+
- Define translation groups using banner markers in JSResources.properties
|
|
15
|
+
- Each group generates a separate chunk
|
|
16
|
+
- Groups load automatically when their associated code chunks load
|
|
17
|
+
|
|
18
|
+
### 3. **Lazy Loading**
|
|
19
|
+
- Initial load: Only numeric.i18n.js and dynamic.i18n.js
|
|
20
|
+
- Setup translations: Load only when SetupHome chunk loads
|
|
21
|
+
- Other groups: Load on-demand based on configuration
|
|
22
|
+
|
|
23
|
+
## Configuration
|
|
24
|
+
|
|
25
|
+
### In `cbt.config.js`:
|
|
26
|
+
|
|
27
|
+
```javascript
|
|
28
|
+
exports.config = {
|
|
29
|
+
i18nIndexing: {
|
|
30
|
+
enable: true,
|
|
31
|
+
jsResourcePath: './deskapp/properties/JSResources.properties',
|
|
32
|
+
propertiesFolderPath: './deskapp/properties',
|
|
33
|
+
numericMapPath: './deskapp/properties/i18n-numeric-map.json',
|
|
34
|
+
numericFilenameTemplate: 'i18n-chunk/[locale]/numeric.i18n.js',
|
|
35
|
+
dynamicFilenameTemplate: 'i18n-chunk/[locale]/dynamic.i18n.js',
|
|
36
|
+
jsonpFunc: 'window.loadI18nChunk',
|
|
37
|
+
htmlTemplateLabel: '{{--user-locale}}',
|
|
38
|
+
localeVarName: 'window.userLangCode',
|
|
39
|
+
customGroups: {
|
|
40
|
+
setup: {
|
|
41
|
+
bannerStart: '#SETUP_LAZY_KEYS STARTS',
|
|
42
|
+
bannerEnd: '#SETUP_LAZY_KEYS ENDS',
|
|
43
|
+
chunks: ['SetupHome'], // Webpack chunks that trigger this group
|
|
44
|
+
filenameTemplate: 'i18n-chunk/[locale]/setup.i18n.js',
|
|
45
|
+
preload: false,
|
|
46
|
+
prefetch: true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### In `JSResources.properties`:
|
|
54
|
+
|
|
55
|
+
```properties
|
|
56
|
+
# Regular translations
|
|
57
|
+
support.label.home=Home
|
|
58
|
+
support.label.tickets=Tickets
|
|
59
|
+
|
|
60
|
+
#SETUP_LAZY_KEYS STARTS
|
|
61
|
+
# These will be lazy loaded
|
|
62
|
+
support.setup.label.phone=Phone
|
|
63
|
+
support.setup.label.layouts_fields=Layouts and Fields
|
|
64
|
+
#SETUP_LAZY_KEYS ENDS
|
|
65
|
+
|
|
66
|
+
# More regular translations
|
|
67
|
+
support.label.chat=Chat
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### In `index.html`:
|
|
71
|
+
|
|
72
|
+
```javascript
|
|
73
|
+
window.loadI18nChunk = function(translations, groupName) {
|
|
74
|
+
// Merge translations
|
|
75
|
+
window.i18n = Object.assign(window.i18n, translations);
|
|
76
|
+
|
|
77
|
+
// Track loaded groups
|
|
78
|
+
if (groupName) {
|
|
79
|
+
console.log('[I18n] Loaded group:', groupName);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Notify framework
|
|
83
|
+
window.dispatchEvent(new CustomEvent('i18nLoaded', {
|
|
84
|
+
detail: { group: groupName }
|
|
85
|
+
}));
|
|
86
|
+
};
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## How It Works
|
|
90
|
+
|
|
91
|
+
### Build Time:
|
|
92
|
+
1. Plugin reads JSResources.properties
|
|
93
|
+
2. Parses banner markers to identify custom groups
|
|
94
|
+
3. Generates numeric mapping for all keys
|
|
95
|
+
4. Creates separate chunks:
|
|
96
|
+
- `numeric.i18n.js` - Main translations with numeric keys
|
|
97
|
+
- `dynamic.i18n.js` - Keys with placeholders (keep string keys)
|
|
98
|
+
- `setup.i18n.js` - Setup-specific translations (lazy loaded)
|
|
99
|
+
|
|
100
|
+
### Runtime:
|
|
101
|
+
1. Initial page load → Loads numeric.i18n.js + dynamic.i18n.js
|
|
102
|
+
2. User clicks Setup → Webpack loads SetupHome.js
|
|
103
|
+
3. Plugin runtime detects SetupHome needs 'setup' group
|
|
104
|
+
4. Automatically loads setup.i18n.js
|
|
105
|
+
5. Calls window.loadI18nChunk() with translations
|
|
106
|
+
|
|
107
|
+
## Output Structure
|
|
108
|
+
|
|
109
|
+
```
|
|
110
|
+
agent/
|
|
111
|
+
└── i18n-chunk/
|
|
112
|
+
├── en_US/
|
|
113
|
+
│ ├── numeric.i18n.js (396KB - main translations)
|
|
114
|
+
│ ├── dynamic.i18n.js (201KB - dynamic keys)
|
|
115
|
+
│ └── setup.i18n.js (217B - setup keys only!)
|
|
116
|
+
└── [other locales]/
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Generated Files
|
|
120
|
+
|
|
121
|
+
### numeric.i18n.js:
|
|
122
|
+
```javascript
|
|
123
|
+
window.loadI18nChunk({
|
|
124
|
+
"1": "Home",
|
|
125
|
+
"2": "Tickets",
|
|
126
|
+
"3": "Chat"
|
|
127
|
+
// ... thousands more
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### setup.i18n.js:
|
|
132
|
+
```javascript
|
|
133
|
+
window.loadI18nChunk({
|
|
134
|
+
"4547": "Phone",
|
|
135
|
+
"4548": "Zia",
|
|
136
|
+
"4549": "Layouts and Fields"
|
|
137
|
+
// ... setup-specific keys
|
|
138
|
+
}, "setup");
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### i18n-numeric-map.json:
|
|
142
|
+
```json
|
|
143
|
+
{
|
|
144
|
+
"support.label.home": 1,
|
|
145
|
+
"support.label.tickets": 2,
|
|
146
|
+
"support.setup.label.phone": 4547
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Using webpackI18nGroup Comments
|
|
151
|
+
|
|
152
|
+
You can also mark chunks for i18n groups using comments:
|
|
153
|
+
|
|
154
|
+
```javascript
|
|
155
|
+
const SetupHome = lazy(() =>
|
|
156
|
+
import(
|
|
157
|
+
/* webpackChunkName: "SetupHome" */
|
|
158
|
+
/* webpackI18nGroup: "setup" */
|
|
159
|
+
'./pages/SetupHome'
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Performance Benefits
|
|
165
|
+
|
|
166
|
+
1. **Initial Bundle**: ~40% smaller due to numeric indexing
|
|
167
|
+
2. **Setup Keys**: Only 217 bytes, loaded on-demand
|
|
168
|
+
3. **Network**: Fewer bytes transferred
|
|
169
|
+
4. **Memory**: Reduced memory footprint
|
|
170
|
+
|
|
171
|
+
## Adding New Groups
|
|
172
|
+
|
|
173
|
+
To add a new lazy-loaded group (e.g., "reports"):
|
|
174
|
+
|
|
175
|
+
1. Add banner markers in JSResources.properties:
|
|
176
|
+
```properties
|
|
177
|
+
#REPORTS_LAZY_KEYS STARTS
|
|
178
|
+
support.reports.label.dashboard=Dashboard
|
|
179
|
+
#REPORTS_LAZY_KEYS ENDS
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
2. Update cbt.config.js:
|
|
183
|
+
```javascript
|
|
184
|
+
customGroups: {
|
|
185
|
+
setup: { /* ... */ },
|
|
186
|
+
reports: {
|
|
187
|
+
bannerStart: '#REPORTS_LAZY_KEYS STARTS',
|
|
188
|
+
bannerEnd: '#REPORTS_LAZY_KEYS ENDS',
|
|
189
|
+
chunks: ['ReportsHome'],
|
|
190
|
+
filenameTemplate: 'i18n-chunk/[locale]/reports.i18n.js'
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Troubleshooting
|
|
196
|
+
|
|
197
|
+
### Keys not in setup chunk:
|
|
198
|
+
- Check banner markers are correct in JSResources.properties
|
|
199
|
+
- Verify key is between STARTS and ENDS markers
|
|
200
|
+
|
|
201
|
+
### Setup chunk not loading:
|
|
202
|
+
- Ensure SetupHome is in the chunks array
|
|
203
|
+
- Check browser DevTools Network tab
|
|
204
|
+
- Verify window.loadI18nChunk is defined
|
|
205
|
+
|
|
206
|
+
### Numeric mapping issues:
|
|
207
|
+
- Check i18n-numeric-map.json is generated
|
|
208
|
+
- Verify no duplicate keys
|
|
209
|
+
- Ensure jsResourcePath is correct
|
|
210
|
+
|
|
211
|
+
## Migration Guide
|
|
212
|
+
|
|
213
|
+
1. Enable i18nIndexing in cbt.config.js
|
|
214
|
+
2. Add banner markers to JSResources.properties
|
|
215
|
+
3. Update index.html with loadI18nChunk function
|
|
216
|
+
4. Build and test
|
|
217
|
+
5. Monitor Network tab to verify lazy loading
|
|
218
|
+
|
|
219
|
+
## Best Practices
|
|
220
|
+
|
|
221
|
+
1. **Group Related Keys**: Keep setup keys together
|
|
222
|
+
2. **Use Root Chunks**: Configure the main entry chunk for each section
|
|
223
|
+
3. **Monitor Bundle Size**: Check generated file sizes
|
|
224
|
+
4. **Test Loading**: Verify chunks load when expected
|
|
225
|
+
5. **Keep Groups Small**: Aim for <1KB per lazy group
|
|
@@ -174,25 +174,22 @@ var _default = {
|
|
|
174
174
|
localeVarName: 'document.documentElement.lang',
|
|
175
175
|
jsonpFunc: 'console.log',
|
|
176
176
|
jsResource: null,
|
|
177
|
-
propertiesFolder: null
|
|
178
|
-
useNumericIndexing: false
|
|
177
|
+
propertiesFolder: null
|
|
179
178
|
},
|
|
180
179
|
i18nIndexing: {
|
|
181
|
-
enable:
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
180
|
+
enable: {
|
|
181
|
+
value: false,
|
|
182
|
+
cli: 'i18n_indexing'
|
|
183
|
+
},
|
|
184
|
+
jsResourcePath: null,
|
|
185
|
+
propertiesFolderPath: null,
|
|
186
|
+
numericMapPath: null,
|
|
186
187
|
numericFilenameTemplate: 'i18n-chunk/[locale]/numeric.i18n.js',
|
|
187
188
|
dynamicFilenameTemplate: 'i18n-chunk/[locale]/dynamic.i18n.js',
|
|
188
|
-
singleFileTemplate: 'i18n/[locale].js',
|
|
189
189
|
jsonpFunc: 'window.loadI18nChunk',
|
|
190
190
|
htmlTemplateLabel: '{{--user-locale}}',
|
|
191
191
|
localeVarName: 'window.userLangCode',
|
|
192
|
-
|
|
193
|
-
includeContentHash: false,
|
|
194
|
-
generateManifest: false,
|
|
195
|
-
manifestPath: null
|
|
192
|
+
customGroups: null
|
|
196
193
|
},
|
|
197
194
|
publicFolders: {
|
|
198
195
|
dev: ['...'],
|
|
@@ -94,24 +94,7 @@ var _default = {
|
|
|
94
94
|
localeVarName: 'document.documentElement.lang',
|
|
95
95
|
jsonpFunc: 'console.log',
|
|
96
96
|
jsResource: null,
|
|
97
|
-
propertiesFolder: null
|
|
98
|
-
useNumericIndexing: false
|
|
99
|
-
},
|
|
100
|
-
i18nIndexing: {
|
|
101
|
-
enable: false,
|
|
102
|
-
devMode: false,
|
|
103
|
-
jsResourcePath: './deskapp/properties/JSResources.properties',
|
|
104
|
-
propertiesFolderPath: './deskapp/properties',
|
|
105
|
-
numericMapPath: './deskapp/properties/i18n-numeric-map.json',
|
|
106
|
-
numericFilenameTemplate: 'i18n-chunk/[locale]/numeric.i18n.js',
|
|
107
|
-
dynamicFilenameTemplate: 'i18n-chunk/[locale]/dynamic.i18n.js',
|
|
108
|
-
jsonpFunc: 'window.loadI18nChunk',
|
|
109
|
-
htmlTemplateLabel: '{{--user-locale}}',
|
|
110
|
-
localeVarName: 'window.userLangCode',
|
|
111
|
-
singleFile: false,
|
|
112
|
-
includeContentHash: false,
|
|
113
|
-
generateManifest: false,
|
|
114
|
-
manifestPath: null
|
|
97
|
+
propertiesFolder: null
|
|
115
98
|
},
|
|
116
99
|
publicFolders: {
|
|
117
100
|
dev: ['...'],
|
package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.I18nGroupRuntimeModule = void 0;
|
|
7
|
+
|
|
8
|
+
var _webpack = require("webpack");
|
|
9
|
+
|
|
10
|
+
class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
super('i18n-group-loader');
|
|
13
|
+
this.options = options;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
generate() {
|
|
17
|
+
const {
|
|
18
|
+
customGroups,
|
|
19
|
+
localeVarName,
|
|
20
|
+
jsonpFunc
|
|
21
|
+
} = this.options; // Build chunk-to-group mapping from config
|
|
22
|
+
|
|
23
|
+
const chunkToGroup = {};
|
|
24
|
+
Object.entries(customGroups || {}).forEach(([groupName, config]) => {
|
|
25
|
+
(config.chunks || []).forEach(chunkName => {
|
|
26
|
+
chunkToGroup[chunkName] = groupName;
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
return `
|
|
30
|
+
// I18n Group Loading Runtime
|
|
31
|
+
(function() {
|
|
32
|
+
var loadedGroups = {};
|
|
33
|
+
var chunkToGroup = ${JSON.stringify(chunkToGroup)};
|
|
34
|
+
|
|
35
|
+
// Store original webpack chunk loading function
|
|
36
|
+
var originalEnsureChunk = __webpack_require__.e;
|
|
37
|
+
|
|
38
|
+
// Override webpack's chunk loading
|
|
39
|
+
__webpack_require__.e = function(chunkId) {
|
|
40
|
+
var promise = originalEnsureChunk.apply(this, arguments);
|
|
41
|
+
|
|
42
|
+
// Check if this chunk needs an i18n group
|
|
43
|
+
var groupName = chunkToGroup[chunkId];
|
|
44
|
+
if (groupName && !loadedGroups[groupName]) {
|
|
45
|
+
// Load the i18n group
|
|
46
|
+
var locale = ${localeVarName} || 'en_US';
|
|
47
|
+
var groupConfig = ${JSON.stringify(customGroups)};
|
|
48
|
+
var config = groupConfig[groupName];
|
|
49
|
+
|
|
50
|
+
if (config) {
|
|
51
|
+
var i18nUrl = config.filenameTemplate
|
|
52
|
+
.replace('[locale]', locale)
|
|
53
|
+
.replace('i18n-chunk/', __webpack_require__.p + 'i18n-chunk/');
|
|
54
|
+
|
|
55
|
+
// Create script tag to load i18n chunk
|
|
56
|
+
var script = document.createElement('script');
|
|
57
|
+
script.src = i18nUrl;
|
|
58
|
+
script.async = true;
|
|
59
|
+
|
|
60
|
+
// Mark as loaded when script loads
|
|
61
|
+
script.onload = function() {
|
|
62
|
+
loadedGroups[groupName] = true;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
document.head.appendChild(script);
|
|
66
|
+
|
|
67
|
+
// If prefetch is enabled, prefetch other locales
|
|
68
|
+
if (config.prefetch && !config.preload) {
|
|
69
|
+
var link = document.createElement('link');
|
|
70
|
+
link.rel = 'prefetch';
|
|
71
|
+
link.href = i18nUrl;
|
|
72
|
+
document.head.appendChild(link);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return promise;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Also check for webpackI18nGroup comments in dynamic imports
|
|
81
|
+
if (typeof __webpack_require__.l !== 'undefined') {
|
|
82
|
+
var originalLoadScript = __webpack_require__.l;
|
|
83
|
+
__webpack_require__.l = function(url, done, key, chunkId) {
|
|
84
|
+
// Check if chunk has i18n group
|
|
85
|
+
var groupName = chunkToGroup[chunkId];
|
|
86
|
+
if (groupName && !loadedGroups[groupName]) {
|
|
87
|
+
// Load i18n before main chunk
|
|
88
|
+
var locale = ${localeVarName} || 'en_US';
|
|
89
|
+
var groupConfig = ${JSON.stringify(customGroups)};
|
|
90
|
+
var config = groupConfig[groupName];
|
|
91
|
+
|
|
92
|
+
if (config) {
|
|
93
|
+
var i18nUrl = config.filenameTemplate
|
|
94
|
+
.replace('[locale]', locale)
|
|
95
|
+
.replace('i18n-chunk/', __webpack_require__.p + 'i18n-chunk/');
|
|
96
|
+
|
|
97
|
+
// Load i18n first, then the chunk
|
|
98
|
+
var i18nScript = document.createElement('script');
|
|
99
|
+
i18nScript.src = i18nUrl;
|
|
100
|
+
i18nScript.onload = function() {
|
|
101
|
+
loadedGroups[groupName] = true;
|
|
102
|
+
// Now load the original chunk
|
|
103
|
+
originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
104
|
+
};
|
|
105
|
+
i18nScript.onerror = function() {
|
|
106
|
+
// Continue even if i18n fails
|
|
107
|
+
originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
108
|
+
};
|
|
109
|
+
document.head.appendChild(i18nScript);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Default behavior
|
|
115
|
+
return originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
})();
|
|
119
|
+
`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
exports.I18nGroupRuntimeModule = I18nGroupRuntimeModule;
|