@zohodesk/client_build_tool 0.0.11-exp.21.0 → 0.0.11-exp.22.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
|
@@ -24,8 +24,11 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
24
24
|
} = this.options; // Build chunk-to-group mapping from config
|
|
25
25
|
|
|
26
26
|
const chunkToGroup = {};
|
|
27
|
+
const groupToChunks = {};
|
|
27
28
|
Object.entries(customGroups || {}).forEach(([groupName, config]) => {
|
|
28
|
-
|
|
29
|
+
const chunkNames = config.chunks || [];
|
|
30
|
+
groupToChunks[groupName] = chunkNames;
|
|
31
|
+
chunkNames.forEach(chunkName => {
|
|
29
32
|
chunkToGroup[chunkName] = groupName;
|
|
30
33
|
});
|
|
31
34
|
});
|
|
@@ -33,7 +36,8 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
33
36
|
// I18n Group Loading Runtime
|
|
34
37
|
(function() {
|
|
35
38
|
var loadedGroups = {};
|
|
36
|
-
var
|
|
39
|
+
var chunkNameToGroup = ${JSON.stringify(chunkToGroup)};
|
|
40
|
+
var groupToChunkNames = ${JSON.stringify(groupToChunks)};
|
|
37
41
|
var cachedI18nBase;
|
|
38
42
|
|
|
39
43
|
function ensureTrailingSlash(path) {
|
|
@@ -155,7 +159,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
155
159
|
var promise = originalEnsureChunk.apply(this, arguments);
|
|
156
160
|
|
|
157
161
|
// Check if this chunk needs an i18n group
|
|
158
|
-
var groupName =
|
|
162
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
159
163
|
if (groupName && !loadedGroups[groupName]) {
|
|
160
164
|
if (typeof console !== 'undefined' && console.log) {
|
|
161
165
|
console.log('[i18n-group:hook]', chunkId, '→', groupName);
|
|
@@ -175,7 +179,7 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
175
179
|
// Also check for webpackI18nGroup comments in dynamic imports
|
|
176
180
|
function wrapLoadScript(originalLoadScript) {
|
|
177
181
|
return function(url, done, key, chunkId) {
|
|
178
|
-
var groupName =
|
|
182
|
+
var groupName = findGroupByChunkId(chunkId);
|
|
179
183
|
if (groupName && !loadedGroups[groupName]) {
|
|
180
184
|
var locale = ${localeVarName} || 'en_US';
|
|
181
185
|
var groupConfig = ${JSON.stringify(customGroups)};
|
|
@@ -186,17 +190,10 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
186
190
|
.replace('[locale]', locale);
|
|
187
191
|
var i18nUrl = buildI18nUrl(relativePath);
|
|
188
192
|
|
|
189
|
-
if (typeof console !== 'undefined' && console.log) {
|
|
190
|
-
console.log('[i18n-group:preload]', groupName, i18nUrl);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
193
|
var i18nScript = document.createElement('script');
|
|
194
194
|
i18nScript.src = i18nUrl;
|
|
195
195
|
i18nScript.onload = function() {
|
|
196
196
|
loadedGroups[groupName] = true;
|
|
197
|
-
if (typeof console !== 'undefined' && console.log) {
|
|
198
|
-
console.log('[i18n-group:loaded]', groupName, i18nUrl);
|
|
199
|
-
}
|
|
200
197
|
originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
|
|
201
198
|
};
|
|
202
199
|
i18nScript.onerror = function() {
|
|
@@ -243,4 +240,48 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
|
|
|
243
240
|
|
|
244
241
|
}
|
|
245
242
|
|
|
246
|
-
exports.I18nGroupRuntimeModule = I18nGroupRuntimeModule;
|
|
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
|
+
}
|
|
@@ -15,11 +15,14 @@ var _configCSSMinifierPlugin = require("./pluginConfigs/configCSSMinifierPlugin"
|
|
|
15
15
|
|
|
16
16
|
var _splitChunksConfig = require("./splitChunksConfig");
|
|
17
17
|
|
|
18
|
+
var _modeUtils = require("./common/modeUtils");
|
|
19
|
+
|
|
18
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
21
|
|
|
20
22
|
function optimizationConfig(options) {
|
|
21
23
|
const {
|
|
22
|
-
changeRuntimeChunkChar
|
|
24
|
+
changeRuntimeChunkChar,
|
|
25
|
+
mode
|
|
23
26
|
} = options;
|
|
24
27
|
const {
|
|
25
28
|
chunkSplitEnable
|
|
@@ -35,19 +38,26 @@ function optimizationConfig(options) {
|
|
|
35
38
|
const suffix = // chunkSplitEnable ? '_[locale]' : '';
|
|
36
39
|
chunkSplitEnable && chunkFilenameHasContentHash ? '_[locale]' : '';
|
|
37
40
|
const char = changeRuntimeChunkChar;
|
|
38
|
-
const excludeList = options.optimization.jsExcludePath;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const excludeList = options.optimization.jsExcludePath; // TEMP: Disable minification in production mode for testing
|
|
42
|
+
|
|
43
|
+
const shouldMinify = !(0, _modeUtils.isProductionMode)(mode);
|
|
44
|
+
const minimizers = [];
|
|
45
|
+
|
|
46
|
+
if (shouldMinify) {
|
|
47
|
+
minimizers.push(excludeList !== '' ? new _terserWebpackPlugin.default({
|
|
44
48
|
exclude: excludeList,
|
|
45
49
|
extractComments: false // Do not extract comments to .LICENSE.txt files
|
|
46
50
|
|
|
47
51
|
}) : new _terserWebpackPlugin.default({
|
|
48
52
|
extractComments: false // Do not extract comments to .LICENSE.txt files
|
|
49
53
|
|
|
50
|
-
})
|
|
54
|
+
}));
|
|
55
|
+
minimizers.push((0, _configCSSMinifierPlugin.configCSSMinifierPlugin)(options));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
|
|
60
|
+
minimizer: minimizers.filter(Boolean),
|
|
51
61
|
moduleIds: 'named',
|
|
52
62
|
runtimeChunk: {
|
|
53
63
|
name: entrypoint => `runtime${char}${entrypoint.name}${suffix}`
|