@module-federation/modern-js 0.21.6 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/configPlugin.js +301 -357
- package/dist/cjs/cli/index.js +103 -93
- package/dist/cjs/cli/mfRuntimePlugins/inject-node-fetch.js +51 -41
- package/dist/cjs/cli/mfRuntimePlugins/resolve-entry-ipv4.js +73 -75
- package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +50 -40
- package/dist/cjs/cli/server/data-fetch-server-plugin.js +55 -44
- package/dist/cjs/cli/ssrPlugin.js +266 -298
- package/dist/cjs/cli/utils.js +84 -81
- package/dist/cjs/constant.js +37 -28
- package/dist/cjs/interfaces/bundler.js +17 -15
- package/dist/cjs/logger.js +37 -25
- package/dist/cjs/react/index.js +55 -19
- package/dist/cjs/react/plugin.js +62 -37
- package/dist/cjs/react/v18.js +55 -19
- package/dist/cjs/react/v19.js +55 -19
- package/dist/cjs/runtime/index.js +55 -19
- package/dist/cjs/server/fileCache.js +76 -76
- package/dist/cjs/server/index.js +65 -57
- package/dist/cjs/server/staticMiddleware.js +84 -84
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +40 -34
- package/dist/cjs/ssr-runtime/devPlugin.js +63 -67
- package/dist/cjs/ssr-runtime/injectDataFetchFunctionPlugin.js +44 -36
- package/dist/cjs/types/index.js +17 -15
- package/dist/esm/cli/configPlugin.mjs +305 -0
- package/dist/esm/cli/index.mjs +83 -0
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.mjs +12 -0
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +58 -0
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.mjs +21 -0
- package/dist/esm/cli/server/data-fetch-server-plugin.mjs +17 -0
- package/dist/esm/cli/ssrPlugin.mjs +254 -0
- package/dist/esm/cli/utils.mjs +40 -0
- package/dist/esm/constant.mjs +3 -0
- package/dist/esm/logger.mjs +5 -0
- package/dist/esm/react/plugin.mjs +3 -0
- package/dist/esm/server/fileCache.mjs +90 -0
- package/dist/esm/server/index.mjs +36 -0
- package/dist/esm/server/staticMiddleware.mjs +87 -0
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +22 -0
- package/dist/esm/ssr-runtime/devPlugin.mjs +70 -0
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.mjs +34 -0
- package/dist/esm-node/cli/configPlugin.mjs +263 -0
- package/dist/esm-node/cli/index.mjs +67 -0
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.mjs +10 -0
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.mjs +46 -0
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.mjs +19 -0
- package/dist/esm-node/cli/server/data-fetch-server-plugin.mjs +15 -0
- package/dist/esm-node/cli/ssrPlugin.mjs +228 -0
- package/dist/esm-node/cli/utils.mjs +40 -0
- package/dist/esm-node/constant.mjs +3 -0
- package/dist/esm-node/logger.mjs +5 -0
- package/dist/esm-node/react/plugin.mjs +3 -0
- package/dist/esm-node/server/fileCache.mjs +37 -0
- package/dist/esm-node/server/index.mjs +34 -0
- package/dist/esm-node/server/staticMiddleware.mjs +42 -0
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +15 -0
- package/dist/esm-node/ssr-runtime/devPlugin.mjs +33 -0
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.mjs +14 -0
- package/package.json +32 -31
- package/dist/cjs/cli/configPlugin.spec.js +0 -112
- package/dist/cjs/server/fileCache.spec.js +0 -28
- package/dist/cjs/server/staticMiddleware.spec.js +0 -185
- package/dist/esm/cli/configPlugin.js +0 -395
- package/dist/esm/cli/configPlugin.spec.js +0 -108
- package/dist/esm/cli/index.js +0 -92
- package/dist/esm/cli/mfRuntimePlugins/inject-node-fetch.js +0 -16
- package/dist/esm/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -74
- package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +0 -25
- package/dist/esm/cli/server/data-fetch-server-plugin.js +0 -20
- package/dist/esm/cli/ssrPlugin.js +0 -305
- package/dist/esm/cli/utils.js +0 -53
- package/dist/esm/constant.js +0 -6
- package/dist/esm/logger.js +0 -7
- package/dist/esm/react/plugin.js +0 -5
- package/dist/esm/server/fileCache.js +0 -98
- package/dist/esm/server/fileCache.spec.js +0 -50
- package/dist/esm/server/index.js +0 -41
- package/dist/esm/server/staticMiddleware.js +0 -104
- package/dist/esm/server/staticMiddleware.spec.js +0 -328
- package/dist/esm/ssr-runtime/SSRLiveReload.js +0 -26
- package/dist/esm/ssr-runtime/devPlugin.js +0 -73
- package/dist/esm/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -34
- package/dist/esm-node/cli/configPlugin.js +0 -347
- package/dist/esm-node/cli/configPlugin.spec.js +0 -89
- package/dist/esm-node/cli/index.js +0 -72
- package/dist/esm-node/cli/mfRuntimePlugins/inject-node-fetch.js +0 -14
- package/dist/esm-node/cli/mfRuntimePlugins/resolve-entry-ipv4.js +0 -62
- package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +0 -23
- package/dist/esm-node/cli/server/data-fetch-server-plugin.js +0 -18
- package/dist/esm-node/cli/ssrPlugin.js +0 -280
- package/dist/esm-node/cli/utils.js +0 -53
- package/dist/esm-node/constant.js +0 -6
- package/dist/esm-node/logger.js +0 -7
- package/dist/esm-node/react/plugin.js +0 -5
- package/dist/esm-node/server/fileCache.js +0 -49
- package/dist/esm-node/server/fileCache.spec.js +0 -27
- package/dist/esm-node/server/index.js +0 -39
- package/dist/esm-node/server/staticMiddleware.js +0 -55
- package/dist/esm-node/server/staticMiddleware.spec.js +0 -162
- package/dist/esm-node/ssr-runtime/SSRLiveReload.js +0 -19
- package/dist/esm-node/ssr-runtime/devPlugin.js +0 -37
- package/dist/esm-node/ssr-runtime/injectDataFetchFunctionPlugin.js +0 -16
- /package/dist/esm/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm/react/{index.js → index.mjs} +0 -0
- /package/dist/esm/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm/types/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/interfaces/{bundler.js → bundler.mjs} +0 -0
- /package/dist/esm-node/react/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/react/{v18.js → v18.mjs} +0 -0
- /package/dist/esm-node/react/{v19.js → v19.mjs} +0 -0
- /package/dist/esm-node/runtime/{index.js → index.mjs} +0 -0
- /package/dist/esm-node/types/{index.js → index.mjs} +0 -0
|
@@ -1,316 +1,284 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
default: ()=>ssrPlugin,
|
|
37
|
+
moduleFederationSSRPlugin: ()=>moduleFederationSSRPlugin,
|
|
38
|
+
setEnv: ()=>setEnv,
|
|
39
|
+
CHAIN_MF_PLUGIN_ID: ()=>CHAIN_MF_PLUGIN_ID
|
|
35
40
|
});
|
|
36
|
-
|
|
37
|
-
var
|
|
38
|
-
|
|
39
|
-
var
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var
|
|
44
|
-
|
|
45
|
-
var
|
|
46
|
-
|
|
41
|
+
const external_path_namespaceObject = require("path");
|
|
42
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
44
|
+
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
45
|
+
const webpack_namespaceObject = require("@module-federation/enhanced/webpack");
|
|
46
|
+
const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
|
|
47
|
+
const universe_entry_chunk_tracker_plugin_namespaceObject = require("@module-federation/node/universe-entry-chunk-tracker-plugin");
|
|
48
|
+
var universe_entry_chunk_tracker_plugin_default = /*#__PURE__*/ __webpack_require__.n(universe_entry_chunk_tracker_plugin_namespaceObject);
|
|
49
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
50
|
+
var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
|
|
51
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
52
|
+
const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
|
|
53
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
47
54
|
function setEnv() {
|
|
48
|
-
|
|
55
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
49
56
|
}
|
|
50
|
-
const CHAIN_MF_PLUGIN_ID =
|
|
57
|
+
const CHAIN_MF_PLUGIN_ID = 'plugin-module-federation-server';
|
|
51
58
|
function getManifestAssetFileNames(manifestOption) {
|
|
52
|
-
|
|
59
|
+
if (!manifestOption) return {
|
|
60
|
+
statsFileName: sdk_namespaceObject.StatsFileName,
|
|
61
|
+
manifestFileName: sdk_namespaceObject.ManifestFileName
|
|
62
|
+
};
|
|
63
|
+
const JSON_EXT = '.json';
|
|
64
|
+
const filePath = 'boolean' == typeof manifestOption ? '' : manifestOption.filePath || '';
|
|
65
|
+
const baseFileName = 'boolean' == typeof manifestOption ? '' : manifestOption.fileName || '';
|
|
66
|
+
const ensureExt = (name)=>name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
|
|
67
|
+
const withSuffix = (name, suffix)=>name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
|
|
68
|
+
const manifestFileName = baseFileName ? ensureExt(baseFileName) : sdk_namespaceObject.ManifestFileName;
|
|
69
|
+
const statsFileName = baseFileName ? withSuffix(manifestFileName, '-stats') : sdk_namespaceObject.StatsFileName;
|
|
53
70
|
return {
|
|
54
|
-
|
|
55
|
-
|
|
71
|
+
statsFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, statsFileName),
|
|
72
|
+
manifestFileName: (0, sdk_namespaceObject.simpleJoinRemoteEntry)(filePath, manifestFileName)
|
|
56
73
|
};
|
|
57
|
-
}
|
|
58
|
-
const JSON_EXT = ".json";
|
|
59
|
-
const filePath = typeof manifestOption === "boolean" ? "" : manifestOption.filePath || "";
|
|
60
|
-
const baseFileName = typeof manifestOption === "boolean" ? "" : manifestOption.fileName || "";
|
|
61
|
-
const ensureExt = (name) => name.endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}`;
|
|
62
|
-
const withSuffix = (name, suffix) => name.replace(JSON_EXT, `${suffix}${JSON_EXT}`);
|
|
63
|
-
const manifestFileName = baseFileName ? ensureExt(baseFileName) : import_sdk.ManifestFileName;
|
|
64
|
-
const statsFileName = baseFileName ? withSuffix(manifestFileName, "-stats") : import_sdk.StatsFileName;
|
|
65
|
-
return {
|
|
66
|
-
statsFileName: (0, import_sdk.simpleJoinRemoteEntry)(filePath, statsFileName),
|
|
67
|
-
manifestFileName: (0, import_sdk.simpleJoinRemoteEntry)(filePath, manifestFileName)
|
|
68
|
-
};
|
|
69
74
|
}
|
|
70
|
-
const mfSSRRsbuildPlugin = (pluginOptions)
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var _pluginOptions_csrConfig2, _pluginOptions_ssrConfig2;
|
|
151
|
-
const envName = envContext.name;
|
|
152
|
-
if (((_pluginOptions_csrConfig2 = pluginOptions.csrConfig) === null || _pluginOptions_csrConfig2 === void 0 ? void 0 : _pluginOptions_csrConfig2.manifest) !== false && csrEnv && envName === csrEnv) {
|
|
153
|
-
const browserAssets = collectAssets(assets, browserAssetFileNames, "browser");
|
|
154
|
-
if (browserAssets) {
|
|
155
|
-
pluginOptions.assetResources.browser = browserAssets;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (((_pluginOptions_ssrConfig2 = pluginOptions.ssrConfig) === null || _pluginOptions_ssrConfig2 === void 0 ? void 0 : _pluginOptions_ssrConfig2.manifest) !== false && ssrEnv && envName === ssrEnv) {
|
|
159
|
-
const nodeAssets = collectAssets(assets, nodeAssetFileNames, "node");
|
|
160
|
-
if (nodeAssets) {
|
|
161
|
-
pluginOptions.assetResources.node = nodeAssets;
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
};
|
|
168
|
-
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
169
|
-
name: "@modern-js/plugin-module-federation-ssr",
|
|
170
|
-
pre: [
|
|
171
|
-
"@modern-js/plugin-module-federation-config",
|
|
172
|
-
"@modern-js/plugin-module-federation"
|
|
173
|
-
],
|
|
174
|
-
setup: async (api) => {
|
|
175
|
-
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
176
|
-
const modernjsConfig = api.getConfig();
|
|
177
|
-
var _pluginOptions_userConfig_ssr;
|
|
178
|
-
const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
179
|
-
if (!enableSSR) {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
setEnv();
|
|
183
|
-
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
184
|
-
const { fetchServerQuery } = pluginOptions;
|
|
185
|
-
plugins.push({
|
|
186
|
-
name: "injectDataFetchFunction",
|
|
187
|
-
path: "@module-federation/modern-js/ssr-inject-data-fetch-function-plugin",
|
|
188
|
-
config: {
|
|
189
|
-
fetchServerQuery
|
|
190
|
-
}
|
|
191
|
-
});
|
|
192
|
-
if (!(0, import_utils.isDev)()) {
|
|
193
|
-
return {
|
|
194
|
-
entrypoint,
|
|
195
|
-
plugins
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
plugins.push({
|
|
199
|
-
name: "mfSSRDev",
|
|
200
|
-
path: "@module-federation/modern-js/ssr-dev-plugin",
|
|
201
|
-
config: {}
|
|
202
|
-
});
|
|
203
|
-
return {
|
|
204
|
-
entrypoint,
|
|
205
|
-
plugins
|
|
206
|
-
};
|
|
207
|
-
});
|
|
208
|
-
if (pluginOptions.ssrConfig.remotes) {
|
|
209
|
-
api._internalServerPlugins(({ plugins }) => {
|
|
210
|
-
plugins.push({
|
|
211
|
-
name: "@module-federation/modern-js/data-fetch-server-plugin",
|
|
212
|
-
options: {}
|
|
213
|
-
});
|
|
214
|
-
return {
|
|
215
|
-
plugins
|
|
216
|
-
};
|
|
217
|
-
});
|
|
218
|
-
}
|
|
219
|
-
api.modifyBundlerChain((chain) => {
|
|
220
|
-
const target = chain.get("target");
|
|
221
|
-
if ((0, import_utils3.skipByTarget)(target)) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
225
|
-
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
226
|
-
const isWeb = (0, import_utils3.isWebTarget)(target);
|
|
227
|
-
if (!isWeb) {
|
|
228
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
229
|
-
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
230
|
-
pluginOptions.ssrConfig
|
|
231
|
-
]).init((Plugin, args) => {
|
|
232
|
-
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
233
|
-
return pluginOptions.nodePlugin;
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
if (!isWeb) {
|
|
238
|
-
chain.target("async-node");
|
|
239
|
-
if ((0, import_utils.isDev)()) {
|
|
240
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
241
|
-
}
|
|
242
|
-
const userSSRConfig = pluginOptions.userConfig.ssr ? typeof pluginOptions.userConfig.ssr === "object" ? pluginOptions.userConfig.ssr : {} : {};
|
|
243
|
-
const publicPath = chain.output.get("publicPath");
|
|
244
|
-
if (userSSRConfig.distOutputDir && publicPath) {
|
|
245
|
-
chain.output.publicPath(`${publicPath}${userSSRConfig.distOutputDir}/`);
|
|
75
|
+
const mfSSRRsbuildPlugin = (pluginOptions)=>({
|
|
76
|
+
name: '@modern-js/plugin-mf-post-config',
|
|
77
|
+
pre: [
|
|
78
|
+
'@modern-js/builder-plugin-ssr'
|
|
79
|
+
],
|
|
80
|
+
setup (api) {
|
|
81
|
+
var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
|
|
82
|
+
if (pluginOptions.csrConfig.getPublicPath) return;
|
|
83
|
+
let csrOutputPath = '';
|
|
84
|
+
let ssrOutputPath = '';
|
|
85
|
+
let ssrEnv = '';
|
|
86
|
+
let csrEnv = '';
|
|
87
|
+
const browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
88
|
+
const nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
|
|
89
|
+
const collectAssets = (assets, fileNames, tag)=>{
|
|
90
|
+
const statsAsset = assets[fileNames.statsFileName];
|
|
91
|
+
const manifestAsset = assets[fileNames.manifestFileName];
|
|
92
|
+
if (!statsAsset || !manifestAsset) return;
|
|
93
|
+
try {
|
|
94
|
+
const statsRaw = statsAsset.source();
|
|
95
|
+
const manifestRaw = manifestAsset.source();
|
|
96
|
+
const statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
|
|
97
|
+
const manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
|
|
98
|
+
return {
|
|
99
|
+
stats: {
|
|
100
|
+
data: JSON.parse(statsContent),
|
|
101
|
+
filename: fileNames.statsFileName
|
|
102
|
+
},
|
|
103
|
+
manifest: {
|
|
104
|
+
data: JSON.parse(manifestContent),
|
|
105
|
+
filename: fileNames.manifestFileName
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
} catch (err) {
|
|
109
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
110
|
+
external_logger_js_default().error(`Failed to parse ${tag} manifest assets: ${message}`);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
api.modifyEnvironmentConfig((config, { name })=>{
|
|
115
|
+
const target = config.output.target;
|
|
116
|
+
if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return config;
|
|
117
|
+
if ((0, external_utils_js_namespaceObject.isWebTarget)(target)) {
|
|
118
|
+
csrOutputPath = config.output.distPath.root;
|
|
119
|
+
csrEnv = name;
|
|
120
|
+
} else {
|
|
121
|
+
ssrOutputPath = config.output.distPath.root;
|
|
122
|
+
ssrEnv = name;
|
|
123
|
+
}
|
|
124
|
+
return config;
|
|
125
|
+
});
|
|
126
|
+
const modifySSRPublicPath = (config, utils)=>{
|
|
127
|
+
if (ssrEnv !== utils.environment.name) return config;
|
|
128
|
+
const userSSRConfig = pluginOptions.userConfig.ssr ? 'object' == typeof pluginOptions.userConfig.ssr ? pluginOptions.userConfig.ssr : {} : {};
|
|
129
|
+
if (!userSSRConfig.distOutputDir) return;
|
|
130
|
+
config.output.publicPath = `${config.output.publicPath}${external_path_default().relative(csrOutputPath, ssrOutputPath)}/`;
|
|
131
|
+
return config;
|
|
132
|
+
};
|
|
133
|
+
api.modifyWebpackConfig((config, utils)=>{
|
|
134
|
+
modifySSRPublicPath(config, utils);
|
|
135
|
+
return config;
|
|
136
|
+
});
|
|
137
|
+
api.modifyRspackConfig((config, utils)=>{
|
|
138
|
+
modifySSRPublicPath(config, utils);
|
|
139
|
+
return config;
|
|
140
|
+
});
|
|
141
|
+
api.processAssets({
|
|
142
|
+
stage: 'report'
|
|
143
|
+
}, ({ assets, environment: envContext })=>{
|
|
144
|
+
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
145
|
+
const envName = envContext.name;
|
|
146
|
+
if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
|
|
147
|
+
const browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
|
|
148
|
+
if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
|
|
149
|
+
}
|
|
150
|
+
if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
|
|
151
|
+
const nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
|
|
152
|
+
if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
246
155
|
}
|
|
247
|
-
}
|
|
248
|
-
if ((0, import_utils.isDev)() && isWeb) {
|
|
249
|
-
chain.externals({
|
|
250
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
156
|
});
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
157
|
+
const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
158
|
+
name: '@modern-js/plugin-module-federation-ssr',
|
|
159
|
+
pre: [
|
|
160
|
+
'@modern-js/plugin-module-federation-config',
|
|
161
|
+
'@modern-js/plugin-module-federation'
|
|
258
162
|
],
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
163
|
+
setup: async (api)=>{
|
|
164
|
+
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
165
|
+
const modernjsConfig = api.getConfig();
|
|
166
|
+
var _ref;
|
|
167
|
+
const enableSSR = null != (_ref = null == (_pluginOptions_userConfig = pluginOptions.userConfig) ? void 0 : _pluginOptions_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr);
|
|
168
|
+
if (!enableSSR) return;
|
|
169
|
+
setEnv();
|
|
170
|
+
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
171
|
+
const { fetchServerQuery } = pluginOptions;
|
|
172
|
+
plugins.push({
|
|
173
|
+
name: 'injectDataFetchFunction',
|
|
174
|
+
path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
|
|
175
|
+
config: {
|
|
176
|
+
fetchServerQuery
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
if (!(0, external_utils_js_namespaceObject.isDev)()) return {
|
|
180
|
+
entrypoint,
|
|
181
|
+
plugins
|
|
182
|
+
};
|
|
183
|
+
plugins.push({
|
|
184
|
+
name: 'mfSSRDev',
|
|
185
|
+
path: '@module-federation/modern-js/ssr-dev-plugin',
|
|
186
|
+
config: {}
|
|
187
|
+
});
|
|
188
|
+
return {
|
|
189
|
+
entrypoint,
|
|
190
|
+
plugins
|
|
191
|
+
};
|
|
192
|
+
});
|
|
193
|
+
if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(({ plugins })=>{
|
|
194
|
+
plugins.push({
|
|
195
|
+
name: '@module-federation/modern-js/data-fetch-server-plugin',
|
|
196
|
+
options: {}
|
|
197
|
+
});
|
|
198
|
+
return {
|
|
199
|
+
plugins
|
|
200
|
+
};
|
|
201
|
+
});
|
|
202
|
+
api.modifyBundlerChain((chain)=>{
|
|
203
|
+
const target = chain.get('target');
|
|
204
|
+
if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
|
|
205
|
+
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
206
|
+
const MFPlugin = 'webpack' === bundlerType ? webpack_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
|
|
207
|
+
const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
|
|
208
|
+
if (!isWeb) {
|
|
209
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
210
|
+
pluginOptions.ssrConfig
|
|
211
|
+
]).init((Plugin, args)=>{
|
|
212
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
213
|
+
return pluginOptions.nodePlugin;
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
if (!isWeb) {
|
|
217
|
+
chain.target('async-node');
|
|
218
|
+
if ((0, external_utils_js_namespaceObject.isDev)()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin_default());
|
|
266
219
|
}
|
|
220
|
+
if ((0, external_utils_js_namespaceObject.isDev)() && isWeb) chain.externals({
|
|
221
|
+
'@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
api.config(()=>({
|
|
225
|
+
builderPlugins: [
|
|
226
|
+
mfSSRRsbuildPlugin(pluginOptions)
|
|
227
|
+
],
|
|
228
|
+
tools: {
|
|
229
|
+
devServer: {
|
|
230
|
+
before: [
|
|
231
|
+
(req, res, next)=>{
|
|
232
|
+
if (!enableSSR) return void next();
|
|
233
|
+
try {
|
|
234
|
+
var _req_url, _req_url1;
|
|
235
|
+
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
236
|
+
const filepath = external_path_default().join(process.cwd(), `dist${req.url}`);
|
|
237
|
+
external_fs_extra_default().statSync(filepath);
|
|
238
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
239
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
240
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
241
|
+
external_fs_extra_default().createReadStream(filepath).pipe(res);
|
|
242
|
+
} else next();
|
|
243
|
+
} catch (err) {
|
|
244
|
+
external_logger_js_default().debug(err);
|
|
245
|
+
next();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}));
|
|
252
|
+
const writeMergedManifest = ()=>{
|
|
253
|
+
const { distOutputDir, assetResources } = pluginOptions;
|
|
254
|
+
const browserAssets = assetResources.browser;
|
|
255
|
+
const nodeAssets = assetResources.node;
|
|
256
|
+
if (!distOutputDir || !browserAssets || !nodeAssets) return;
|
|
267
257
|
try {
|
|
268
|
-
|
|
269
|
-
if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.includes(".json")) && !((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes("hot-update"))) {
|
|
270
|
-
const filepath = import_path.default.join(process.cwd(), `dist${req.url}`);
|
|
271
|
-
import_fs_extra.default.statSync(filepath);
|
|
272
|
-
res.setHeader("Access-Control-Allow-Origin", "*");
|
|
273
|
-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
|
|
274
|
-
res.setHeader("Access-Control-Allow-Headers", "*");
|
|
275
|
-
import_fs_extra.default.createReadStream(filepath).pipe(res);
|
|
276
|
-
} else {
|
|
277
|
-
next();
|
|
278
|
-
}
|
|
258
|
+
(0, utils_namespaceObject.updateStatsAndManifest)(nodeAssets, browserAssets, distOutputDir);
|
|
279
259
|
} catch (err) {
|
|
280
|
-
|
|
281
|
-
next();
|
|
260
|
+
external_logger_js_default().error(err);
|
|
282
261
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
262
|
+
};
|
|
263
|
+
api.onAfterBuild(()=>{
|
|
264
|
+
writeMergedManifest();
|
|
265
|
+
});
|
|
266
|
+
api.onDevCompileDone(()=>{
|
|
267
|
+
writeMergedManifest();
|
|
268
|
+
});
|
|
286
269
|
}
|
|
287
|
-
};
|
|
288
270
|
});
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
api.onAfterBuild(() => {
|
|
303
|
-
writeMergedManifest();
|
|
304
|
-
});
|
|
305
|
-
api.onDevCompileDone(() => {
|
|
306
|
-
writeMergedManifest();
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
311
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
312
|
-
0 && (module.exports = {
|
|
313
|
-
CHAIN_MF_PLUGIN_ID,
|
|
314
|
-
moduleFederationSSRPlugin,
|
|
315
|
-
setEnv
|
|
271
|
+
const ssrPlugin = moduleFederationSSRPlugin;
|
|
272
|
+
exports.CHAIN_MF_PLUGIN_ID = __webpack_exports__.CHAIN_MF_PLUGIN_ID;
|
|
273
|
+
exports["default"] = __webpack_exports__["default"];
|
|
274
|
+
exports.moduleFederationSSRPlugin = __webpack_exports__.moduleFederationSSRPlugin;
|
|
275
|
+
exports.setEnv = __webpack_exports__.setEnv;
|
|
276
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
277
|
+
"CHAIN_MF_PLUGIN_ID",
|
|
278
|
+
"default",
|
|
279
|
+
"moduleFederationSSRPlugin",
|
|
280
|
+
"setEnv"
|
|
281
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
282
|
+
Object.defineProperty(exports, '__esModule', {
|
|
283
|
+
value: true
|
|
316
284
|
});
|