@module-federation/modern-js 0.0.0-release-v0-21-5-20251120103315 → 0.0.0-release-v0-23-0-20260123023720
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 +341 -377
- 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 +320 -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 +283 -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
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _instanceof__ } from "@swc/helpers/_/_instanceof";
|
|
3
|
+
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
4
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import path from "path";
|
|
6
|
+
import fs_extra from "fs-extra";
|
|
7
|
+
import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
|
|
8
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
9
|
+
import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
10
|
+
import logger from "../logger.mjs";
|
|
11
|
+
import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
12
|
+
import { updateStatsAndManifest } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
+
import { ManifestFileName, StatsFileName, simpleJoinRemoteEntry } from "@module-federation/sdk";
|
|
14
|
+
function setEnv() {
|
|
15
|
+
process.env['MF_SSR_PRJ'] = 'true';
|
|
16
|
+
}
|
|
17
|
+
var CHAIN_MF_PLUGIN_ID = 'plugin-module-federation-server';
|
|
18
|
+
function getManifestAssetFileNames(manifestOption) {
|
|
19
|
+
if (!manifestOption) return {
|
|
20
|
+
statsFileName: StatsFileName,
|
|
21
|
+
manifestFileName: ManifestFileName
|
|
22
|
+
};
|
|
23
|
+
var JSON_EXT = '.json';
|
|
24
|
+
var filePath = 'boolean' == typeof manifestOption ? '' : manifestOption.filePath || '';
|
|
25
|
+
var baseFileName = 'boolean' == typeof manifestOption ? '' : manifestOption.fileName || '';
|
|
26
|
+
var ensureExt = function(name) {
|
|
27
|
+
return name.endsWith(JSON_EXT) ? name : "".concat(name).concat(JSON_EXT);
|
|
28
|
+
};
|
|
29
|
+
var withSuffix = function(name, suffix) {
|
|
30
|
+
return name.replace(JSON_EXT, "".concat(suffix).concat(JSON_EXT));
|
|
31
|
+
};
|
|
32
|
+
var manifestFileName = baseFileName ? ensureExt(baseFileName) : ManifestFileName;
|
|
33
|
+
var statsFileName = baseFileName ? withSuffix(manifestFileName, '-stats') : StatsFileName;
|
|
34
|
+
return {
|
|
35
|
+
statsFileName: simpleJoinRemoteEntry(filePath, statsFileName),
|
|
36
|
+
manifestFileName: simpleJoinRemoteEntry(filePath, manifestFileName)
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var mfSSRRsbuildPlugin = function(pluginOptions) {
|
|
40
|
+
return {
|
|
41
|
+
name: '@modern-js/plugin-mf-post-config',
|
|
42
|
+
pre: [
|
|
43
|
+
'@modern-js/builder-plugin-ssr'
|
|
44
|
+
],
|
|
45
|
+
setup: function(api) {
|
|
46
|
+
var _pluginOptions_csrConfig, _pluginOptions_assetFileNames, _pluginOptions_ssrConfig;
|
|
47
|
+
if (pluginOptions.csrConfig.getPublicPath) return;
|
|
48
|
+
var csrOutputPath = '';
|
|
49
|
+
var ssrOutputPath = '';
|
|
50
|
+
var ssrEnv = '';
|
|
51
|
+
var csrEnv = '';
|
|
52
|
+
var browserAssetFileNames = pluginOptions.assetFileNames.browser || getManifestAssetFileNames(null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest);
|
|
53
|
+
var nodeAssetFileNames = (null == (_pluginOptions_assetFileNames = pluginOptions.assetFileNames) ? void 0 : _pluginOptions_assetFileNames.node) || getManifestAssetFileNames(null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest);
|
|
54
|
+
var collectAssets = function(assets, fileNames, tag) {
|
|
55
|
+
var statsAsset = assets[fileNames.statsFileName];
|
|
56
|
+
var manifestAsset = assets[fileNames.manifestFileName];
|
|
57
|
+
if (!statsAsset || !manifestAsset) return;
|
|
58
|
+
try {
|
|
59
|
+
var statsRaw = statsAsset.source();
|
|
60
|
+
var manifestRaw = manifestAsset.source();
|
|
61
|
+
var statsContent = 'string' == typeof statsRaw ? statsRaw : statsRaw.toString();
|
|
62
|
+
var manifestContent = 'string' == typeof manifestRaw ? manifestRaw : manifestRaw.toString();
|
|
63
|
+
return {
|
|
64
|
+
stats: {
|
|
65
|
+
data: JSON.parse(statsContent),
|
|
66
|
+
filename: fileNames.statsFileName
|
|
67
|
+
},
|
|
68
|
+
manifest: {
|
|
69
|
+
data: JSON.parse(manifestContent),
|
|
70
|
+
filename: fileNames.manifestFileName
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
var message = _instanceof__(err, Error) ? err.message : String(err);
|
|
75
|
+
logger.error("Failed to parse ".concat(tag, " manifest assets: ").concat(message));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
api.modifyEnvironmentConfig(function(config, param) {
|
|
80
|
+
var name = param.name;
|
|
81
|
+
var target = config.output.target;
|
|
82
|
+
if (skipByTarget(target)) return config;
|
|
83
|
+
if (isWebTarget(target)) {
|
|
84
|
+
csrOutputPath = config.output.distPath.root;
|
|
85
|
+
csrEnv = name;
|
|
86
|
+
} else {
|
|
87
|
+
ssrOutputPath = config.output.distPath.root;
|
|
88
|
+
ssrEnv = name;
|
|
89
|
+
}
|
|
90
|
+
return config;
|
|
91
|
+
});
|
|
92
|
+
var modifySSRPublicPath = function(config, utils) {
|
|
93
|
+
if (ssrEnv !== utils.environment.name) return config;
|
|
94
|
+
var userSSRConfig = pluginOptions.userConfig.ssr ? 'object' === _type_of__(pluginOptions.userConfig.ssr) ? pluginOptions.userConfig.ssr : {} : {};
|
|
95
|
+
if (!userSSRConfig.distOutputDir) return;
|
|
96
|
+
config.output.publicPath = "".concat(config.output.publicPath).concat(path.relative(csrOutputPath, ssrOutputPath), "/");
|
|
97
|
+
return config;
|
|
98
|
+
};
|
|
99
|
+
api.modifyWebpackConfig(function(config, utils) {
|
|
100
|
+
modifySSRPublicPath(config, utils);
|
|
101
|
+
return config;
|
|
102
|
+
});
|
|
103
|
+
api.modifyRspackConfig(function(config, utils) {
|
|
104
|
+
modifySSRPublicPath(config, utils);
|
|
105
|
+
return config;
|
|
106
|
+
});
|
|
107
|
+
api.processAssets({
|
|
108
|
+
stage: 'report'
|
|
109
|
+
}, function(param) {
|
|
110
|
+
var assets = param.assets, envContext = param.environment;
|
|
111
|
+
var _pluginOptions_csrConfig, _pluginOptions_ssrConfig;
|
|
112
|
+
var envName = envContext.name;
|
|
113
|
+
if ((null == (_pluginOptions_csrConfig = pluginOptions.csrConfig) ? void 0 : _pluginOptions_csrConfig.manifest) !== false && csrEnv && envName === csrEnv) {
|
|
114
|
+
var browserAssets = collectAssets(assets, browserAssetFileNames, 'browser');
|
|
115
|
+
if (browserAssets) pluginOptions.assetResources.browser = browserAssets;
|
|
116
|
+
}
|
|
117
|
+
if ((null == (_pluginOptions_ssrConfig = pluginOptions.ssrConfig) ? void 0 : _pluginOptions_ssrConfig.manifest) !== false && ssrEnv && envName === ssrEnv) {
|
|
118
|
+
var nodeAssets = collectAssets(assets, nodeAssetFileNames, 'node');
|
|
119
|
+
if (nodeAssets) pluginOptions.assetResources.node = nodeAssets;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
126
|
+
return {
|
|
127
|
+
name: '@modern-js/plugin-module-federation-ssr',
|
|
128
|
+
pre: [
|
|
129
|
+
'@modern-js/plugin-module-federation-config',
|
|
130
|
+
'@modern-js/plugin-module-federation'
|
|
131
|
+
],
|
|
132
|
+
setup: function(api) {
|
|
133
|
+
return _(function() {
|
|
134
|
+
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, _ref, enableSSR, writeMergedManifest;
|
|
135
|
+
return _ts_generator__(this, function(_state) {
|
|
136
|
+
modernjsConfig = api.getConfig();
|
|
137
|
+
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);
|
|
138
|
+
if (!enableSSR) return [
|
|
139
|
+
2
|
|
140
|
+
];
|
|
141
|
+
setEnv();
|
|
142
|
+
api._internalRuntimePlugins(function(param) {
|
|
143
|
+
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
144
|
+
var fetchServerQuery = pluginOptions.fetchServerQuery;
|
|
145
|
+
plugins.push({
|
|
146
|
+
name: 'injectDataFetchFunction',
|
|
147
|
+
path: '@module-federation/modern-js/ssr-inject-data-fetch-function-plugin',
|
|
148
|
+
config: {
|
|
149
|
+
fetchServerQuery: fetchServerQuery
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
if (!isDev()) return {
|
|
153
|
+
entrypoint: entrypoint,
|
|
154
|
+
plugins: plugins
|
|
155
|
+
};
|
|
156
|
+
plugins.push({
|
|
157
|
+
name: 'mfSSRDev',
|
|
158
|
+
path: '@module-federation/modern-js/ssr-dev-plugin',
|
|
159
|
+
config: {}
|
|
160
|
+
});
|
|
161
|
+
return {
|
|
162
|
+
entrypoint: entrypoint,
|
|
163
|
+
plugins: plugins
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
if (pluginOptions.ssrConfig.remotes) api._internalServerPlugins(function(param) {
|
|
167
|
+
var plugins = param.plugins;
|
|
168
|
+
plugins.push({
|
|
169
|
+
name: '@module-federation/modern-js/data-fetch-server-plugin',
|
|
170
|
+
options: {}
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
plugins: plugins
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
api.modifyBundlerChain(function(chain) {
|
|
177
|
+
var target = chain.get('target');
|
|
178
|
+
if (skipByTarget(target)) return;
|
|
179
|
+
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
180
|
+
var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
181
|
+
var isWeb = isWebTarget(target);
|
|
182
|
+
if (!isWeb) {
|
|
183
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
184
|
+
pluginOptions.ssrConfig
|
|
185
|
+
]).init(function(Plugin, args) {
|
|
186
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
187
|
+
return pluginOptions.nodePlugin;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (!isWeb) {
|
|
191
|
+
chain.target('async-node');
|
|
192
|
+
if (isDev()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin);
|
|
193
|
+
}
|
|
194
|
+
if (isDev() && isWeb) chain.externals({
|
|
195
|
+
'@module-federation/node/utils': 'NOT_USED_IN_BROWSER'
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
api.config(function() {
|
|
199
|
+
return {
|
|
200
|
+
builderPlugins: [
|
|
201
|
+
mfSSRRsbuildPlugin(pluginOptions)
|
|
202
|
+
],
|
|
203
|
+
tools: {
|
|
204
|
+
devServer: {
|
|
205
|
+
before: [
|
|
206
|
+
function(req, res, next) {
|
|
207
|
+
if (!enableSSR) return void next();
|
|
208
|
+
try {
|
|
209
|
+
var _req_url, _req_url1;
|
|
210
|
+
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
211
|
+
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
212
|
+
fs_extra.statSync(filepath);
|
|
213
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
214
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
215
|
+
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
216
|
+
fs_extra.createReadStream(filepath).pipe(res);
|
|
217
|
+
} else next();
|
|
218
|
+
} catch (err) {
|
|
219
|
+
logger.debug(err);
|
|
220
|
+
next();
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
]
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
});
|
|
228
|
+
writeMergedManifest = function() {
|
|
229
|
+
var distOutputDir = pluginOptions.distOutputDir, assetResources = pluginOptions.assetResources;
|
|
230
|
+
var browserAssets = assetResources.browser;
|
|
231
|
+
var nodeAssets = assetResources.node;
|
|
232
|
+
if (!distOutputDir || !browserAssets || !nodeAssets) return;
|
|
233
|
+
try {
|
|
234
|
+
updateStatsAndManifest(nodeAssets, browserAssets, distOutputDir);
|
|
235
|
+
} catch (err) {
|
|
236
|
+
logger.error(err);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
api.onAfterBuild(function() {
|
|
240
|
+
writeMergedManifest();
|
|
241
|
+
});
|
|
242
|
+
api.onDevCompileDone(function() {
|
|
243
|
+
writeMergedManifest();
|
|
244
|
+
});
|
|
245
|
+
return [
|
|
246
|
+
2
|
|
247
|
+
];
|
|
248
|
+
});
|
|
249
|
+
})();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
var ssrPlugin = moduleFederationSSRPlugin;
|
|
254
|
+
export { CHAIN_MF_PLUGIN_ID, ssrPlugin as default, moduleFederationSSRPlugin, setEnv };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
var localIpv4 = '127.0.0.1';
|
|
3
|
+
var getIpv4Interfaces = function() {
|
|
4
|
+
try {
|
|
5
|
+
var interfaces = os.networkInterfaces();
|
|
6
|
+
var ipv4Interfaces = [];
|
|
7
|
+
Object.values(interfaces).forEach(function(detail) {
|
|
8
|
+
null == detail || detail.forEach(function(detail) {
|
|
9
|
+
var familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
|
|
10
|
+
if (detail.family === familyV4Value && detail.address !== localIpv4) ipv4Interfaces.push(detail);
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
return ipv4Interfaces;
|
|
14
|
+
} catch (_err) {
|
|
15
|
+
return [];
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var getIPV4 = function() {
|
|
19
|
+
var ipv4Interfaces = getIpv4Interfaces();
|
|
20
|
+
var ipv4Interface = ipv4Interfaces[0] || {
|
|
21
|
+
address: localIpv4
|
|
22
|
+
};
|
|
23
|
+
return ipv4Interface.address;
|
|
24
|
+
};
|
|
25
|
+
var isWebTarget = function(target) {
|
|
26
|
+
var WEB_TARGET = 'web';
|
|
27
|
+
if (Array.isArray(target)) return target.includes(WEB_TARGET);
|
|
28
|
+
if ('string' == typeof target) return target === WEB_TARGET;
|
|
29
|
+
return false;
|
|
30
|
+
};
|
|
31
|
+
var skipByTarget = function(target) {
|
|
32
|
+
var IGNORE_TARGET = 'webworker';
|
|
33
|
+
if (Array.isArray(target)) return target.includes(IGNORE_TARGET);
|
|
34
|
+
if ('string' == typeof target) return target === IGNORE_TARGET;
|
|
35
|
+
return false;
|
|
36
|
+
};
|
|
37
|
+
function isDev() {
|
|
38
|
+
return 'development' === process.env.NODE_ENV;
|
|
39
|
+
}
|
|
40
|
+
export { getIPV4, isDev, isWebTarget, skipByTarget };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _class_call_check__ } from "@swc/helpers/_/_class_call_check";
|
|
3
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import fs_extra from "fs-extra";
|
|
5
|
+
import { LRUCache } from "lru-cache";
|
|
6
|
+
var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
7
|
+
"use strict";
|
|
8
|
+
function FileCache() {
|
|
9
|
+
_class_call_check__(this, FileCache);
|
|
10
|
+
this.cache = new LRUCache({
|
|
11
|
+
maxSize: 209715200
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
var _proto = FileCache.prototype;
|
|
15
|
+
_proto.getFile = function(filepath) {
|
|
16
|
+
return _(function() {
|
|
17
|
+
var stat, currentModified, cachedEntry, content, newEntry;
|
|
18
|
+
return _ts_generator__(this, function(_state) {
|
|
19
|
+
switch(_state.label){
|
|
20
|
+
case 0:
|
|
21
|
+
return [
|
|
22
|
+
4,
|
|
23
|
+
fs_extra.pathExists(filepath)
|
|
24
|
+
];
|
|
25
|
+
case 1:
|
|
26
|
+
if (!_state.sent()) return [
|
|
27
|
+
2,
|
|
28
|
+
null
|
|
29
|
+
];
|
|
30
|
+
_state.label = 2;
|
|
31
|
+
case 2:
|
|
32
|
+
_state.trys.push([
|
|
33
|
+
2,
|
|
34
|
+
5,
|
|
35
|
+
,
|
|
36
|
+
6
|
|
37
|
+
]);
|
|
38
|
+
return [
|
|
39
|
+
4,
|
|
40
|
+
fs_extra.lstat(filepath)
|
|
41
|
+
];
|
|
42
|
+
case 3:
|
|
43
|
+
stat = _state.sent();
|
|
44
|
+
currentModified = stat.mtimeMs;
|
|
45
|
+
cachedEntry = this.cache.get(filepath);
|
|
46
|
+
if (cachedEntry && currentModified <= cachedEntry.lastModified) return [
|
|
47
|
+
2,
|
|
48
|
+
{
|
|
49
|
+
content: cachedEntry.content,
|
|
50
|
+
lastModified: cachedEntry.lastModified
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
return [
|
|
54
|
+
4,
|
|
55
|
+
fs_extra.readFile(filepath, 'utf-8')
|
|
56
|
+
];
|
|
57
|
+
case 4:
|
|
58
|
+
content = _state.sent();
|
|
59
|
+
newEntry = {
|
|
60
|
+
content: content,
|
|
61
|
+
lastModified: currentModified
|
|
62
|
+
};
|
|
63
|
+
this.cache.set(filepath, newEntry, {
|
|
64
|
+
size: stat.size || content.length
|
|
65
|
+
});
|
|
66
|
+
return [
|
|
67
|
+
2,
|
|
68
|
+
{
|
|
69
|
+
content: content,
|
|
70
|
+
lastModified: currentModified
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
case 5:
|
|
74
|
+
_state.sent();
|
|
75
|
+
return [
|
|
76
|
+
2,
|
|
77
|
+
null
|
|
78
|
+
];
|
|
79
|
+
case 6:
|
|
80
|
+
return [
|
|
81
|
+
2
|
|
82
|
+
];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}).call(this);
|
|
86
|
+
};
|
|
87
|
+
return FileCache;
|
|
88
|
+
}();
|
|
89
|
+
var fileCache = new fileCache_FileCache();
|
|
90
|
+
export { fileCache_FileCache as FileCache, fileCache };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createCorsMiddleware, createStaticMiddleware } from "./staticMiddleware.mjs";
|
|
2
|
+
var staticServePlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: '@modern-js/module-federation/server',
|
|
5
|
+
setup: function(api) {
|
|
6
|
+
api.onPrepare(function() {
|
|
7
|
+
var _config_output, _config_server;
|
|
8
|
+
if ('development' === process.env.NODE_ENV) return;
|
|
9
|
+
var middlewares = api.getServerContext().middlewares;
|
|
10
|
+
var config = api.getServerConfig();
|
|
11
|
+
var assetPrefix = (null == (_config_output = config.output) ? void 0 : _config_output.assetPrefix) || '';
|
|
12
|
+
if (null == (_config_server = config.server) ? void 0 : _config_server.ssr) {
|
|
13
|
+
var context = api.getServerContext();
|
|
14
|
+
var pwd = context.distDirectory;
|
|
15
|
+
var serverStaticMiddleware = createStaticMiddleware({
|
|
16
|
+
assetPrefix: assetPrefix,
|
|
17
|
+
pwd: pwd
|
|
18
|
+
});
|
|
19
|
+
middlewares.push({
|
|
20
|
+
name: 'module-federation-serve-manifest',
|
|
21
|
+
handler: serverStaticMiddleware
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
if (process.env.MODERN_MF_AUTO_CORS) {
|
|
25
|
+
var corsMiddleware = createCorsMiddleware();
|
|
26
|
+
middlewares.push({
|
|
27
|
+
name: 'module-federation-cors',
|
|
28
|
+
handler: corsMiddleware
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
var server = staticServePlugin;
|
|
36
|
+
export { server as default, staticServePlugin };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import fs_extra from "fs-extra";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import { fileCache } from "./fileCache.mjs";
|
|
6
|
+
var bundlesAssetPrefix = '/bundles';
|
|
7
|
+
var removeHost = function(url) {
|
|
8
|
+
try {
|
|
9
|
+
var hasProtocol = url.includes('://');
|
|
10
|
+
var hasDomain = hasProtocol || url.startsWith('//');
|
|
11
|
+
var pathname = hasDomain ? new URL(hasProtocol ? url : "http:".concat(url)).pathname : url;
|
|
12
|
+
return pathname;
|
|
13
|
+
} catch (e) {
|
|
14
|
+
return url;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var createStaticMiddleware = function(options) {
|
|
18
|
+
var assetPrefix = options.assetPrefix, pwd = options.pwd;
|
|
19
|
+
return function(c, next) {
|
|
20
|
+
return _(function() {
|
|
21
|
+
var pathname, prefixWithoutHost, prefixWithBundle, pathnameWithoutPrefix, filepath, fileResult;
|
|
22
|
+
return _ts_generator__(this, function(_state) {
|
|
23
|
+
switch(_state.label){
|
|
24
|
+
case 0:
|
|
25
|
+
pathname = c.req.path;
|
|
26
|
+
if ('.js' !== path.extname(pathname)) return [
|
|
27
|
+
2,
|
|
28
|
+
next()
|
|
29
|
+
];
|
|
30
|
+
prefixWithoutHost = removeHost(assetPrefix);
|
|
31
|
+
prefixWithBundle = path.join(prefixWithoutHost, bundlesAssetPrefix);
|
|
32
|
+
if (!pathname.startsWith(prefixWithBundle)) return [
|
|
33
|
+
2,
|
|
34
|
+
next()
|
|
35
|
+
];
|
|
36
|
+
pathnameWithoutPrefix = pathname.replace(prefixWithBundle, '');
|
|
37
|
+
filepath = path.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
|
|
38
|
+
return [
|
|
39
|
+
4,
|
|
40
|
+
fs_extra.pathExists(filepath)
|
|
41
|
+
];
|
|
42
|
+
case 1:
|
|
43
|
+
if (!_state.sent()) return [
|
|
44
|
+
2,
|
|
45
|
+
next()
|
|
46
|
+
];
|
|
47
|
+
return [
|
|
48
|
+
4,
|
|
49
|
+
fileCache.getFile(filepath)
|
|
50
|
+
];
|
|
51
|
+
case 2:
|
|
52
|
+
fileResult = _state.sent();
|
|
53
|
+
if (!fileResult) return [
|
|
54
|
+
2,
|
|
55
|
+
next()
|
|
56
|
+
];
|
|
57
|
+
c.header('Content-Type', "application/javascript");
|
|
58
|
+
c.header('Content-Length', String(fileResult.content.length));
|
|
59
|
+
return [
|
|
60
|
+
2,
|
|
61
|
+
c.body(fileResult.content, 200)
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
})();
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
var createCorsMiddleware = function() {
|
|
69
|
+
return function(c, next) {
|
|
70
|
+
return _(function() {
|
|
71
|
+
var pathname;
|
|
72
|
+
return _ts_generator__(this, function(_state) {
|
|
73
|
+
pathname = c.req.path;
|
|
74
|
+
if (path.extname(pathname)) {
|
|
75
|
+
c.header('Access-Control-Allow-Origin', '*');
|
|
76
|
+
c.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
77
|
+
c.header('Access-Control-Allow-Headers', '*');
|
|
78
|
+
}
|
|
79
|
+
return [
|
|
80
|
+
2,
|
|
81
|
+
next()
|
|
82
|
+
];
|
|
83
|
+
});
|
|
84
|
+
})();
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
export { createCorsMiddleware, createStaticMiddleware };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_tagged_template_literal";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
function SSRLiveReload_templateObject() {
|
|
4
|
+
var data = _([
|
|
5
|
+
"\n if(",
|
|
6
|
+
"){\n location.reload();\n }\n "
|
|
7
|
+
]);
|
|
8
|
+
SSRLiveReload_templateObject = function() {
|
|
9
|
+
return data;
|
|
10
|
+
};
|
|
11
|
+
return data;
|
|
12
|
+
}
|
|
13
|
+
function SSRLiveReload() {
|
|
14
|
+
if ('development' !== process.env.NODE_ENV) return null;
|
|
15
|
+
return /*#__PURE__*/ jsx("script", {
|
|
16
|
+
suppressHydrationWarning: true,
|
|
17
|
+
dangerouslySetInnerHTML: {
|
|
18
|
+
__html: String.raw(SSRLiveReload_templateObject(), globalThis.shouldUpdate)
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
export { SSRLiveReload };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { SSRLiveReload } from "./SSRLiveReload.mjs";
|
|
6
|
+
import { flushDataFetch } from "@module-federation/bridge-react/lazy-utils";
|
|
7
|
+
var mfSSRDevPlugin = function() {
|
|
8
|
+
return {
|
|
9
|
+
name: '@module-federation/modern-js',
|
|
10
|
+
setup: function(api) {
|
|
11
|
+
api.onBeforeRender(function() {
|
|
12
|
+
return _(function() {
|
|
13
|
+
var nodeUtils, shouldUpdate;
|
|
14
|
+
return _ts_generator__(this, function(_state) {
|
|
15
|
+
switch(_state.label){
|
|
16
|
+
case 0:
|
|
17
|
+
if ("u" > typeof window) return [
|
|
18
|
+
2
|
|
19
|
+
];
|
|
20
|
+
globalThis.shouldUpdate = false;
|
|
21
|
+
return [
|
|
22
|
+
4,
|
|
23
|
+
import("@module-federation/node/utils")
|
|
24
|
+
];
|
|
25
|
+
case 1:
|
|
26
|
+
nodeUtils = _state.sent();
|
|
27
|
+
return [
|
|
28
|
+
4,
|
|
29
|
+
nodeUtils.revalidate()
|
|
30
|
+
];
|
|
31
|
+
case 2:
|
|
32
|
+
shouldUpdate = _state.sent();
|
|
33
|
+
console.log('shouldUpdate: ', shouldUpdate);
|
|
34
|
+
if (!shouldUpdate) return [
|
|
35
|
+
3,
|
|
36
|
+
4
|
|
37
|
+
];
|
|
38
|
+
console.log('should RELOAD', shouldUpdate);
|
|
39
|
+
return [
|
|
40
|
+
4,
|
|
41
|
+
nodeUtils.flushChunks()
|
|
42
|
+
];
|
|
43
|
+
case 3:
|
|
44
|
+
_state.sent();
|
|
45
|
+
flushDataFetch();
|
|
46
|
+
globalThis.shouldUpdate = true;
|
|
47
|
+
_state.label = 4;
|
|
48
|
+
case 4:
|
|
49
|
+
return [
|
|
50
|
+
2
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
})();
|
|
55
|
+
});
|
|
56
|
+
api.wrapRoot(function(App) {
|
|
57
|
+
var AppWrapper = function(props) {
|
|
58
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
59
|
+
children: [
|
|
60
|
+
/*#__PURE__*/ jsx(SSRLiveReload, {}),
|
|
61
|
+
/*#__PURE__*/ jsx(App, _object_spread__({}, props))
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
return AppWrapper;
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
export { mfSSRDevPlugin };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { callDataFetch } from "@module-federation/bridge-react/data-fetch-utils";
|
|
4
|
+
import { setSSREnv } from "@module-federation/bridge-react/lazy-utils";
|
|
5
|
+
var injectDataFetchFunctionPlugin = function(param) {
|
|
6
|
+
var fetchServerQuery = param.fetchServerQuery;
|
|
7
|
+
return {
|
|
8
|
+
name: '@module-federation/inject-data-fetch-function-plugin',
|
|
9
|
+
setup: function(api) {
|
|
10
|
+
api.onBeforeRender(function() {
|
|
11
|
+
return _(function() {
|
|
12
|
+
return _ts_generator__(this, function(_state) {
|
|
13
|
+
switch(_state.label){
|
|
14
|
+
case 0:
|
|
15
|
+
setSSREnv({
|
|
16
|
+
fetchServerQuery: fetchServerQuery
|
|
17
|
+
});
|
|
18
|
+
return [
|
|
19
|
+
4,
|
|
20
|
+
callDataFetch()
|
|
21
|
+
];
|
|
22
|
+
case 1:
|
|
23
|
+
_state.sent();
|
|
24
|
+
return [
|
|
25
|
+
2
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
})();
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export { injectDataFetchFunctionPlugin };
|