@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.
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.js +29 -0
- package/dist/_virtual/_rolldown/runtime.mjs +8 -0
- package/dist/client/UrlNode.js +89 -147
- package/dist/client/UrlNode.js.map +1 -1
- package/dist/client/UrlNode.mjs +91 -0
- package/dist/client/UrlNode.mjs.map +1 -0
- package/dist/src/federation-noop.d.mts +1 -0
- package/dist/src/federation-noop.d.ts +1 -0
- package/dist/src/federation-noop.js +17 -0
- package/dist/src/federation-noop.js.map +1 -1
- package/dist/src/federation-noop.mjs +23 -0
- package/dist/src/federation-noop.mjs.map +1 -0
- package/dist/src/index.d.mts +2 -0
- package/dist/src/index.d.ts +2 -3
- package/dist/src/index.js +13 -11
- package/dist/src/index.js.map +1 -1
- package/dist/src/index.mjs +8 -0
- package/dist/src/index.mjs.map +1 -0
- package/dist/src/internal.js +140 -243
- package/dist/src/internal.js.map +1 -1
- package/dist/src/internal.mjs +152 -0
- package/dist/src/internal.mjs.map +1 -0
- package/dist/src/loaders/fixImageLoader.d.mts +27 -0
- package/dist/src/loaders/fixImageLoader.d.ts +8 -3
- package/dist/src/loaders/fixImageLoader.js +91 -103
- package/dist/src/loaders/fixImageLoader.js.map +1 -1
- package/dist/src/loaders/fixImageLoader.mjs +101 -0
- package/dist/src/loaders/fixImageLoader.mjs.map +1 -0
- package/dist/src/loaders/fixUrlLoader.d.mts +16 -0
- package/dist/src/loaders/fixUrlLoader.d.ts +5 -2
- package/dist/src/loaders/fixUrlLoader.js +17 -19
- package/dist/src/loaders/fixUrlLoader.js.map +1 -1
- package/dist/src/loaders/fixUrlLoader.mjs +19 -0
- package/dist/src/loaders/fixUrlLoader.mjs.map +1 -0
- package/dist/src/loaders/helpers.js +72 -124
- package/dist/src/loaders/helpers.js.map +1 -1
- package/dist/src/loaders/helpers.mjs +79 -0
- package/dist/src/loaders/helpers.mjs.map +1 -0
- package/dist/src/loaders/nextPageMapLoader.d.mts +29 -0
- package/dist/src/loaders/nextPageMapLoader.d.ts +10 -5
- package/dist/src/loaders/nextPageMapLoader.js +126 -144
- package/dist/src/loaders/nextPageMapLoader.js.map +1 -1
- package/dist/src/loaders/nextPageMapLoader.mjs +143 -0
- package/dist/src/loaders/nextPageMapLoader.mjs.map +1 -0
- package/dist/src/logger.js +7 -7
- package/dist/src/logger.js.map +1 -1
- package/dist/src/logger.mjs +8 -0
- package/dist/src/logger.mjs.map +1 -0
- package/dist/src/plugins/CopyFederationPlugin.js +64 -71
- package/dist/src/plugins/CopyFederationPlugin.js.map +1 -1
- package/dist/src/plugins/CopyFederationPlugin.mjs +65 -0
- package/dist/src/plugins/CopyFederationPlugin.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js +36 -53
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs +40 -0
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js +103 -121
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs +111 -0
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/index.d.mts +31 -0
- package/dist/src/plugins/NextFederationPlugin/index.d.ts +27 -23
- package/dist/src/plugins/NextFederationPlugin/index.js +147 -181
- package/dist/src/plugins/NextFederationPlugin/index.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/index.mjs +150 -0
- package/dist/src/plugins/NextFederationPlugin/index.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.d.mts +18 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.d.ts +16 -18
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js +62 -92
- package/dist/src/plugins/NextFederationPlugin/next-fragments.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs +68 -0
- package/dist/src/plugins/NextFederationPlugin/next-fragments.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.js +17 -19
- package/dist/src/plugins/NextFederationPlugin/set-options.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/set-options.mjs +19 -0
- package/dist/src/plugins/NextFederationPlugin/set-options.mjs.map +1 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.js +30 -38
- package/dist/src/plugins/NextFederationPlugin/validate-options.js.map +1 -1
- package/dist/src/plugins/NextFederationPlugin/validate-options.mjs +35 -0
- package/dist/src/plugins/NextFederationPlugin/validate-options.mjs.map +1 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.js +22 -25
- package/dist/src/plugins/container/InvertedContainerPlugin.js.map +1 -1
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs +23 -0
- package/dist/src/plugins/container/InvertedContainerPlugin.mjs.map +1 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js +55 -67
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.js.map +1 -1
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs +57 -0
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.mjs.map +1 -0
- package/dist/src/plugins/container/runtimePlugin.d.mts +7 -0
- package/dist/src/plugins/container/runtimePlugin.d.ts +6 -2
- package/dist/src/plugins/container/runtimePlugin.js +167 -0
- package/dist/src/plugins/container/runtimePlugin.js.map +1 -1
- package/dist/src/plugins/container/runtimePlugin.mjs +166 -0
- package/dist/src/plugins/container/runtimePlugin.mjs.map +1 -0
- package/dist/utils/flushedChunks.d.mts +29 -0
- package/dist/utils/flushedChunks.d.ts +12 -5
- package/dist/utils/flushedChunks.js +32 -72
- package/dist/utils/flushedChunks.js.map +1 -1
- package/dist/utils/flushedChunks.mjs +35 -0
- package/dist/utils/flushedChunks.mjs.map +1 -0
- package/dist/utils/index.d.mts +14 -0
- package/dist/utils/index.d.ts +8 -14
- package/dist/utils/index.js +27 -62
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +22 -0
- package/dist/utils/index.mjs.map +1 -0
- package/package.json +29 -9
- package/dist/client/UrlNode.d.ts +0 -17
- package/dist/node.d.ts +0 -1
- package/dist/node.js +0 -18
- package/dist/node.js.map +0 -1
- package/dist/package.json +0 -80
- package/dist/src/federation-noop.cjs +0 -15
- package/dist/src/internal.d.ts +0 -50
- package/dist/src/loaders/helpers.d.ts +0 -17
- package/dist/src/logger.d.ts +0 -2
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.d.ts +0 -5
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js +0 -19
- package/dist/src/plugins/AddRuntimeRequirementToPromiseExternalPlugin.js.map +0 -1
- package/dist/src/plugins/CopyFederationPlugin.d.ts +0 -20
- package/dist/src/plugins/NextFederationPlugin/apply-client-plugins.d.ts +0 -23
- package/dist/src/plugins/NextFederationPlugin/apply-server-plugins.d.ts +0 -36
- package/dist/src/plugins/NextFederationPlugin/regex-equal.d.ts +0 -14
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js +0 -25
- package/dist/src/plugins/NextFederationPlugin/regex-equal.js.map +0 -1
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.d.ts +0 -8
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js +0 -34
- package/dist/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.js.map +0 -1
- package/dist/src/plugins/NextFederationPlugin/set-options.d.ts +0 -16
- package/dist/src/plugins/NextFederationPlugin/validate-options.d.ts +0 -25
- package/dist/src/plugins/container/InvertedContainerPlugin.d.ts +0 -5
- package/dist/src/plugins/container/InvertedContainerRuntimeModule.d.ts +0 -11
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.d.ts +0 -39
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js +0 -78
- package/dist/src/plugins/container/RemoveEagerModulesFromRuntimePlugin.js.map +0 -1
- package/dist/src/plugins/container/runtimePlugin.cjs +0 -219
- package/dist/src/plugins/container/types.d.ts +0 -2
- package/dist/src/plugins/container/types.js +0 -3
- package/dist/src/plugins/container/types.js.map +0 -1
- package/dist/src/types.d.ts +0 -28
- package/dist/src/types.js +0 -3
- package/dist/src/types.js.map +0 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
24
|
+
declare const pitch: typeof fixImageLoader;
|
|
25
|
+
//#endregion
|
|
26
|
+
export { fixImageLoader, pitch };
|
|
27
|
+
//# sourceMappingURL=fixImageLoader.d.ts.map
|
|
@@ -1,46 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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","
|
|
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
|
-
|
|
13
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
|
|
3
|
+
//#region src/loaders/fixUrlLoader.ts
|
|
4
4
|
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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","
|
|
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"}
|