@module-federation/nextjs-mf 8.8.55 → 8.8.57

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 (143) hide show
  1. package/dist/LICENSE +21 -0
  2. package/dist/_virtual/_rolldown/runtime.js +29 -0
  3. package/dist/_virtual/_rolldown/runtime.mjs +8 -0
  4. package/dist/client/UrlNode.js +89 -147
  5. package/dist/client/UrlNode.js.map +1 -1
  6. package/dist/client/UrlNode.mjs +91 -0
  7. package/dist/client/UrlNode.mjs.map +1 -0
  8. package/dist/src/federation-noop.d.mts +1 -0
  9. package/dist/src/federation-noop.d.ts +1 -0
  10. package/dist/src/federation-noop.js +17 -0
  11. package/dist/src/federation-noop.js.map +1 -1
  12. package/dist/src/federation-noop.mjs +23 -0
  13. package/dist/src/federation-noop.mjs.map +1 -0
  14. package/dist/src/index.d.mts +2 -0
  15. package/dist/src/index.d.ts +2 -3
  16. package/dist/src/index.js +13 -11
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/index.mjs +8 -0
  19. package/dist/src/index.mjs.map +1 -0
  20. package/dist/src/internal.js +140 -243
  21. package/dist/src/internal.js.map +1 -1
  22. package/dist/src/internal.mjs +152 -0
  23. package/dist/src/internal.mjs.map +1 -0
  24. package/dist/src/loaders/fixImageLoader.d.mts +27 -0
  25. package/dist/src/loaders/fixImageLoader.d.ts +8 -3
  26. package/dist/src/loaders/fixImageLoader.js +91 -103
  27. package/dist/src/loaders/fixImageLoader.js.map +1 -1
  28. package/dist/src/loaders/fixImageLoader.mjs +101 -0
  29. package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
  30. package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
  31. package/dist/src/loaders/fixUrlLoader.d.ts +5 -2
  32. package/dist/src/loaders/fixUrlLoader.js +17 -19
  33. package/dist/src/loaders/fixUrlLoader.js.map +1 -1
  34. package/dist/src/loaders/fixUrlLoader.mjs +19 -0
  35. package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
  36. package/dist/src/loaders/helpers.js +72 -124
  37. package/dist/src/loaders/helpers.js.map +1 -1
  38. package/dist/src/loaders/helpers.mjs +79 -0
  39. package/dist/src/loaders/helpers.mjs.map +1 -0
  40. package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
  41. package/dist/src/loaders/nextPageMapLoader.d.ts +10 -5
  42. package/dist/src/loaders/nextPageMapLoader.js +126 -144
  43. package/dist/src/loaders/nextPageMapLoader.js.map +1 -1
  44. package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
  45. package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
  46. package/dist/src/logger.js +7 -7
  47. package/dist/src/logger.js.map +1 -1
  48. package/dist/src/logger.mjs +8 -0
  49. package/dist/src/logger.mjs.map +1 -0
  50. package/dist/src/plugins/CopyFederationPlugin.js +64 -71
  51. package/dist/src/plugins/CopyFederationPlugin.js.map +1 -1
  52. package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
  53. package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
  54. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +36 -53
  55. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
  56. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
  57. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
  58. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +103 -121
  59. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
  60. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
  61. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
  62. package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
  63. package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -23
  64. package/dist/src/plugins/NextFederationPlugin/index.js +147 -181
  65. package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
  66. package/dist/src/plugins/NextFederationPlugin/index.mjs +150 -0
  67. package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
  68. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
  69. package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +16 -18
  70. package/dist/src/plugins/NextFederationPlugin/next-fragments.js +62 -92
  71. package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
  72. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +68 -0
  73. package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
  74. package/dist/src/plugins/NextFederationPlugin/set-options.js +17 -19
  75. package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
  76. package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
  77. package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
  78. package/dist/src/plugins/NextFederationPlugin/validate-options.js +30 -38
  79. package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
  80. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
  81. package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
  82. package/dist/src/plugins/container/InvertedContainerPlugin.js +22 -25
  83. package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
  84. package/dist/src/plugins/container/InvertedContainerPlugin.mjs +23 -0
  85. package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
  86. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +55 -67
  87. package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
  88. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
  89. package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
  90. package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
  91. package/dist/src/plugins/container/runtimePlugin.d.ts +6 -2
  92. package/dist/src/plugins/container/runtimePlugin.js +167 -0
  93. package/dist/src/plugins/container/runtimePlugin.js.map +1 -1
  94. package/dist/src/plugins/container/runtimePlugin.mjs +166 -0
  95. package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
  96. package/dist/utils/flushedChunks.d.mts +29 -0
  97. package/dist/utils/flushedChunks.d.ts +12 -5
  98. package/dist/utils/flushedChunks.js +32 -72
  99. package/dist/utils/flushedChunks.js.map +1 -1
  100. package/dist/utils/flushedChunks.mjs +35 -0
  101. package/dist/utils/flushedChunks.mjs.map +1 -0
  102. package/dist/utils/index.d.mts +14 -0
  103. package/dist/utils/index.d.ts +8 -14
  104. package/dist/utils/index.js +27 -62
  105. package/dist/utils/index.js.map +1 -1
  106. package/dist/utils/index.mjs +22 -0
  107. package/dist/utils/index.mjs.map +1 -0
  108. package/package.json +29 -9
  109. package/dist/client/UrlNode.d.ts +0 -17
  110. package/dist/node.d.ts +0 -1
  111. package/dist/node.js +0 -18
  112. package/dist/node.js.map +0 -1
  113. package/dist/package.json +0 -80
  114. package/dist/src/federation-noop.cjs +0 -15
  115. package/dist/src/internal.d.ts +0 -50
  116. package/dist/src/loaders/helpers.d.ts +0 -17
  117. package/dist/src/logger.d.ts +0 -2
  118. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +0 -5
  119. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +0 -19
  120. package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +0 -1
  121. package/dist/src/plugins/CopyFederationPlugin.d.ts +0 -20
  122. package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +0 -23
  123. package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +0 -36
  124. package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +0 -14
  125. package/dist/src/plugins/NextFederationPlugin/regex-equal.js +0 -25
  126. package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +0 -1
  127. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +0 -8
  128. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +0 -34
  129. package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +0 -1
  130. package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +0 -16
  131. package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +0 -25
  132. package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +0 -5
  133. package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +0 -11
  134. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +0 -39
  135. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +0 -78
  136. package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +0 -1
  137. package/dist/src/plugins/container/runtimePlugin.cjs +0 -219
  138. package/dist/src/plugins/container/types.d.ts +0 -2
  139. package/dist/src/plugins/container/types.js +0 -3
  140. package/dist/src/plugins/container/types.js.map +0 -1
  141. package/dist/src/types.d.ts +0 -28
  142. package/dist/src/types.js +0 -3
  143. package/dist/src/types.js.map +0 -1
@@ -1,4 +1,6 @@
1
- import type { LoaderContext } from 'webpack';
1
+ import { LoaderContext } from "webpack";
2
+
3
+ //#region src/loaders/fixImageLoader.d.ts
2
4
  /**
3
5
  * This loader is specifically created for tuning the next-image-loader result.
4
6
  * It modifies the regular string output of the next-image-loader.
@@ -15,8 +17,11 @@ import type { LoaderContext } from 'webpack';
15
17
  * @param {string} remaining - The remaining part of the resource path.
16
18
  * @returns {string} The modified source code with the injected code.
17
19
  */
18
- export declare function fixImageLoader(this: LoaderContext<Record<string, unknown>>, remaining: string): Promise<string>;
20
+ declare function fixImageLoader(this: LoaderContext<Record<string, unknown>>, remaining: string): Promise<string>;
19
21
  /**
20
22
  * The pitch function of the loader, which is the same as the fixImageLoader function.
21
23
  */
22
- export declare const pitch: typeof fixImageLoader;
24
+ declare const pitch: typeof fixImageLoader;
25
+ //#endregion
26
+ export { fixImageLoader, pitch };
27
+ //# sourceMappingURL=fixImageLoader.d.ts.map
@@ -1,46 +1,42 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.pitch = void 0;
7
- exports.fixImageLoader = fixImageLoader;
8
- const normalize_webpack_path_1 = require("@module-federation/sdk/normalize-webpack-path");
9
- const { Template } = require((0, normalize_webpack_path_1.normalizeWebpackPath)('webpack'));
10
- const path_1 = __importDefault(require("path"));
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_runtime = require('../../_virtual/_rolldown/runtime.js');
3
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
4
+ let path = require("path");
5
+ path = require_runtime.__toESM(path);
6
+
7
+ //#region src/loaders/fixImageLoader.ts
8
+ const { Template } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
11
9
  /**
12
- * This loader is specifically created for tuning the next-image-loader result.
13
- * It modifies the regular string output of the next-image-loader.
14
- * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
15
- * For client-side rendering (CSR), it injects the document.currentScript.src.
16
- * After these injections, it selects the full URI before _next.
17
- *
18
- * @example
19
- * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
20
- * will become
21
- * http://localhost:1234/test/test2
22
- *
23
- * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
24
- * @param {string} remaining - The remaining part of the resource path.
25
- * @returns {string} The modified source code with the injected code.
26
- */
10
+ * This loader is specifically created for tuning the next-image-loader result.
11
+ * It modifies the regular string output of the next-image-loader.
12
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
13
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
14
+ * After these injections, it selects the full URI before _next.
15
+ *
16
+ * @example
17
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
18
+ * will become
19
+ * http://localhost:1234/test/test2
20
+ *
21
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
22
+ * @param {string} remaining - The remaining part of the resource path.
23
+ * @returns {string} The modified source code with the injected code.
24
+ */
27
25
  async function fixImageLoader(remaining) {
28
- this.cacheable(true);
29
- const isServer = this._compiler?.options?.name !== 'client';
30
- const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';
31
- const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
32
- const content = (result.default || result);
33
- const computedAssetPrefix = isServer
34
- ? `${Template.asString([
35
- 'function getSSRImagePath(){',
36
- //TODO: use auto public path plugin instead
37
- `const pubpath = ${publicPath};`,
38
- Template.asString([
39
- 'try {',
40
- Template.indent([
41
- "const globalThisVal = new Function('return globalThis')();",
42
- 'const name = __webpack_require__.federation.instance.name',
43
- `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
26
+ this.cacheable(true);
27
+ const isServer = this._compiler?.options?.name !== "client";
28
+ const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? "";
29
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
30
+ const content = result.default || result;
31
+ const computedAssetPrefix = isServer ? `${Template.asString([
32
+ "function getSSRImagePath(){",
33
+ `const pubpath = ${publicPath};`,
34
+ Template.asString([
35
+ "try {",
36
+ Template.indent([
37
+ "const globalThisVal = new Function('return globalThis')();",
38
+ "const name = __webpack_require__.federation.instance.name",
39
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
44
40
  (instance) => {
45
41
  if(!instance) return;
46
42
  if (!instance.moduleCache.has(name)) return;
@@ -49,68 +45,60 @@ async function fixImageLoader(remaining) {
49
45
  return container.remoteInfo.entry;
50
46
  },
51
47
  );`,
52
- 'if(!container) return "";',
53
- 'const cache = container.moduleCache',
54
- 'const remote = cache.get(name).remoteInfo',
55
- `const remoteEntry = remote.entry;`,
56
- `if (remoteEntry) {`,
57
- Template.indent([
58
- `const splitted = remoteEntry.split('/_next')`,
59
- `return splitted.length === 2 ? splitted[0] : '';`,
60
- ]),
61
- `}`,
62
- `return '';`,
63
- ]),
64
- '} catch (e) {',
65
- Template.indent([
66
- `console.error('failed generating SSR image path', e);`,
67
- 'return "";',
68
- ]),
69
- '}',
70
- ]),
71
- '}()',
72
- ])}`
73
- : `${Template.asString([
74
- 'function getCSRImagePath(){',
75
- Template.indent([
76
- 'try {',
77
- Template.indent([
78
- `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,
79
- `return splitted.length === 2 ? splitted[0] : '';`,
80
- ]),
81
- '} catch (e) {',
82
- Template.indent([
83
- `const path = document.currentScript && document.currentScript.src;`,
84
- `console.error('failed generating CSR image path', e, path);`,
85
- 'return "";',
86
- ]),
87
- '}',
88
- ]),
89
- '}()',
90
- ])}`;
91
- const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
92
- if (key === 'src') {
93
- if (value && !value.includes('://')) {
94
- value = path_1.default.join(value);
95
- }
96
- acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
97
- return acc;
98
- }
99
- acc.push(`${key}: ${JSON.stringify(value)}`);
100
- return acc;
101
- }, []);
102
- return Template.asString([
103
- "let computedAssetsPrefixReference = '';",
104
- 'try {',
105
- Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
106
- '} catch (e) {}',
107
- 'export default {',
108
- Template.indent(constructedObject.join(',\n')),
109
- '}',
110
- ]);
48
+ "if(!container) return \"\";",
49
+ "const cache = container.moduleCache",
50
+ "const remote = cache.get(name).remoteInfo",
51
+ `const remoteEntry = remote.entry;`,
52
+ `if (remoteEntry) {`,
53
+ Template.indent([`const splitted = remoteEntry.split('/_next')`, `return splitted.length === 2 ? splitted[0] : '';`]),
54
+ `}`,
55
+ `return '';`
56
+ ]),
57
+ "} catch (e) {",
58
+ Template.indent([`console.error('failed generating SSR image path', e);`, "return \"\";"]),
59
+ "}"
60
+ ]),
61
+ "}()"
62
+ ])}` : `${Template.asString([
63
+ "function getCSRImagePath(){",
64
+ Template.indent([
65
+ "try {",
66
+ Template.indent([`const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`, `return splitted.length === 2 ? splitted[0] : '';`]),
67
+ "} catch (e) {",
68
+ Template.indent([
69
+ `const path = document.currentScript && document.currentScript.src;`,
70
+ `console.error('failed generating CSR image path', e, path);`,
71
+ "return \"\";"
72
+ ]),
73
+ "}"
74
+ ]),
75
+ "}()"
76
+ ])}`;
77
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
78
+ if (key === "src") {
79
+ if (value && !value.includes("://")) value = path.default.join(value);
80
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
81
+ return acc;
82
+ }
83
+ acc.push(`${key}: ${JSON.stringify(value)}`);
84
+ return acc;
85
+ }, []);
86
+ return Template.asString([
87
+ "let computedAssetsPrefixReference = '';",
88
+ "try {",
89
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
90
+ "} catch (e) {}",
91
+ "export default {",
92
+ Template.indent(constructedObject.join(",\n")),
93
+ "}"
94
+ ]);
111
95
  }
112
96
  /**
113
- * The pitch function of the loader, which is the same as the fixImageLoader function.
114
- */
115
- exports.pitch = fixImageLoader;
97
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
98
+ */
99
+ const pitch = fixImageLoader;
100
+
101
+ //#endregion
102
+ exports.fixImageLoader = fixImageLoader;
103
+ exports.pitch = pitch;
116
104
  //# sourceMappingURL=fixImageLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixImageLoader.js","sourceRoot":"","sources":["../../../src/loaders/fixImageLoader.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"fixImageLoader.js","names":[],"sources":["../../../src/loaders/fixImageLoader.ts"],"sourcesContent":["import type { LoaderContext } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport path from 'path';\n\n/**\n * This loader is specifically created for tuning the next-image-loader result.\n * It modifies the regular string output of the next-image-loader.\n * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.\n * For client-side rendering (CSR), it injects the document.currentScript.src.\n * After these injections, it selects the full URI before _next.\n *\n * @example\n * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg\n * will become\n * http://localhost:1234/test/test2\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n * @param {string} remaining - The remaining part of the resource path.\n * @returns {string} The modified source code with the injected code.\n */\nexport async function fixImageLoader(\n this: LoaderContext<Record<string, unknown>>,\n remaining: string,\n) {\n this.cacheable(true);\n\n const isServer = this._compiler?.options?.name !== 'client';\n const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';\n\n const result = await this.importModule(\n `${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,\n );\n\n const content = (result.default || result) as Record<string, string>;\n\n const computedAssetPrefix = isServer\n ? `${Template.asString([\n 'function getSSRImagePath(){',\n //TODO: use auto public path plugin instead\n `const pubpath = ${publicPath};`,\n Template.asString([\n 'try {',\n Template.indent([\n \"const globalThisVal = new Function('return globalThis')();\",\n 'const name = __webpack_require__.federation.instance.name',\n `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(\n (instance) => {\n if(!instance) return;\n if (!instance.moduleCache.has(name)) return;\n const container = instance.moduleCache.get(name);\n if (!container.remoteInfo) return;\n return container.remoteInfo.entry;\n },\n );`,\n 'if(!container) return \"\";',\n 'const cache = container.moduleCache',\n 'const remote = cache.get(name).remoteInfo',\n `const remoteEntry = remote.entry;`,\n `if (remoteEntry) {`,\n Template.indent([\n `const splitted = remoteEntry.split('/_next')`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n `}`,\n `return '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `console.error('failed generating SSR image path', e);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`\n : `${Template.asString([\n 'function getCSRImagePath(){',\n Template.indent([\n 'try {',\n Template.indent([\n `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `const path = document.currentScript && document.currentScript.src;`,\n `console.error('failed generating CSR image path', e, path);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`;\n\n const constructedObject = Object.entries(content).reduce(\n (acc, [key, value]) => {\n if (key === 'src') {\n if (value && !value.includes('://')) {\n value = path.join(value);\n }\n acc.push(\n `${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`,\n );\n return acc;\n }\n acc.push(`${key}: ${JSON.stringify(value)}`);\n return acc;\n },\n [] as string[],\n );\n\n return Template.asString([\n \"let computedAssetsPrefixReference = '';\",\n 'try {',\n Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),\n '} catch (e) {}',\n 'export default {',\n Template.indent(constructedObject.join(',\\n')),\n '}',\n ]);\n}\n\n/**\n * The pitch function of the loader, which is the same as the fixImageLoader function.\n */\nexport const pitch = fixImageLoader;\n"],"mappings":";;;;;;;AAEA,MAAM,EAAE,aAAa,gFACE,UAAU,CAChC;;;;;;;;;;;;;;;;;AAmBD,eAAsB,eAEpB,WACA;AACA,MAAK,UAAU,KAAK;CAEpB,MAAM,WAAW,KAAK,WAAW,SAAS,SAAS;CACnD,MAAM,aAAa,KAAK,WAAW,SAAS,gBAAgB,cAAc;CAE1E,MAAM,SAAS,MAAM,KAAK,aACxB,GAAG,KAAK,aAAa,8BAA8B,YACpD;CAED,MAAM,UAAW,OAAO,WAAW;CAEnC,MAAM,sBAAsB,WACxB,GAAG,SAAS,SAAS;EACnB;EAEA,mBAAmB,WAAW;EAC9B,SAAS,SAAS;GAChB;GACA,SAAS,OAAO;IACd;IACA;IACA;;;;;;;;;IASA;IACA;IACA;IACA;IACA;IACA,SAAS,OAAO,CACd,gDACA,mDACD,CAAC;IACF;IACA;IACD,CAAC;GACF;GACA,SAAS,OAAO,CACd,yDACA,eACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC,KACF,GAAG,SAAS,SAAS;EACnB;EACA,SAAS,OAAO;GACd;GACA,SAAS,OAAO,CACd,oBAAoB,WAAW,KAAK,WAAW,yBAC/C,mDACD,CAAC;GACF;GACA,SAAS,OAAO;IACd;IACA;IACA;IACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC;CAEN,MAAM,oBAAoB,OAAO,QAAQ,QAAQ,CAAC,QAC/C,KAAK,CAAC,KAAK,WAAW;AACrB,MAAI,QAAQ,OAAO;AACjB,OAAI,SAAS,CAAC,MAAM,SAAS,MAAM,CACjC,SAAQ,aAAK,KAAK,MAAM;AAE1B,OAAI,KACF,GAAG,IAAI,oCAAoC,KAAK,UAAU,MAAM,GACjE;AACD,UAAO;;AAET,MAAI,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,MAAM,GAAG;AAC5C,SAAO;IAET,EAAE,CACH;AAED,QAAO,SAAS,SAAS;EACvB;EACA;EACA,SAAS,OAAO,mCAAmC,oBAAoB,GAAG;EAC1E;EACA;EACA,SAAS,OAAO,kBAAkB,KAAK,MAAM,CAAC;EAC9C;EACD,CAAC;;;;;AAMJ,MAAa,QAAQ"}
@@ -0,0 +1,101 @@
1
+ import { __require } from "../../_virtual/_rolldown/runtime.mjs";
2
+ import { normalizeWebpackPath } from "@module-federation/sdk/normalize-webpack-path";
3
+ import path from "path";
4
+
5
+ //#region src/loaders/fixImageLoader.ts
6
+ const { Template } = __require(normalizeWebpackPath("webpack"));
7
+ /**
8
+ * This loader is specifically created for tuning the next-image-loader result.
9
+ * It modifies the regular string output of the next-image-loader.
10
+ * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.
11
+ * For client-side rendering (CSR), it injects the document.currentScript.src.
12
+ * After these injections, it selects the full URI before _next.
13
+ *
14
+ * @example
15
+ * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg
16
+ * will become
17
+ * http://localhost:1234/test/test2
18
+ *
19
+ * @param {LoaderContext<Record<string, unknown>>} this - The loader context.
20
+ * @param {string} remaining - The remaining part of the resource path.
21
+ * @returns {string} The modified source code with the injected code.
22
+ */
23
+ async function fixImageLoader(remaining) {
24
+ this.cacheable(true);
25
+ const isServer = this._compiler?.options?.name !== "client";
26
+ const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? "";
27
+ const result = await this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`);
28
+ const content = result.default || result;
29
+ const computedAssetPrefix = isServer ? `${Template.asString([
30
+ "function getSSRImagePath(){",
31
+ `const pubpath = ${publicPath};`,
32
+ Template.asString([
33
+ "try {",
34
+ Template.indent([
35
+ "const globalThisVal = new Function('return globalThis')();",
36
+ "const name = __webpack_require__.federation.instance.name",
37
+ `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(
38
+ (instance) => {
39
+ if(!instance) return;
40
+ if (!instance.moduleCache.has(name)) return;
41
+ const container = instance.moduleCache.get(name);
42
+ if (!container.remoteInfo) return;
43
+ return container.remoteInfo.entry;
44
+ },
45
+ );`,
46
+ "if(!container) return \"\";",
47
+ "const cache = container.moduleCache",
48
+ "const remote = cache.get(name).remoteInfo",
49
+ `const remoteEntry = remote.entry;`,
50
+ `if (remoteEntry) {`,
51
+ Template.indent([`const splitted = remoteEntry.split('/_next')`, `return splitted.length === 2 ? splitted[0] : '';`]),
52
+ `}`,
53
+ `return '';`
54
+ ]),
55
+ "} catch (e) {",
56
+ Template.indent([`console.error('failed generating SSR image path', e);`, "return \"\";"]),
57
+ "}"
58
+ ]),
59
+ "}()"
60
+ ])}` : `${Template.asString([
61
+ "function getCSRImagePath(){",
62
+ Template.indent([
63
+ "try {",
64
+ Template.indent([`const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`, `return splitted.length === 2 ? splitted[0] : '';`]),
65
+ "} catch (e) {",
66
+ Template.indent([
67
+ `const path = document.currentScript && document.currentScript.src;`,
68
+ `console.error('failed generating CSR image path', e, path);`,
69
+ "return \"\";"
70
+ ]),
71
+ "}"
72
+ ]),
73
+ "}()"
74
+ ])}`;
75
+ const constructedObject = Object.entries(content).reduce((acc, [key, value]) => {
76
+ if (key === "src") {
77
+ if (value && !value.includes("://")) value = path.join(value);
78
+ acc.push(`${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`);
79
+ return acc;
80
+ }
81
+ acc.push(`${key}: ${JSON.stringify(value)}`);
82
+ return acc;
83
+ }, []);
84
+ return Template.asString([
85
+ "let computedAssetsPrefixReference = '';",
86
+ "try {",
87
+ Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),
88
+ "} catch (e) {}",
89
+ "export default {",
90
+ Template.indent(constructedObject.join(",\n")),
91
+ "}"
92
+ ]);
93
+ }
94
+ /**
95
+ * The pitch function of the loader, which is the same as the fixImageLoader function.
96
+ */
97
+ const pitch = fixImageLoader;
98
+
99
+ //#endregion
100
+ export { fixImageLoader, pitch };
101
+ //# sourceMappingURL=fixImageLoader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixImageLoader.mjs","names":[],"sources":["../../../src/loaders/fixImageLoader.ts"],"sourcesContent":["import type { LoaderContext } from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst { Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport path from 'path';\n\n/**\n * This loader is specifically created for tuning the next-image-loader result.\n * It modifies the regular string output of the next-image-loader.\n * For server-side rendering (SSR), it injects the remote scope of a specific remote URL.\n * For client-side rendering (CSR), it injects the document.currentScript.src.\n * After these injections, it selects the full URI before _next.\n *\n * @example\n * http://localhost:1234/test/test2/_next/static/media/ssl.e3019f0e.svg\n * will become\n * http://localhost:1234/test/test2\n *\n * @param {LoaderContext<Record<string, unknown>>} this - The loader context.\n * @param {string} remaining - The remaining part of the resource path.\n * @returns {string} The modified source code with the injected code.\n */\nexport async function fixImageLoader(\n this: LoaderContext<Record<string, unknown>>,\n remaining: string,\n) {\n this.cacheable(true);\n\n const isServer = this._compiler?.options?.name !== 'client';\n const publicPath = this._compiler?.webpack?.RuntimeGlobals?.publicPath ?? '';\n\n const result = await this.importModule(\n `${this.resourcePath}.webpack[javascript/auto]!=!${remaining}`,\n );\n\n const content = (result.default || result) as Record<string, string>;\n\n const computedAssetPrefix = isServer\n ? `${Template.asString([\n 'function getSSRImagePath(){',\n //TODO: use auto public path plugin instead\n `const pubpath = ${publicPath};`,\n Template.asString([\n 'try {',\n Template.indent([\n \"const globalThisVal = new Function('return globalThis')();\",\n 'const name = __webpack_require__.federation.instance.name',\n `const container = globalThisVal['__FEDERATION__']['__INSTANCES__'].find(\n (instance) => {\n if(!instance) return;\n if (!instance.moduleCache.has(name)) return;\n const container = instance.moduleCache.get(name);\n if (!container.remoteInfo) return;\n return container.remoteInfo.entry;\n },\n );`,\n 'if(!container) return \"\";',\n 'const cache = container.moduleCache',\n 'const remote = cache.get(name).remoteInfo',\n `const remoteEntry = remote.entry;`,\n `if (remoteEntry) {`,\n Template.indent([\n `const splitted = remoteEntry.split('/_next')`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n `}`,\n `return '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `console.error('failed generating SSR image path', e);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`\n : `${Template.asString([\n 'function getCSRImagePath(){',\n Template.indent([\n 'try {',\n Template.indent([\n `const splitted = ${publicPath} ? ${publicPath}.split('/_next') : '';`,\n `return splitted.length === 2 ? splitted[0] : '';`,\n ]),\n '} catch (e) {',\n Template.indent([\n `const path = document.currentScript && document.currentScript.src;`,\n `console.error('failed generating CSR image path', e, path);`,\n 'return \"\";',\n ]),\n '}',\n ]),\n '}()',\n ])}`;\n\n const constructedObject = Object.entries(content).reduce(\n (acc, [key, value]) => {\n if (key === 'src') {\n if (value && !value.includes('://')) {\n value = path.join(value);\n }\n acc.push(\n `${key}: computedAssetsPrefixReference + ${JSON.stringify(value)}`,\n );\n return acc;\n }\n acc.push(`${key}: ${JSON.stringify(value)}`);\n return acc;\n },\n [] as string[],\n );\n\n return Template.asString([\n \"let computedAssetsPrefixReference = '';\",\n 'try {',\n Template.indent(`computedAssetsPrefixReference = ${computedAssetPrefix};`),\n '} catch (e) {}',\n 'export default {',\n Template.indent(constructedObject.join(',\\n')),\n '}',\n ]);\n}\n\n/**\n * The pitch function of the loader, which is the same as the fixImageLoader function.\n */\nexport const pitch = fixImageLoader;\n"],"mappings":";;;;;AAEA,MAAM,EAAE,uBACN,qBAAqB,UAAU,CAChC;;;;;;;;;;;;;;;;;AAmBD,eAAsB,eAEpB,WACA;AACA,MAAK,UAAU,KAAK;CAEpB,MAAM,WAAW,KAAK,WAAW,SAAS,SAAS;CACnD,MAAM,aAAa,KAAK,WAAW,SAAS,gBAAgB,cAAc;CAE1E,MAAM,SAAS,MAAM,KAAK,aACxB,GAAG,KAAK,aAAa,8BAA8B,YACpD;CAED,MAAM,UAAW,OAAO,WAAW;CAEnC,MAAM,sBAAsB,WACxB,GAAG,SAAS,SAAS;EACnB;EAEA,mBAAmB,WAAW;EAC9B,SAAS,SAAS;GAChB;GACA,SAAS,OAAO;IACd;IACA;IACA;;;;;;;;;IASA;IACA;IACA;IACA;IACA;IACA,SAAS,OAAO,CACd,gDACA,mDACD,CAAC;IACF;IACA;IACD,CAAC;GACF;GACA,SAAS,OAAO,CACd,yDACA,eACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC,KACF,GAAG,SAAS,SAAS;EACnB;EACA,SAAS,OAAO;GACd;GACA,SAAS,OAAO,CACd,oBAAoB,WAAW,KAAK,WAAW,yBAC/C,mDACD,CAAC;GACF;GACA,SAAS,OAAO;IACd;IACA;IACA;IACD,CAAC;GACF;GACD,CAAC;EACF;EACD,CAAC;CAEN,MAAM,oBAAoB,OAAO,QAAQ,QAAQ,CAAC,QAC/C,KAAK,CAAC,KAAK,WAAW;AACrB,MAAI,QAAQ,OAAO;AACjB,OAAI,SAAS,CAAC,MAAM,SAAS,MAAM,CACjC,SAAQ,KAAK,KAAK,MAAM;AAE1B,OAAI,KACF,GAAG,IAAI,oCAAoC,KAAK,UAAU,MAAM,GACjE;AACD,UAAO;;AAET,MAAI,KAAK,GAAG,IAAI,IAAI,KAAK,UAAU,MAAM,GAAG;AAC5C,SAAO;IAET,EAAE,CACH;AAED,QAAO,SAAS,SAAS;EACvB;EACA;EACA,SAAS,OAAO,mCAAmC,oBAAoB,GAAG;EAC1E;EACA;EACA,SAAS,OAAO,kBAAkB,KAAK,MAAM,CAAC;EAC9C;EACD,CAAC;;;;;AAMJ,MAAa,QAAQ"}
@@ -0,0 +1,16 @@
1
+ //#region src/loaders/fixUrlLoader.d.ts
2
+ /**
3
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
4
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
5
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
6
+ *
7
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
8
+ * For example, it could be: http://localhost:3000/_next
9
+ *
10
+ * @param {string} content - The original output from the url-loader.
11
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
12
+ */
13
+ declare function fixUrlLoader(content: string): string;
14
+ //#endregion
15
+ export { fixUrlLoader as default, fixUrlLoader };
16
+ //# sourceMappingURL=fixUrlLoader.d.mts.map
@@ -1,3 +1,4 @@
1
+ //#region src/loaders/fixUrlLoader.d.ts
1
2
  /**
2
3
  * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
3
4
  * It injects the PUBLIC_PATH from the webpack runtime into the output.
@@ -9,5 +10,7 @@
9
10
  * @param {string} content - The original output from the url-loader.
10
11
  * @returns {string} The modified output with the injected PUBLIC_PATH.
11
12
  */
12
- export declare function fixUrlLoader(content: string): string;
13
- export default fixUrlLoader;
13
+ declare function fixUrlLoader(content: string): string;
14
+ //#endregion
15
+ export { fixUrlLoader as default, fixUrlLoader };
16
+ //# sourceMappingURL=fixUrlLoader.d.ts.map
@@ -1,24 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fixUrlLoader = fixUrlLoader;
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+
3
+ //#region src/loaders/fixUrlLoader.ts
4
4
  /**
5
- * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
6
- * It injects the PUBLIC_PATH from the webpack runtime into the output.
7
- * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
8
- *
9
- * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
10
- * For example, it could be: http://localhost:3000/_next
11
- *
12
- * @param {string} content - The original output from the url-loader.
13
- * @returns {string} The modified output with the injected PUBLIC_PATH.
14
- */
5
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
6
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
7
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
8
+ *
9
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
10
+ * For example, it could be: http://localhost:3000/_next
11
+ *
12
+ * @param {string} content - The original output from the url-loader.
13
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
14
+ */
15
15
  function fixUrlLoader(content) {
16
- // This regular expression extracts the hostname from the publicPath.
17
- // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000
18
- const currentHostnameCode = "__webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '$1')";
19
- // Replace the default export path in the content with the modified path that includes the hostname.
20
- return content.replace('export default "/', `export default ${currentHostnameCode}+"/`);
16
+ return content.replace("export default \"/", `export default __webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '\$1')+"/`);
21
17
  }
22
- // Export the fixUrlLoader function as the default export of this module.
18
+
19
+ //#endregion
23
20
  exports.default = fixUrlLoader;
21
+ exports.fixUrlLoader = fixUrlLoader;
24
22
  //# sourceMappingURL=fixUrlLoader.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixUrlLoader.js","sourceRoot":"","sources":["../../../src/loaders/fixUrlLoader.ts"],"names":[],"mappings":";;AAWA,oCAWC;AAtBD;;;;;;;;;;GAUG;AACH,SAAgB,YAAY,CAAC,OAAe;IAC1C,qEAAqE;IACrE,wFAAwF;IACxF,MAAM,mBAAmB,GACvB,wEAAwE,CAAC;IAE3E,oGAAoG;IACpG,OAAO,OAAO,CAAC,OAAO,CACpB,mBAAmB,EACnB,kBAAkB,mBAAmB,KAAK,CAC3C,CAAC;AACJ,CAAC;AAED,yEAAyE;AACzE,kBAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"fixUrlLoader.js","names":[],"sources":["../../../src/loaders/fixUrlLoader.ts"],"sourcesContent":["/**\n * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.\n * It injects the PUBLIC_PATH from the webpack runtime into the output.\n * The output format is: `export default __webpack_require__.p + \"/static/media/ssl.e3019f0e.svg\"`\n *\n * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.\n * For example, it could be: http://localhost:3000/_next\n *\n * @param {string} content - The original output from the url-loader.\n * @returns {string} The modified output with the injected PUBLIC_PATH.\n */\nexport function fixUrlLoader(content: string) {\n // This regular expression extracts the hostname from the publicPath.\n // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000\n const currentHostnameCode =\n \"__webpack_require__.p.replace(/(.+\\\\:\\\\/\\\\/[^\\\\/]+){0,1}\\\\/.*/i, '$1')\";\n\n // Replace the default export path in the content with the modified path that includes the hostname.\n return content.replace(\n 'export default \"/',\n `export default ${currentHostnameCode}+\"/`,\n );\n}\n\n// Export the fixUrlLoader function as the default export of this module.\nexport default fixUrlLoader;\n"],"mappings":";;;;;;;;;;;;;;AAWA,SAAgB,aAAa,SAAiB;AAO5C,QAAO,QAAQ,QACb,sBACA,4FACD"}
@@ -0,0 +1,19 @@
1
+ //#region src/loaders/fixUrlLoader.ts
2
+ /**
3
+ * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.
4
+ * It injects the PUBLIC_PATH from the webpack runtime into the output.
5
+ * The output format is: `export default __webpack_require__.p + "/static/media/ssl.e3019f0e.svg"`
6
+ *
7
+ * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.
8
+ * For example, it could be: http://localhost:3000/_next
9
+ *
10
+ * @param {string} content - The original output from the url-loader.
11
+ * @returns {string} The modified output with the injected PUBLIC_PATH.
12
+ */
13
+ function fixUrlLoader(content) {
14
+ return content.replace("export default \"/", `export default __webpack_require__.p.replace(/(.+\\:\\/\\/[^\\/]+){0,1}\\/.*/i, '\$1')+"/`);
15
+ }
16
+
17
+ //#endregion
18
+ export { fixUrlLoader as default, fixUrlLoader };
19
+ //# sourceMappingURL=fixUrlLoader.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fixUrlLoader.mjs","names":[],"sources":["../../../src/loaders/fixUrlLoader.ts"],"sourcesContent":["/**\n * `fixUrlLoader` is a custom loader designed to modify the output of the url-loader.\n * It injects the PUBLIC_PATH from the webpack runtime into the output.\n * The output format is: `export default __webpack_require__.p + \"/static/media/ssl.e3019f0e.svg\"`\n *\n * `__webpack_require__.p` is a global variable in the webpack container that contains the publicPath.\n * For example, it could be: http://localhost:3000/_next\n *\n * @param {string} content - The original output from the url-loader.\n * @returns {string} The modified output with the injected PUBLIC_PATH.\n */\nexport function fixUrlLoader(content: string) {\n // This regular expression extracts the hostname from the publicPath.\n // For example, it transforms http://localhost:3000/_next/... into http://localhost:3000\n const currentHostnameCode =\n \"__webpack_require__.p.replace(/(.+\\\\:\\\\/\\\\/[^\\\\/]+){0,1}\\\\/.*/i, '$1')\";\n\n // Replace the default export path in the content with the modified path that includes the hostname.\n return content.replace(\n 'export default \"/',\n `export default ${currentHostnameCode}+\"/`,\n );\n}\n\n// Export the fixUrlLoader function as the default export of this module.\nexport default fixUrlLoader;\n"],"mappings":";;;;;;;;;;;;AAWA,SAAgB,aAAa,SAAiB;AAO5C,QAAO,QAAQ,QACb,sBACA,4FACD"}