@zohodesk/client_build_tool 0.0.11-exp.20.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.
@@ -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
- (config.chunks || []).forEach(chunkName => {
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 chunkToGroup = ${JSON.stringify(chunkToGroup)};
39
+ var chunkNameToGroup = ${JSON.stringify(chunkToGroup)};
40
+ var groupToChunkNames = ${JSON.stringify(groupToChunks)};
37
41
  var cachedI18nBase;
38
42
 
39
43
  function ensureTrailingSlash(path) {
@@ -82,6 +86,9 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
82
86
  }
83
87
 
84
88
  cachedI18nBase = ensureTrailingSlash(base);
89
+ if (typeof console !== 'undefined' && console.log) {
90
+ console.log('[i18n-group:base]', cachedI18nBase || '<empty>');
91
+ }
85
92
  return cachedI18nBase;
86
93
  }
87
94
 
@@ -124,12 +131,18 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
124
131
  script.src = i18nUrl;
125
132
  script.async = true;
126
133
 
127
- script.onload = function() {
128
- loadedGroups[groupName] = true;
134
+ script.onload = function() {
135
+ loadedGroups[groupName] = true;
136
+ if (typeof console !== 'undefined' && console.log) {
137
+ console.log('[i18n-group:loaded]', groupName, i18nUrl);
138
+ }
129
139
  resolve();
130
140
  };
131
-
141
+
132
142
  script.onerror = function() {
143
+ if (typeof console !== 'undefined' && console.error) {
144
+ console.error('[i18n-group:error]', groupName, i18nUrl);
145
+ }
133
146
  reject(new Error('Failed to load i18n group: ' + groupName));
134
147
  };
135
148
 
@@ -146,8 +159,11 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
146
159
  var promise = originalEnsureChunk.apply(this, arguments);
147
160
 
148
161
  // Check if this chunk needs an i18n group
149
- var groupName = chunkToGroup[chunkId];
162
+ var groupName = findGroupByChunkId(chunkId);
150
163
  if (groupName && !loadedGroups[groupName]) {
164
+ if (typeof console !== 'undefined' && console.log) {
165
+ console.log('[i18n-group:hook]', chunkId, '→', groupName);
166
+ }
151
167
  // Load the i18n group before the chunk
152
168
  var i18nPromise = loadI18nGroup(groupName);
153
169
  // Chain the promises so i18n loads first
@@ -161,51 +177,111 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
161
177
  }
162
178
 
163
179
  // Also check for webpackI18nGroup comments in dynamic imports
164
- if (typeof __webpack_require__.l !== 'undefined') {
165
- var originalLoadScript = __webpack_require__.l;
166
- __webpack_require__.l = function(url, done, key, chunkId) {
167
- // Check if chunk has i18n group
168
- var groupName = chunkToGroup[chunkId];
180
+ function wrapLoadScript(originalLoadScript) {
181
+ return function(url, done, key, chunkId) {
182
+ var groupName = findGroupByChunkId(chunkId);
169
183
  if (groupName && !loadedGroups[groupName]) {
170
- // Load i18n before main chunk
171
184
  var locale = ${localeVarName} || 'en_US';
172
185
  var groupConfig = ${JSON.stringify(customGroups)};
173
186
  var config = groupConfig[groupName];
174
-
187
+
175
188
  if (config) {
176
189
  var relativePath = config.filenameTemplate
177
190
  .replace('[locale]', locale);
178
191
  var i18nUrl = buildI18nUrl(relativePath);
179
192
 
180
- if (typeof console !== 'undefined' && console.log) {
181
- console.log('[i18n-group:preload]', groupName, i18nUrl);
182
- }
183
-
184
- // Load i18n first, then the chunk
185
193
  var i18nScript = document.createElement('script');
186
194
  i18nScript.src = i18nUrl;
187
195
  i18nScript.onload = function() {
188
196
  loadedGroups[groupName] = true;
189
- // Now load the original chunk
190
197
  originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
191
198
  };
192
199
  i18nScript.onerror = function() {
193
- // Continue even if i18n fails
200
+ if (typeof console !== 'undefined' && console.error) {
201
+ console.error('[i18n-group:error]', groupName, i18nUrl);
202
+ }
194
203
  originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
195
204
  };
196
205
  document.head.appendChild(i18nScript);
197
206
  return;
198
207
  }
199
208
  }
200
-
201
- // Default behavior
209
+
202
210
  return originalLoadScript.call(__webpack_require__, url, done, key, chunkId);
203
211
  };
204
212
  }
213
+
214
+ function installLoadScriptHook(loadScript) {
215
+ Object.defineProperty(__webpack_require__, 'l', {
216
+ configurable: true,
217
+ enumerable: true,
218
+ writable: true,
219
+ value: wrapLoadScript(loadScript)
220
+ });
221
+ }
222
+
223
+ if (typeof __webpack_require__.l === 'function') {
224
+ installLoadScriptHook(__webpack_require__.l);
225
+ } else {
226
+ Object.defineProperty(__webpack_require__, 'l', {
227
+ configurable: true,
228
+ enumerable: true,
229
+ set: function(newLoader) {
230
+ installLoadScriptHook(newLoader);
231
+ },
232
+ get: function() {
233
+ return undefined;
234
+ }
235
+ });
236
+ }
205
237
  })();
206
238
  `;
207
239
  }
208
240
 
209
241
  }
210
242
 
211
- 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
+ }
@@ -52,7 +52,8 @@ class I18nNumericIndexPlugin {
52
52
  compilation.addRuntimeModule(chunk, new _I18nGroupRuntimeModule.I18nGroupRuntimeModule({
53
53
  customGroups: this.options.customGroups,
54
54
  localeVarName: this.options.localeVarName,
55
- jsonpFunc: this.options.jsonpFunc
55
+ jsonpFunc: this.options.jsonpFunc,
56
+ i18nPublicPathVar: this.options.i18nPublicPathVar
56
57
  }));
57
58
  }
58
59
  });
@@ -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
- return {
40
- splitChunks: (0, _splitChunksConfig.splitChunksConfig)(options),
41
- minimizer: [// For webpack@5 you can use the `...` syntax to extend existing minimizers (i.e. `terser-webpack-plugin`), uncomment the next line
42
- // '...',
43
- excludeList !== '' ? new _terserWebpackPlugin.default({
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
- }), (0, _configCSSMinifierPlugin.configCSSMinifierPlugin)(options)].filter(Boolean),
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}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.11-exp.20.0",
3
+ "version": "0.0.11-exp.22.0",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {