@zohodesk/client_build_tool 0.0.11-exp.18.0 → 0.0.11-exp.19.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.
@@ -10,14 +10,18 @@ var _webpack = require("webpack");
10
10
  class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
11
11
  constructor(options) {
12
12
  super('i18n-group-loader');
13
- this.options = options;
13
+ this.options = {
14
+ i18nPublicPathVar: 'window.__I18N_CDN__',
15
+ ...options
16
+ };
14
17
  }
15
18
 
16
19
  generate() {
17
20
  const {
18
21
  customGroups,
19
22
  localeVarName,
20
- jsonpFunc
23
+ jsonpFunc,
24
+ i18nPublicPathVar
21
25
  } = this.options; // Build chunk-to-group mapping from config
22
26
 
23
27
  const chunkToGroup = {};
@@ -31,6 +35,64 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
31
35
  (function() {
32
36
  var loadedGroups = {};
33
37
  var chunkToGroup = ${JSON.stringify(chunkToGroup)};
38
+ var cachedI18nBase;
39
+
40
+ function ensureTrailingSlash(path) {
41
+ if (!path) {
42
+ return '';
43
+ }
44
+ return path.charAt(path.length - 1) === '/' ? path : path + '/';
45
+ }
46
+
47
+ function resolveConfiguredBase() {
48
+ try {
49
+ var candidate = (${i18nPublicPathVar});
50
+ if (typeof candidate === 'string' && candidate.length) {
51
+ return candidate;
52
+ }
53
+ } catch (err) {
54
+ // ignore – fall back to DOM/publicPath detection
55
+ }
56
+ return '';
57
+ }
58
+
59
+ function resolveI18nBase() {
60
+ if (cachedI18nBase !== undefined) {
61
+ return cachedI18nBase;
62
+ }
63
+
64
+ var base = resolveConfiguredBase();
65
+
66
+ if (!base && typeof document !== 'undefined') {
67
+ var scripts = document.getElementsByTagName('script');
68
+ for (var i = 0; i < scripts.length; i++) {
69
+ var src = scripts[i].getAttribute('data-src') || scripts[i].getAttribute('src') || '';
70
+ var markerIndex = src.indexOf('i18n-chunk/');
71
+ if (markerIndex !== -1) {
72
+ base = src.slice(0, markerIndex);
73
+ break;
74
+ }
75
+ }
76
+ }
77
+
78
+ if (!base) {
79
+ base = __webpack_require__.p || '';
80
+ }
81
+
82
+ cachedI18nBase = ensureTrailingSlash(base);
83
+ return cachedI18nBase;
84
+ }
85
+
86
+ function buildI18nUrl(relativePath) {
87
+ var base = resolveI18nBase();
88
+ if (!relativePath) {
89
+ return base;
90
+ }
91
+ if (relativePath.charAt(0) === '/') {
92
+ relativePath = relativePath.slice(1);
93
+ }
94
+ return base + relativePath;
95
+ }
34
96
 
35
97
  // Function to load i18n group
36
98
  function loadI18nGroup(groupName) {
@@ -47,10 +109,14 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
47
109
  }
48
110
 
49
111
  return new Promise(function(resolve, reject) {
50
- var i18nUrl = config.filenameTemplate
51
- .replace('[locale]', locale)
52
- .replace('i18n-chunk/', __webpack_require__.p + 'i18n-chunk/');
53
-
112
+ var relativePath = config.filenameTemplate
113
+ .replace('[locale]', locale);
114
+ var i18nUrl = buildI18nUrl(relativePath);
115
+
116
+ if (typeof console !== 'undefined' && console.debug) {
117
+ console.debug('[i18n-group:load]', groupName, i18nUrl);
118
+ }
119
+
54
120
 
55
121
  var script = document.createElement('script');
56
122
  script.src = i18nUrl;
@@ -105,9 +171,13 @@ class I18nGroupRuntimeModule extends _webpack.RuntimeModule {
105
171
  var config = groupConfig[groupName];
106
172
 
107
173
  if (config) {
108
- var i18nUrl = config.filenameTemplate
109
- .replace('[locale]', locale)
110
- .replace('i18n-chunk/', __webpack_require__.p + 'i18n-chunk/');
174
+ var relativePath = config.filenameTemplate
175
+ .replace('[locale]', locale);
176
+ var i18nUrl = buildI18nUrl(relativePath);
177
+
178
+ if (typeof console !== 'undefined' && console.debug) {
179
+ console.debug('[i18n-group:preload]', groupName, i18nUrl);
180
+ }
111
181
 
112
182
  // Load i18n first, then the chunk
113
183
  var i18nScript = document.createElement('script');
@@ -91,7 +91,8 @@ function configI18nNumericIndexPlugin(options) {
91
91
  manifestPath: i18nOpts.manifestPath || null,
92
92
  customGroups: i18nOpts.customGroups || null,
93
93
  emitFiles: i18nOpts.emitFiles !== undefined ? i18nOpts.emitFiles : true,
94
- isDevelopment: isDevelopment
94
+ isDevelopment: isDevelopment,
95
+ i18nPublicPathVar: i18nOpts.i18nPublicPathVar
95
96
  }; // HTML injector options
96
97
 
97
98
  const htmlInjectorOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/client_build_tool",
3
- "version": "0.0.11-exp.18.0",
3
+ "version": "0.0.11-exp.19.0",
4
4
  "description": "A CLI tool to build web applications and client libraries",
5
5
  "main": "lib/index.js",
6
6
  "bin": {