@zohodesk/client_build_tool 0.0.10 → 0.0.11-exp.6

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.
Files changed (24) hide show
  1. package/CHANGELOG.md +0 -10
  2. package/README.md +146 -8
  3. package/README_backup.md +148 -0
  4. package/lib/schemas/defaultConfigValues.js +17 -5
  5. package/lib/schemas/defaultConfigValuesOnly.js +16 -1
  6. package/lib/shared/babel/getBabelPlugin.js +4 -9
  7. package/lib/shared/babel/runBabelForTsFile.js +1 -1
  8. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexHtmlInjectorPlugin.js +49 -0
  9. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin.js +161 -0
  10. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nNumericIndexPlugin_simplified.js +129 -0
  11. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/i18nDataLoader.js +134 -0
  12. package/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/utils/i18nDataLoader.js +113 -0
  13. package/lib/shared/bundler/webpack/custom_plugins/I18nSplitPlugin/utils/collectAstKeys.js +96 -0
  14. package/lib/shared/bundler/webpack/jsLoaders.js +20 -2
  15. package/lib/shared/bundler/webpack/loaderConfigs/i18nIdReplaceLoaderConfig.js +74 -0
  16. package/lib/shared/bundler/webpack/loaders/i18nIdReplaceLoader.js +105 -0
  17. package/lib/shared/bundler/webpack/pluginConfigs/configI18nNumericIndexPlugin.js +70 -0
  18. package/lib/shared/bundler/webpack/plugins.js +3 -1
  19. package/lib/shared/bundler/webpack/utils/i18n/collectAstKeys.js +96 -0
  20. package/lib/shared/bundler/webpack/utils/propertiesParser.js +103 -0
  21. package/lib/shared/server/mockApiHandler.js +0 -7
  22. package/lib/shared/server/urlConcat.js +1 -1
  23. package/npm-shrinkwrap.json +32 -8240
  24. package/package.json +5 -6
package/CHANGELOG.md CHANGED
@@ -1,16 +1,6 @@
1
1
  # Changelog and Release Notes
2
- # v0.0.10 (12-05-2025)
3
- **Feature:-**
4
- - `alias` support for `build:es` and `build:lib`
5
- - Add babel-plugin-module-resolver dependencies
6
- - Modify getBabelPlugin to include module resolver with aliases
7
2
 
8
- **Bug Fix:-**
9
- - Enhance runBabelForTSFile to handle both .tsx and .ts file extensions
10
- - Update mockApiHandler to ensure mock function is called correctly
11
3
 
12
- **Change:-**
13
- - Refactor defaultConfigValues.js to include cli options for enableRTLSplit
14
4
 
15
5
  **Feature:-**
16
6
  - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
package/README.md CHANGED
@@ -99,18 +99,156 @@ fixes :-
99
99
  - preload plc undefined url fixed
100
100
 
101
101
  # Changelog and Release Notes
102
- # v0.0.10 (12-05-2025)
102
+
103
+
104
+
105
+ **Feature:-**
106
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
107
+ - to use externals, we use the following pattern in `app > externals` :
108
+
109
+ For example
110
+ ```
111
+ externals: {
112
+ <key> : <value>
113
+ }
114
+ ```
115
+
116
+ ## v0.0.6 (4-09-2023)
117
+
118
+ **Feature:-**
119
+ - 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`.
120
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
121
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
122
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
123
+ - added support for glob pattern for custom chunks split logic.
124
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
125
+
126
+ **Change:-**
127
+ - i18n name not generated issue fix.
128
+ - public path not correctly set issue fix.
129
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
130
+ ## v0.0.5 (6-08-2023)
131
+
132
+ **Changes:--**
133
+ - Typo fix in i18nRuntimeDealerPlugin.js
134
+ - fixing some bugs in resolvers.js file
135
+
136
+ ## v0.0.3 (1-08-2023)
137
+
138
+ **Changes:--**
139
+ - `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
140
+ - unwanted files deleted from build
141
+
142
+ **Issue Fix:--**
143
+ - The issue with the source map not being created in the build has been fixed."
144
+
145
+
146
+ ## v0.0.2 (28-04-2023)
147
+
148
+ **Features:-**
149
+
150
+ - `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)
151
+ - `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)
152
+ - `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.
153
+ - `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.
154
+ - `enableChunkHash` renamed as `enableFileNameHashing`
155
+
156
+ - `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`)
157
+ - `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
158
+ - `removeAttribute` option changes as `babelCustomizations.removeAttribute`
159
+ - `removePropTypes` support for remove the prop types package in the output build.
160
+ - `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
161
+ - `manifestJson` default value set as false.
162
+ - `customAttributes` support for add attributes to html, link , script tag in the output build.
163
+
164
+
165
+ ## v0.0.1 (18-04-2023)
166
+
167
+ First Release
168
+ **Features:-**
169
+
170
+ - 'start' command to run react app
171
+ - 'build' command to create build for react app
172
+ - 'build:lib' command to create lib for react library
173
+ - 'build:es' command to create es for react library
174
+ - 'templates' command to create es for react library
175
+ # Changelog and Release Notes
176
+
177
+
178
+
103
179
  **Feature:-**
104
- - `alias` support for `build:es` and `build:lib`
105
- - Add babel-plugin-module-resolver dependencies
106
- - Modify getBabelPlugin to include module resolver with aliases
180
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
181
+ - to use externals, we use the following pattern in `app > externals` :
107
182
 
108
- **Bug Fix:-**
109
- - Enhance runBabelForTSFile to handle both .tsx and .ts file extensions
110
- - Update mockApiHandler to ensure mock function is called correctly
183
+ For example
184
+ ```
185
+ externals: {
186
+ <key> : <value>
187
+ }
188
+ ```
189
+
190
+ ## v0.0.6 (4-09-2023)
191
+
192
+ **Feature:-**
193
+ - 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`.
194
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
195
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
196
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
197
+ - added support for glob pattern for custom chunks split logic.
198
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
111
199
 
112
200
  **Change:-**
113
- - Refactor defaultConfigValues.js to include cli options for enableRTLSplit
201
+ - i18n name not generated issue fix.
202
+ - public path not correctly set issue fix.
203
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
204
+ ## v0.0.5 (6-08-2023)
205
+
206
+ **Changes:--**
207
+ - Typo fix in i18nRuntimeDealerPlugin.js
208
+ - fixing some bugs in resolvers.js file
209
+
210
+ ## v0.0.3 (1-08-2023)
211
+
212
+ **Changes:--**
213
+ - `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
214
+ - unwanted files deleted from build
215
+
216
+ **Issue Fix:--**
217
+ - The issue with the source map not being created in the build has been fixed."
218
+
219
+
220
+ ## v0.0.2 (28-04-2023)
221
+
222
+ **Features:-**
223
+
224
+ - `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)
225
+ - `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)
226
+ - `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.
227
+ - `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.
228
+ - `enableChunkHash` renamed as `enableFileNameHashing`
229
+
230
+ - `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`)
231
+ - `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
232
+ - `removeAttribute` option changes as `babelCustomizations.removeAttribute`
233
+ - `removePropTypes` support for remove the prop types package in the output build.
234
+ - `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
235
+ - `manifestJson` default value set as false.
236
+ - `customAttributes` support for add attributes to html, link , script tag in the output build.
237
+
238
+
239
+ ## v0.0.1 (18-04-2023)
240
+
241
+ First Release
242
+ **Features:-**
243
+
244
+ - 'start' command to run react app
245
+ - 'build' command to create build for react app
246
+ - 'build:lib' command to create lib for react library
247
+ - 'build:es' command to create es for react library
248
+ - 'templates' command to create es for react library
249
+ # Changelog and Release Notes
250
+
251
+
114
252
 
115
253
  **Feature:-**
116
254
  - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
package/README_backup.md CHANGED
@@ -98,3 +98,151 @@ fixes :-
98
98
 
99
99
  - preload plc undefined url fixed
100
100
 
101
+ # Changelog and Release Notes
102
+
103
+
104
+
105
+ **Feature:-**
106
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
107
+ - to use externals, we use the following pattern in `app > externals` :
108
+
109
+ For example
110
+ ```
111
+ externals: {
112
+ <key> : <value>
113
+ }
114
+ ```
115
+
116
+ ## v0.0.6 (4-09-2023)
117
+
118
+ **Feature:-**
119
+ - 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`.
120
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
121
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
122
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
123
+ - added support for glob pattern for custom chunks split logic.
124
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
125
+
126
+ **Change:-**
127
+ - i18n name not generated issue fix.
128
+ - public path not correctly set issue fix.
129
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
130
+ ## v0.0.5 (6-08-2023)
131
+
132
+ **Changes:--**
133
+ - Typo fix in i18nRuntimeDealerPlugin.js
134
+ - fixing some bugs in resolvers.js file
135
+
136
+ ## v0.0.3 (1-08-2023)
137
+
138
+ **Changes:--**
139
+ - `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
140
+ - unwanted files deleted from build
141
+
142
+ **Issue Fix:--**
143
+ - The issue with the source map not being created in the build has been fixed."
144
+
145
+
146
+ ## v0.0.2 (28-04-2023)
147
+
148
+ **Features:-**
149
+
150
+ - `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)
151
+ - `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)
152
+ - `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.
153
+ - `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.
154
+ - `enableChunkHash` renamed as `enableFileNameHashing`
155
+
156
+ - `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`)
157
+ - `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
158
+ - `removeAttribute` option changes as `babelCustomizations.removeAttribute`
159
+ - `removePropTypes` support for remove the prop types package in the output build.
160
+ - `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
161
+ - `manifestJson` default value set as false.
162
+ - `customAttributes` support for add attributes to html, link , script tag in the output build.
163
+
164
+
165
+ ## v0.0.1 (18-04-2023)
166
+
167
+ First Release
168
+ **Features:-**
169
+
170
+ - 'start' command to run react app
171
+ - 'build' command to create build for react app
172
+ - 'build:lib' command to create lib for react library
173
+ - 'build:es' command to create es for react library
174
+ - 'templates' command to create es for react library
175
+ # Changelog and Release Notes
176
+
177
+
178
+
179
+ **Feature:-**
180
+ - externals was added to Prevent bundling of certain imported packages and retrieve these external dependencies at runtime.
181
+ - to use externals, we use the following pattern in `app > externals` :
182
+
183
+ For example
184
+ ```
185
+ externals: {
186
+ <key> : <value>
187
+ }
188
+ ```
189
+
190
+ ## v0.0.6 (4-09-2023)
191
+
192
+ **Feature:-**
193
+ - 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`.
194
+ - Added Resource Cleanup plugin to cleanup resource retained by build tool. this plugin is controlled by efc flag resourcecleanup flag.
195
+ - added support for using regex expression to get group of chunks chunkId via Resource Hint plugin prefetch/preload hook.
196
+ only will be activate when `resourceHints` => `allowPrefetchingMultipleChunks` as `true`
197
+ - added support for glob pattern for custom chunks split logic.
198
+ - added options to split chunks base config in the key `app` => `customChunksBaseConfig` as object
199
+
200
+ **Change:-**
201
+ - i18n name not generated issue fix.
202
+ - public path not correctly set issue fix.
203
+ - changing plugin hook stages in i18nRuntimePlugin and sourceMapPlugin
204
+ ## v0.0.5 (6-08-2023)
205
+
206
+ **Changes:--**
207
+ - Typo fix in i18nRuntimeDealerPlugin.js
208
+ - fixing some bugs in resolvers.js file
209
+
210
+ ## v0.0.3 (1-08-2023)
211
+
212
+ **Changes:--**
213
+ - `devtool` default value changed from `hidden-cheap-source-map` to `source-map`
214
+ - unwanted files deleted from build
215
+
216
+ **Issue Fix:--**
217
+ - The issue with the source map not being created in the build has been fixed."
218
+
219
+
220
+ ## v0.0.2 (28-04-2023)
221
+
222
+ **Features:-**
223
+
224
+ - `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)
225
+ - `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)
226
+ - `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.
227
+ - `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.
228
+ - `enableChunkHash` renamed as `enableFileNameHashing`
229
+
230
+ - `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`)
231
+ - `createSeparateSmap` flag `source_map_enable` renamed as `enable_smap`
232
+ - `removeAttribute` option changes as `babelCustomizations.removeAttribute`
233
+ - `removePropTypes` support for remove the prop types package in the output build.
234
+ - `devConsoleExclude` support for remove the _console statements_ such as _console.log_, _console.warn_ in the output build.
235
+ - `manifestJson` default value set as false.
236
+ - `customAttributes` support for add attributes to html, link , script tag in the output build.
237
+
238
+
239
+ ## v0.0.1 (18-04-2023)
240
+
241
+ First Release
242
+ **Features:-**
243
+
244
+ - 'start' command to run react app
245
+ - 'build' command to create build for react app
246
+ - 'build:lib' command to create lib for react library
247
+ - 'build:es' command to create es for react library
248
+ - 'templates' command to create es for react library
@@ -115,10 +115,7 @@ var _default = {
115
115
  // Name Suggestions `customizations` this will be easier then `plugin` to understand for developers
116
116
  plugins: {
117
117
  rtlSplit: {
118
- enableRTLSplit: {
119
- value: false,
120
- cli: 'enable_rtl_split'
121
- },
118
+ enableRTLSplit: false,
122
119
  templateLabel: '{{--dir}}',
123
120
  disableMinifySelector: false,
124
121
  dirVarName: 'document.dir'
@@ -174,7 +171,22 @@ var _default = {
174
171
  localeVarName: 'document.documentElement.lang',
175
172
  jsonpFunc: 'console.log',
176
173
  jsResource: null,
177
- propertiesFolder: null
174
+ propertiesFolder: null,
175
+ useNumericIndexing: false
176
+ },
177
+ i18nIndexing: {
178
+ enable: false,
179
+ jsResourcePath: './deskapp/properties/JSResources.properties',
180
+ propertiesFolderPath: './deskapp/properties',
181
+ numericMapPath: './deskapp/properties/i18n-numeric-map.json',
182
+ numericFilenameTemplate: 'i18n-chunk/[locale]/numeric.i18n.js',
183
+ dynamicFilenameTemplate: 'i18n-chunk/[locale]/dynamic.i18n.js',
184
+ jsonpFunc: 'window.loadI18nChunk',
185
+ htmlTemplateLabel: '{{--user-locale}}',
186
+ localeVarName: 'window.userLangCode',
187
+ singleFile: false,
188
+ includeContentHash: false,
189
+ generateManifest: false
178
190
  },
179
191
  publicFolders: ['...'],
180
192
  app: {
@@ -94,7 +94,22 @@ var _default = {
94
94
  localeVarName: 'document.documentElement.lang',
95
95
  jsonpFunc: 'console.log',
96
96
  jsResource: null,
97
- propertiesFolder: null
97
+ propertiesFolder: null,
98
+ useNumericIndexing: false
99
+ },
100
+ i18nIndexing: {
101
+ enable: false,
102
+ jsResourcePath: './deskapp/properties/JSResources.properties',
103
+ propertiesFolderPath: './deskapp/properties',
104
+ numericMapPath: './deskapp/properties/i18n-numeric-map.json',
105
+ numericFilenameTemplate: 'i18n-chunk/[locale]/numeric.i18n.js',
106
+ dynamicFilenameTemplate: 'i18n-chunk/[locale]/dynamic.i18n.js',
107
+ jsonpFunc: 'window.loadI18nChunk',
108
+ htmlTemplateLabel: '{{--user-locale}}',
109
+ localeVarName: 'window.userLangCode',
110
+ singleFile: false,
111
+ includeContentHash: false,
112
+ generateManifest: false
98
113
  },
99
114
  publicFolders: ['...', {
100
115
  source: './deskapp/tp/',
@@ -20,14 +20,7 @@ function getBabelPlugin(options) {
20
20
  const {
21
21
  mode
22
22
  } = options;
23
- const {
24
- alias
25
- } = options.resolve; // let customPlugins = [];
26
-
27
- let customPlugins = [[require.resolve('babel-plugin-module-resolver'), {
28
- root: ['./'],
29
- alias
30
- }]];
23
+ let customPlugins = [];
31
24
  const {
32
25
  babelCustomizations
33
26
  } = options;
@@ -39,4 +32,6 @@ function getBabelPlugin(options) {
39
32
  }
40
33
 
41
34
  return customPlugins.filter(Boolean);
42
- }
35
+ }
36
+
37
+ ;
@@ -25,6 +25,6 @@ function runBabelForTSFile({
25
25
  // const jsSourceCode = readFileSync(filename).toString();
26
26
  const babelConfig = (0, _babelWebConfig.babelWebConfig)(options, mode);
27
27
  const result = (0, _core.transformFileSync)(filename, babelConfig);
28
- (0, _copyFile.writeFile)(outputFile.replace('.tsx', '.js').replace('.ts', '.js'), result.code);
28
+ (0, _copyFile.writeFile)(outputFile.replace('.tsx', '.js'), result.code);
29
29
  }
30
30
  }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ const HtmlWebpackPlugin = require('html-webpack-plugin');
4
+
5
+ const pluginName = 'I18nNumericIndexHtmlInjectorPlugin';
6
+
7
+ class I18nNumericIndexHtmlInjectorPlugin {
8
+ constructor(options) {
9
+ this.options = options;
10
+ }
11
+
12
+ apply(compiler) {
13
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
14
+ HtmlWebpackPlugin.getHooks(compilation).beforeAssetTagGeneration.tapAsync(pluginName, (hookData, cb) => {
15
+ const {
16
+ assets
17
+ } = hookData;
18
+ const {
19
+ numericFilenameTemplate,
20
+ dynamicFilenameTemplate,
21
+ htmlTemplateLabel,
22
+ i18nAssetsPublicPathPrefix = ''
23
+ } = this.options;
24
+ const newI18nAssetUrlsToAdd = [];
25
+
26
+ if (numericFilenameTemplate) {
27
+ const numericFilename = numericFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
28
+ newI18nAssetUrlsToAdd.push(numericFilename);
29
+ }
30
+
31
+ if (dynamicFilenameTemplate) {
32
+ const dynamicFilename = dynamicFilenameTemplate.replace(/\[locale\]/g, htmlTemplateLabel);
33
+ newI18nAssetUrlsToAdd.push(dynamicFilename);
34
+ }
35
+
36
+ if (newI18nAssetUrlsToAdd.length > 0) {
37
+ assets.js = [...assets.js, ...newI18nAssetUrlsToAdd];
38
+ }
39
+
40
+ cb(null, hookData);
41
+ });
42
+ });
43
+ }
44
+
45
+ }
46
+
47
+ module.exports = {
48
+ I18nNumericIndexHtmlInjectorPlugin
49
+ };
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+
3
+ const path = require('path');
4
+
5
+ const {
6
+ sources,
7
+ Compilation,
8
+ util
9
+ } = require('webpack');
10
+
11
+ const {
12
+ decodeUnicodeEscapes
13
+ } = require('../../utils/propertiesParser');
14
+
15
+ const {
16
+ loadNumericMap,
17
+ loadI18nData
18
+ } = require('./utils/i18nDataLoader');
19
+
20
+ const {
21
+ RawSource
22
+ } = sources;
23
+ const pluginName = 'I18nNumericIndexPlugin';
24
+
25
+ class I18nNumericIndexPlugin {
26
+ constructor(options = {}) {
27
+ this.options = { ...options,
28
+ singleFile: options.singleFile || false,
29
+ includeContentHash: options.includeContentHash || false,
30
+ generateManifest: options.generateManifest || false
31
+ };
32
+ this.numericMap = null;
33
+ this.i18nData = null;
34
+ this.manifest = {};
35
+ }
36
+
37
+ getNumericMap(compilation) {
38
+ if (!this.numericMap) {
39
+ const mapPath = path.resolve(compilation.compiler.context, this.options.numericMapPath);
40
+ this.numericMap = loadNumericMap(mapPath, compilation);
41
+ }
42
+
43
+ return this.numericMap;
44
+ }
45
+
46
+ getI18nData(compilation) {
47
+ if (!this.i18nData) {
48
+ this.i18nData = loadI18nData(this.options, compilation);
49
+ }
50
+
51
+ return this.i18nData;
52
+ }
53
+
54
+ generateContentHash(content, compilation) {
55
+ const {
56
+ hashFunction,
57
+ hashDigest,
58
+ hashDigestLength
59
+ } = compilation.outputOptions;
60
+ const hash = util.createHash(hashFunction || 'xxhash64');
61
+ hash.update(content);
62
+ return hash.digest(hashDigest || 'hex').substring(0, hashDigestLength || 20);
63
+ }
64
+
65
+ emitChunk(compilation, filename, locale, data, fileType = null) {
66
+ const content = decodeUnicodeEscapes(JSON.stringify(data));
67
+ const fileContent = `${this.options.jsonpFunc}(${content});`;
68
+ let outputPath = filename.replace(/\[locale\]/g, locale);
69
+
70
+ if (this.options.includeContentHash) {
71
+ const contentHash = this.generateContentHash(fileContent, compilation);
72
+ outputPath = outputPath.replace(/\.js$/, `.${contentHash}.js`);
73
+ }
74
+
75
+ if (this.options.generateManifest) {
76
+ const cleanName = filename.replace(/\[locale\]/g, locale).replace(/\.js$/, '.js');
77
+ const cleanNameWithType = fileType ? cleanName.replace(/\.js$/, `.${fileType}.js`) : cleanName;
78
+ this.manifest[cleanNameWithType] = outputPath.split('/').pop();
79
+ }
80
+
81
+ compilation.emitAsset(outputPath, new RawSource(fileContent));
82
+ return outputPath;
83
+ }
84
+
85
+ apply(compiler) {
86
+ compiler.hooks.thisCompilation.tap(pluginName, compilation => {
87
+ compilation.hooks.processAssets.tapAsync({
88
+ name: pluginName,
89
+ stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
90
+ }, (assets, callback) => {
91
+ if (!this.options.enable) {
92
+ return callback();
93
+ }
94
+
95
+ const {
96
+ sortedKeys,
97
+ totalKeys
98
+ } = this.getNumericMap(compilation);
99
+ const {
100
+ jsResourceBase,
101
+ allI18n,
102
+ locales
103
+ } = this.getI18nData(compilation);
104
+ if (!locales.length) return callback();
105
+ const numericKeysSet = new Set(sortedKeys);
106
+ const englishData = allI18n.en_US || jsResourceBase;
107
+ locales.forEach(locale => {
108
+ const localeData = allI18n[locale] || {};
109
+ const numericData = {};
110
+
111
+ for (let i = 0; i < totalKeys; i++) {
112
+ const key = sortedKeys[i];
113
+
114
+ if (key && jsResourceBase[key] !== undefined) {
115
+ numericData[i] = localeData[key] ?? englishData[key];
116
+ }
117
+ }
118
+
119
+ const dynamicData = {};
120
+ Object.keys(jsResourceBase).forEach(key => {
121
+ if (!numericKeysSet.has(key)) {
122
+ dynamicData[key] = localeData[key] ?? englishData[key];
123
+ }
124
+ });
125
+
126
+ if (this.options.singleFile) {
127
+ const combinedData = { ...numericData,
128
+ ...dynamicData
129
+ };
130
+
131
+ if (Object.keys(combinedData).length > 0) {
132
+ const filename = this.options.numericFilenameTemplate || this.options.dynamicFilenameTemplate;
133
+ this.emitChunk(compilation, filename, locale, combinedData);
134
+ }
135
+ } else {
136
+ if (Object.keys(numericData).length > 0) {
137
+ this.emitChunk(compilation, this.options.numericFilenameTemplate, locale, numericData, 'numeric');
138
+ }
139
+
140
+ if (Object.keys(dynamicData).length > 0) {
141
+ this.emitChunk(compilation, this.options.dynamicFilenameTemplate, locale, dynamicData, 'dynamic');
142
+ }
143
+ }
144
+ });
145
+
146
+ if (this.options.generateManifest && Object.keys(this.manifest).length > 0) {
147
+ const manifestPath = path.dirname(this.options.numericFilenameTemplate) + '/manifest.json';
148
+ const manifestContent = JSON.stringify(this.manifest, null, 2);
149
+ compilation.emitAsset(manifestPath, new RawSource(manifestContent));
150
+ }
151
+
152
+ callback();
153
+ });
154
+ });
155
+ }
156
+
157
+ }
158
+
159
+ module.exports = {
160
+ I18nNumericIndexPlugin
161
+ };