@zohodesk/client_build_tool 0.0.11-exp.22.0 → 0.0.11-exp.24.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/lib/shared/bundler/webpack/custom_plugins/I18nNumericIndexPlugin/I18nGroupRuntimeModule.js
CHANGED
|
@@ -39,6 +39,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
39
39
|
var chunkNameToGroup = ${JSON.stringify(chunkToGroup)};
|
|
40
40
|
var groupToChunkNames = ${JSON.stringify(groupToChunks)};
|
|
41
41
|
var cachedI18nBase;
|
|
42
|
+
var loadReasonKey = '__i18nGroupLoadReason';
|
|
42
43
|
|
|
43
44
|
function ensureTrailingSlash(path) {
|
|
44
45
|
if (!path) {
|
|
@@ -59,6 +60,34 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
59
60
|
return '';
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
function withLoadReason(reason, fn) {
|
|
64
|
+
var previous = __webpack_require__[loadReasonKey];
|
|
65
|
+
__webpack_require__[loadReasonKey] = reason;
|
|
66
|
+
try {
|
|
67
|
+
return fn();
|
|
68
|
+
} finally {
|
|
69
|
+
__webpack_require__[loadReasonKey] = previous;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (typeof __webpack_require__.pfc === 'function') {
|
|
74
|
+
var originalPrefetchChunk = __webpack_require__.pfc;
|
|
75
|
+
__webpack_require__.pfc = function(prefetchChunkId) {
|
|
76
|
+
return withLoadReason('prefetch', function() {
|
|
77
|
+
return originalPrefetchChunk(prefetchChunkId);
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (typeof __webpack_require__.plc === 'function') {
|
|
83
|
+
var originalPreloadChunk = __webpack_require__.plc;
|
|
84
|
+
__webpack_require__.plc = function(preloadChunkId) {
|
|
85
|
+
return withLoadReason('preload', function() {
|
|
86
|
+
return originalPreloadChunk(preloadChunkId);
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
62
91
|
function resolveI18nBase() {
|
|
63
92
|
if (cachedI18nBase !== undefined) {
|
|
64
93
|
return cachedI18nBase;
|
|
@@ -104,37 +133,47 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
104
133
|
}
|
|
105
134
|
|
|
106
135
|
// Function to load i18n group
|
|
107
|
-
function loadI18nGroup(groupName) {
|
|
136
|
+
function loadI18nGroup(groupName, loadReason) {
|
|
108
137
|
if (loadedGroups[groupName]) {
|
|
109
138
|
return Promise.resolve();
|
|
110
139
|
}
|
|
111
|
-
|
|
140
|
+
|
|
112
141
|
var locale = ${localeVarName} || 'en_US';
|
|
113
142
|
var groupConfig = ${JSON.stringify(customGroups)};
|
|
114
143
|
var config = groupConfig[groupName];
|
|
115
|
-
|
|
144
|
+
|
|
116
145
|
if (!config) {
|
|
117
146
|
return Promise.resolve();
|
|
118
147
|
}
|
|
119
|
-
|
|
148
|
+
|
|
149
|
+
var shouldSkip =
|
|
150
|
+
(loadReason === 'prefetch' && config.prefetch === false) ||
|
|
151
|
+
(loadReason === 'preload' && config.preload === false);
|
|
152
|
+
|
|
153
|
+
if (shouldSkip) {
|
|
154
|
+
if (typeof console !== 'undefined' && console.log) {
|
|
155
|
+
console.log('[i18n-group:skip]', groupName, loadReason, 'prefetch/preload disabled');
|
|
156
|
+
}
|
|
157
|
+
return Promise.resolve();
|
|
158
|
+
}
|
|
159
|
+
|
|
120
160
|
return new Promise(function(resolve, reject) {
|
|
121
161
|
var relativePath = config.filenameTemplate
|
|
122
162
|
.replace('[locale]', locale);
|
|
123
163
|
var i18nUrl = buildI18nUrl(relativePath);
|
|
124
164
|
|
|
125
165
|
if (typeof console !== 'undefined' && console.log) {
|
|
126
|
-
console.log('[i18n-group:load]', groupName, i18nUrl);
|
|
166
|
+
console.log('[i18n-group:load]', groupName, loadReason || 'require', i18nUrl);
|
|
127
167
|
}
|
|
128
168
|
|
|
129
|
-
|
|
130
169
|
var script = document.createElement('script');
|
|
131
170
|
script.src = i18nUrl;
|
|
132
171
|
script.async = true;
|
|
133
172
|
|
|
134
|
-
|
|
135
|
-
|
|
173
|
+
script.onload = function() {
|
|
174
|
+
loadedGroups[groupName] = true;
|
|
136
175
|
if (typeof console !== 'undefined' && console.log) {
|
|
137
|
-
console.log('[i18n-group:loaded]', groupName, i18nUrl);
|
|
176
|
+
console.log('[i18n-group:loaded]', groupName, loadReason || 'require', i18nUrl);
|
|
138
177
|
}
|
|
139
178
|
resolve();
|
|
140
179
|
};
|
|
@@ -149,6 +188,46 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
149
188
|
document.head.appendChild(script);
|
|
150
189
|
});
|
|
151
190
|
}
|
|
191
|
+
|
|
192
|
+
function toLower(str) {
|
|
193
|
+
return typeof str === 'string' ? str.toLowerCase() : str;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function findGroupByChunkId(chunkId) {
|
|
197
|
+
var directGroup = chunkNameToGroup[chunkId];
|
|
198
|
+
if (directGroup) {
|
|
199
|
+
return directGroup;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var stringId = '' + chunkId;
|
|
203
|
+
if (chunkNameToGroup[stringId]) {
|
|
204
|
+
return chunkNameToGroup[stringId];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (typeof __webpack_require__ !== 'undefined' && typeof __webpack_require__.u === 'function') {
|
|
208
|
+
var filename = __webpack_require__.u(chunkId) || '';
|
|
209
|
+
if (filename) {
|
|
210
|
+
var loweredFilename = toLower(filename);
|
|
211
|
+
for (var group in groupToChunkNames) {
|
|
212
|
+
if (!Object.prototype.hasOwnProperty.call(groupToChunkNames, group)) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
var chunkNames = groupToChunkNames[group] || [];
|
|
216
|
+
for (var i = 0; i < chunkNames.length; i++) {
|
|
217
|
+
var candidate = chunkNames[i];
|
|
218
|
+
if (candidate && loweredFilename.indexOf(toLower(candidate)) !== -1) {
|
|
219
|
+
if (typeof console !== 'undefined' && console.log) {
|
|
220
|
+
console.log('[i18n-group:match-by-filename]', chunkId, filename, 'matched', candidate, '→', group);
|
|
221
|
+
}
|
|
222
|
+
return group;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
152
231
|
|
|
153
232
|
// Store original webpack chunk loading function
|
|
154
233
|
var originalEnsureChunk = __webpack_require__.e;
|
|
@@ -157,21 +236,25 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
157
236
|
if (originalEnsureChunk) {
|
|
158
237
|
__webpack_require__.e = function(chunkId) {
|
|
159
238
|
var promise = originalEnsureChunk.apply(this, arguments);
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
239
|
+
|
|
240
|
+
// Check if this chunk needs an i18n group
|
|
241
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
242
|
+
if (groupName && !loadedGroups[groupName]) {
|
|
243
|
+
if (typeof console !== 'undefined' && console.log) {
|
|
244
|
+
var chunkFilename = typeof __webpack_require__ !== 'undefined' && typeof __webpack_require__.u === 'function'
|
|
245
|
+
? __webpack_require__.u(chunkId)
|
|
246
|
+
: '<no __webpack_require__.u>';
|
|
247
|
+
console.log('[i18n-group:hook]', chunkId, '→', groupName, '| reason:', (__webpack_require__[loadReasonKey] || 'require'), '| file:', chunkFilename);
|
|
248
|
+
}
|
|
249
|
+
// Load the i18n group before the chunk
|
|
250
|
+
var loadReason = __webpack_require__[loadReasonKey] || 'require';
|
|
251
|
+
var i18nPromise = loadI18nGroup(groupName, loadReason);
|
|
252
|
+
// Chain the promises so i18n loads first
|
|
253
|
+
promise = Promise.all([promise, i18nPromise]).then(function(results) {
|
|
254
|
+
return results[0]; // Return the original chunk promise result
|
|
255
|
+
});
|
|
166
256
|
}
|
|
167
|
-
|
|
168
|
-
var i18nPromise = loadI18nGroup(groupName);
|
|
169
|
-
// Chain the promises so i18n loads first
|
|
170
|
-
promise = Promise.all([promise, i18nPromise]).then(function(results) {
|
|
171
|
-
return results[0]; // Return the original chunk promise result
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
|
|
257
|
+
|
|
175
258
|
return promise;
|
|
176
259
|
};
|
|
177
260
|
}
|
|
@@ -190,6 +273,13 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
190
273
|
.replace('[locale]', locale);
|
|
191
274
|
var i18nUrl = buildI18nUrl(relativePath);
|
|
192
275
|
|
|
276
|
+
if (config.prefetch === false) {
|
|
277
|
+
if (typeof console !== 'undefined' && console.log) {
|
|
278
|
+
console.log('[i18n-group:skip-prefetch-loader]', groupName, chunkId, i18nUrl);
|
|
279
|
+
}
|
|
280
|
+
return originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
281
|
+
}
|
|
282
|
+
|
|
193
283
|
var i18nScript = document.createElement('script');
|
|
194
284
|
i18nScript.src = i18nUrl;
|
|
195
285
|
i18nScript.onload = function() {
|
|
@@ -212,6 +302,20 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
212
302
|
}
|
|
213
303
|
|
|
214
304
|
function installLoadScriptHook(loadScript) {
|
|
305
|
+
if (typeof loadScript !== 'function') {
|
|
306
|
+
Object.defineProperty(__webpack_require__, 'l', {
|
|
307
|
+
configurable: true,
|
|
308
|
+
enumerable: true,
|
|
309
|
+
get: function() {
|
|
310
|
+
return loadScript;
|
|
311
|
+
},
|
|
312
|
+
set: function(newLoader) {
|
|
313
|
+
installLoadScriptHook(newLoader);
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
|
|
215
319
|
Object.defineProperty(__webpack_require__, 'l', {
|
|
216
320
|
configurable: true,
|
|
217
321
|
enumerable: true,
|
|
@@ -240,48 +344,4 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
240
344
|
|
|
241
345
|
}
|
|
242
346
|
|
|
243
|
-
exports.I18nGroupRuntimeModule = I18nGroupRuntimeModule;
|
|
244
|
-
|
|
245
|
-
function toLower(str) {
|
|
246
|
-
return typeof str === 'string' ? str.toLowerCase() : str;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function findGroupByChunkId(chunkId) {
|
|
250
|
-
var directGroup = chunkNameToGroup[chunkId];
|
|
251
|
-
|
|
252
|
-
if (directGroup) {
|
|
253
|
-
return directGroup;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
var stringId = '' + chunkId;
|
|
257
|
-
|
|
258
|
-
if (chunkNameToGroup[stringId]) {
|
|
259
|
-
return chunkNameToGroup[stringId];
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (typeof __webpack_require__ !== 'undefined' && typeof __webpack_require__.u === 'function') {
|
|
263
|
-
var filename = __webpack_require__.u(chunkId) || '';
|
|
264
|
-
|
|
265
|
-
if (filename) {
|
|
266
|
-
var loweredFilename = toLower(filename);
|
|
267
|
-
|
|
268
|
-
for (var group in groupToChunkNames) {
|
|
269
|
-
if (!Object.prototype.hasOwnProperty.call(groupToChunkNames, group)) {
|
|
270
|
-
continue;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
var chunkNames = groupToChunkNames[group] || [];
|
|
274
|
-
|
|
275
|
-
for (var i = 0; i < chunkNames.length; i++) {
|
|
276
|
-
var candidate = chunkNames[i];
|
|
277
|
-
|
|
278
|
-
if (candidate && loweredFilename.indexOf(toLower(candidate)) !== -1) {
|
|
279
|
-
return group;
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
return undefined;
|
|
287
|
-
}
|
|
347
|
+
exports.I18nGroupRuntimeModule = I18nGroupRuntimeModule;
|
|
@@ -15,18 +15,18 @@ var _configCSSMinifierPlugin = require("./pluginConfigs/configCSSMinifierPlugin"
|
|
|
15
15
|
|
|
16
16
|
var _splitChunksConfig = require("./splitChunksConfig");
|
|
17
17
|
|
|
18
|
-
var _modeUtils = require("./common/modeUtils");
|
|
19
|
-
|
|
20
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
19
|
|
|
22
20
|
function optimizationConfig(options) {
|
|
23
21
|
const {
|
|
24
|
-
changeRuntimeChunkChar
|
|
25
|
-
mode
|
|
22
|
+
changeRuntimeChunkChar
|
|
26
23
|
} = options;
|
|
27
24
|
const {
|
|
28
25
|
chunkSplitEnable
|
|
29
|
-
} = options.i18nChunkSplit;
|
|
26
|
+
} = options.i18nChunkSplit; // TEMP: Test console logs for minification verification
|
|
27
|
+
|
|
28
|
+
console.log('MINIFY_TEST: optimizationConfig called in mode:', options.mode);
|
|
29
|
+
console.log('MINIFY_TEST: TerserPlugin and CSS minification active');
|
|
30
30
|
const i18nChunkFilename = (0, _nameTemplates.nameTemplates)('i18njs', options);
|
|
31
31
|
const chunkFilenameHasContentHash = (0, _hashUtils.hasContentHash)(i18nChunkFilename);
|
|
32
32
|
/**
|
|
@@ -38,26 +38,19 @@ function optimizationConfig(options) {
|
|
|
38
38
|
const suffix = // chunkSplitEnable ? '_[locale]' : '';
|
|
39
39
|
chunkSplitEnable && chunkFilenameHasContentHash ? '_[locale]' : '';
|
|
40
40
|
const char = changeRuntimeChunkChar;
|
|
41
|
-
const excludeList = options.optimization.jsExcludePath;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
minimizers.push(excludeList !== '' ? new _terserWebpackPlugin.default({
|
|
41
|
+
const excludeList = options.optimization.jsExcludePath;
|
|
42
|
+
return {
|
|
43
|
+
splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
|
|
44
|
+
minimizer: [// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
|
|
45
|
+
// '...',
|
|
46
|
+
excludeList !== '' ? new _terserWebpackPlugin.default({
|
|
48
47
|
exclude: excludeList,
|
|
49
48
|
extractComments: false // Do not extract comments to .LICENSE.txt files
|
|
50
49
|
|
|
51
50
|
}) : new _terserWebpackPlugin.default({
|
|
52
51
|
extractComments: false // Do not extract comments to .LICENSE.txt files
|
|
53
52
|
|
|
54
|
-
}))
|
|
55
|
-
minimizers.push((0, _configCSSMinifierPlugin.configCSSMinifierPlugin)(options));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
|
|
60
|
-
minimizer: minimizers.filter(Boolean),
|
|
53
|
+
}), (0, _configCSSMinifierPlugin.configCSSMinifierPlugin)(options)].filter(Boolean),
|
|
61
54
|
moduleIds: 'named',
|
|
62
55
|
runtimeChunk: {
|
|
63
56
|
name: entrypoint => `runtime${char}${entrypoint.name}${suffix}`
|
|
@@ -55,6 +55,9 @@ var _configCustomScriptLoadingStrategyPlugin = require("./pluginConfigs/configCu
|
|
|
55
55
|
function plugins(options) {
|
|
56
56
|
const {
|
|
57
57
|
webpackPlugins
|
|
58
|
-
} = options;
|
|
58
|
+
} = options; // TEMP: Test console logs for minification verification
|
|
59
|
+
|
|
60
|
+
console.log('MINIFY_TEST: plugins function called with options:', options.mode);
|
|
61
|
+
console.log('MINIFY_TEST: This message should be visible if minification is disabled');
|
|
59
62
|
return [(0, _configEnvVariables.configEnvVariables)(options), (0, _configCustomAttributesPlugin.configCustomAttributesPlugin)(options), (0, _configTPHashMappingPlugin.configTPHashMappingPlugin)(options), (0, _configCopyPublicFolders.configCopyPublicFolders)(options), (0, _configIgnorePlugin.configIgnorePlugin)(options), (0, _configMiniCSSExtractPlugin.configMiniCSSExtractPlugin)(options), (0, _configSelectorWeightPlugin.configSelectorWeightPlugin)(options), (0, _configVariableConversionPlugin.configVariableConversionPlugin)(options), (0, _configI18nSplitPlugin.configI18nSplitPlugin)(options), ...((0, _configI18nNumericIndexPlugin.configI18nNumericIndexPlugin)(options) || []), (0, _configRtlCssPlugin.configRtlCssPlugin)(options), (0, _configHtmlWebpackPlugin.configHtmlWebpackPlugin)(options), (0, _configCustomScriptLoadingStrategyPlugin.configCustomScriptLoadingStrategyPlugin)(options), (0, _configCdnChangePlugin.configCdnChangePlugin)(options), (0, _configServiceWorkerPlugin.configServiceWorkerPlugin)(options), (0, _configEFCTemplatePlugin.configEFCTemplatePlugin)(options), (0, _configResourceHintsPlugin.configResourceHintsPlugin)(options), (0, _configBundleAnalyzer.configBundleAnalyzer)(options), (0, _configManifestJsonPlugin.configManifestJsonPlugin)(options), (0, _configSourceMapPlugin.configSourceMapPlugin)(options), (0, _configProgressPlugin.configProgressPlugin)(options), (0, _configBundleIntegrityReport.configBundleIntegrityReport)(options), (0, _configRuntimeResourceCleanup.configRuntimeResourceCleanup)(options), ...webpackPlugins].filter(Boolean);
|
|
60
63
|
}
|