@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,320 @@
|
|
|
1
|
+
import * as __rspack_external_jiti from "jiti";
|
|
2
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
3
|
+
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
4
|
+
import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props";
|
|
5
|
+
import { _ as _to_consumable_array__ } from "@swc/helpers/_/_to_consumable_array";
|
|
6
|
+
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
7
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
8
|
+
import path from "path";
|
|
9
|
+
import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
10
|
+
import { encodeName } from "@module-federation/sdk";
|
|
11
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
12
|
+
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
13
|
+
import logger from "../logger.mjs";
|
|
14
|
+
var __webpack_modules__ = {
|
|
15
|
+
jiti: function(module) {
|
|
16
|
+
module.exports = __rspack_external_jiti;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
var __webpack_module_cache__ = {};
|
|
20
|
+
function __webpack_require__(moduleId) {
|
|
21
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
22
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
23
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
24
|
+
exports: {}
|
|
25
|
+
};
|
|
26
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
27
|
+
return module.exports;
|
|
28
|
+
}
|
|
29
|
+
var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
30
|
+
function setEnv(enableSSR) {
|
|
31
|
+
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
32
|
+
}
|
|
33
|
+
var getMFConfig = function(userConfig) {
|
|
34
|
+
return _(function() {
|
|
35
|
+
var config, configPath, mfConfigPath, createJiti, jit, configModule, resolvedConfig;
|
|
36
|
+
return _ts_generator__(this, function(_state) {
|
|
37
|
+
switch(_state.label){
|
|
38
|
+
case 0:
|
|
39
|
+
config = userConfig.config, configPath = userConfig.configPath;
|
|
40
|
+
if (config) return [
|
|
41
|
+
2,
|
|
42
|
+
config
|
|
43
|
+
];
|
|
44
|
+
mfConfigPath = configPath ? configPath : defaultPath;
|
|
45
|
+
createJiti = __webpack_require__("jiti").createJiti;
|
|
46
|
+
jit = createJiti(__filename, {
|
|
47
|
+
interopDefault: true,
|
|
48
|
+
esmResolve: true
|
|
49
|
+
});
|
|
50
|
+
return [
|
|
51
|
+
4,
|
|
52
|
+
jit(mfConfigPath)
|
|
53
|
+
];
|
|
54
|
+
case 1:
|
|
55
|
+
configModule = _state.sent();
|
|
56
|
+
resolvedConfig = configModule && (void 0 === configModule ? "undefined" : _type_of__(configModule)) === 'object' && 'default' in configModule ? configModule.default : configModule;
|
|
57
|
+
return [
|
|
58
|
+
2,
|
|
59
|
+
resolvedConfig
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
})();
|
|
64
|
+
};
|
|
65
|
+
var injectRuntimePlugins = function(runtimePlugin, runtimePlugins) {
|
|
66
|
+
var pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
67
|
+
var hasPlugin = runtimePlugins.some(function(existingPlugin) {
|
|
68
|
+
if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
|
|
69
|
+
return existingPlugin[0] === pluginName;
|
|
70
|
+
});
|
|
71
|
+
if (!hasPlugin) runtimePlugins.push(runtimePlugin);
|
|
72
|
+
};
|
|
73
|
+
var replaceRemoteUrl = function(mfConfig, remoteIpStrategy) {
|
|
74
|
+
if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
|
|
75
|
+
if (!mfConfig.remotes) return;
|
|
76
|
+
var ipv4 = getIPV4();
|
|
77
|
+
var handleRemoteObject = function(remoteObject) {
|
|
78
|
+
Object.keys(remoteObject).forEach(function(remoteKey) {
|
|
79
|
+
var remote = remoteObject[remoteKey];
|
|
80
|
+
if (Array.isArray(remote)) return;
|
|
81
|
+
if ('string' == typeof remote && remote.includes(LOCALHOST)) remoteObject[remoteKey] = remote.replace(LOCALHOST, ipv4);
|
|
82
|
+
if ((void 0 === remote ? "undefined" : _type_of__(remote)) === 'object' && !Array.isArray(remote.external) && remote.external.includes(LOCALHOST)) remote.external = remote.external.replace(LOCALHOST, ipv4);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach(function(remoteObject) {
|
|
86
|
+
if ('string' == typeof remoteObject) return;
|
|
87
|
+
handleRemoteObject(remoteObject);
|
|
88
|
+
});
|
|
89
|
+
else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
|
|
90
|
+
};
|
|
91
|
+
var patchDTSConfig = function(mfConfig, isServer) {
|
|
92
|
+
if (isServer) return;
|
|
93
|
+
var ModernJSRuntime = '@module-federation/modern-js/runtime';
|
|
94
|
+
if (false !== mfConfig.dts) {
|
|
95
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
96
|
+
if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
|
|
97
|
+
consumeTypes: {
|
|
98
|
+
runtimePkgs: [
|
|
99
|
+
ModernJSRuntime
|
|
100
|
+
]
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
104
|
+
var _mfConfig_dts2;
|
|
105
|
+
if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
|
|
106
|
+
runtimePkgs: [
|
|
107
|
+
ModernJSRuntime
|
|
108
|
+
]
|
|
109
|
+
};
|
|
110
|
+
else {
|
|
111
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
112
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
var patchMFConfig = function(mfConfig, isServer, remoteIpStrategy, enableSSR) {
|
|
118
|
+
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
119
|
+
addDataFetchExposes(mfConfig.exposes, isServer);
|
|
120
|
+
if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
|
|
121
|
+
if (!mfConfig.name) throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
122
|
+
var runtimePlugins = _to_consumable_array__(mfConfig.runtimePlugins || []);
|
|
123
|
+
patchDTSConfig(mfConfig, isServer);
|
|
124
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
|
|
125
|
+
if (enableSSR && isDev()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
|
|
126
|
+
if (isServer) {
|
|
127
|
+
injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
|
|
128
|
+
if (isDev()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
|
|
129
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
|
|
130
|
+
if (mfConfig.library) {
|
|
131
|
+
if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
|
|
132
|
+
if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
|
|
133
|
+
} else mfConfig.library = {
|
|
134
|
+
type: 'commonjs-module',
|
|
135
|
+
name: mfConfig.name
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
139
|
+
if (!isServer) {
|
|
140
|
+
var _mfConfig_library;
|
|
141
|
+
if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
|
|
142
|
+
return mfConfig;
|
|
143
|
+
}
|
|
144
|
+
mfConfig.dts = false;
|
|
145
|
+
mfConfig.dev = false;
|
|
146
|
+
return mfConfig;
|
|
147
|
+
};
|
|
148
|
+
function patchIgnoreWarning(chain) {
|
|
149
|
+
var ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
150
|
+
var ignoredMsgs = [
|
|
151
|
+
"external script",
|
|
152
|
+
'process.env.WS_NO_BUFFER_UTIL',
|
|
153
|
+
"Can't resolve 'utf-8-validate"
|
|
154
|
+
];
|
|
155
|
+
ignoreWarnings.push(function(warning) {
|
|
156
|
+
if (ignoredMsgs.some(function(msg) {
|
|
157
|
+
return warning.message.includes(msg);
|
|
158
|
+
})) return true;
|
|
159
|
+
return false;
|
|
160
|
+
});
|
|
161
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
162
|
+
}
|
|
163
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
164
|
+
var watchOptions = chain.get('watchOptions');
|
|
165
|
+
if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
|
|
166
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
167
|
+
});
|
|
168
|
+
var ignored = watchOptions.ignored;
|
|
169
|
+
var DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
|
|
170
|
+
if (Array.isArray(ignored)) {
|
|
171
|
+
if (false !== mfConfig.dts && 'object' === _type_of__(mfConfig.dts) && 'object' === _type_of__(mfConfig.dts.consumeTypes) && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
172
|
+
ignored: ignored.concat("**/".concat(mfConfig.dts.consumeTypes.remoteTypesFolder, "/**"))
|
|
173
|
+
}));
|
|
174
|
+
else chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
175
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
176
|
+
}));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if ('string' != typeof ignored) return void chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
180
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
181
|
+
}));
|
|
182
|
+
chain.watchOptions(_object_spread_props__(_object_spread__({}, watchOptions), {
|
|
183
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
function patchBundlerConfig(options) {
|
|
187
|
+
var _modernjsConfig_deploy;
|
|
188
|
+
var chain = options.chain, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig, enableSSR = options.enableSSR;
|
|
189
|
+
chain.optimization.delete('runtimeChunk');
|
|
190
|
+
patchIgnoreWarning(chain);
|
|
191
|
+
if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal("chunk_".concat(mfConfig.name));
|
|
192
|
+
if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
|
|
193
|
+
var splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
194
|
+
if (!isServer) autoDeleteSplitChunkCacheGroups(mfConfig, splitChunkConfig);
|
|
195
|
+
if (!isServer && enableSSR && splitChunkConfig && (void 0 === splitChunkConfig ? "undefined" : _type_of__(splitChunkConfig)) === 'object' && splitChunkConfig.cacheGroups) {
|
|
196
|
+
splitChunkConfig.chunks = 'async';
|
|
197
|
+
logger.warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
198
|
+
}
|
|
199
|
+
if (isDev() && 'auto' === chain.output.get('publicPath')) {
|
|
200
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
201
|
+
var port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
202
|
+
var publicPath = "http://localhost:".concat(port, "/");
|
|
203
|
+
chain.output.publicPath(publicPath);
|
|
204
|
+
}
|
|
205
|
+
if (isServer && enableSSR) {
|
|
206
|
+
var uniqueName = mfConfig.name || chain.output.get('uniqueName');
|
|
207
|
+
var chunkFileName = chain.output.get('chunkFilename');
|
|
208
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
209
|
+
var suffix = "".concat(encodeName(uniqueName), "-[contenthash].js");
|
|
210
|
+
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (isDev() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
|
|
214
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
|
|
215
|
+
}
|
|
216
|
+
var moduleFederationConfigPlugin = function(userConfig) {
|
|
217
|
+
return {
|
|
218
|
+
name: '@modern-js/plugin-module-federation-config',
|
|
219
|
+
pre: [
|
|
220
|
+
'@modern-js/plugin-initialize'
|
|
221
|
+
],
|
|
222
|
+
post: [
|
|
223
|
+
'@modern-js/plugin-module-federation'
|
|
224
|
+
],
|
|
225
|
+
setup: function(api) {
|
|
226
|
+
return _(function() {
|
|
227
|
+
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, _ref, enableSSR;
|
|
228
|
+
return _ts_generator__(this, function(_state) {
|
|
229
|
+
switch(_state.label){
|
|
230
|
+
case 0:
|
|
231
|
+
modernjsConfig = api.getConfig();
|
|
232
|
+
return [
|
|
233
|
+
4,
|
|
234
|
+
getMFConfig(userConfig.originPluginOptions)
|
|
235
|
+
];
|
|
236
|
+
case 1:
|
|
237
|
+
mfConfig = _state.sent();
|
|
238
|
+
csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
239
|
+
ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
240
|
+
userConfig.ssrConfig = ssrConfig;
|
|
241
|
+
userConfig.csrConfig = csrConfig;
|
|
242
|
+
enableSSR = Boolean(null != (_ref = null == (_userConfig_userConfig = userConfig.userConfig) ? void 0 : _userConfig_userConfig.ssr) ? _ref : Boolean(null == modernjsConfig ? void 0 : null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.ssr));
|
|
243
|
+
api.modifyBundlerChain(function(chain) {
|
|
244
|
+
var target = chain.get('target');
|
|
245
|
+
if (skipByTarget(target)) return;
|
|
246
|
+
var isWeb = isWebTarget(target);
|
|
247
|
+
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
248
|
+
var targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
249
|
+
patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
|
|
250
|
+
patchBundlerConfig({
|
|
251
|
+
chain: chain,
|
|
252
|
+
isServer: !isWeb,
|
|
253
|
+
modernjsConfig: modernjsConfig,
|
|
254
|
+
mfConfig: mfConfig,
|
|
255
|
+
enableSSR: enableSSR
|
|
256
|
+
});
|
|
257
|
+
if (isWeb) userConfig.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist');
|
|
258
|
+
else if (enableSSR) {
|
|
259
|
+
var _userConfig, _userConfig_userConfig;
|
|
260
|
+
(_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
|
|
261
|
+
(_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
|
|
262
|
+
if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
|
|
263
|
+
userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || path.resolve(process.cwd(), 'dist/bundles');
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
api.config(function() {
|
|
267
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
268
|
+
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
269
|
+
var ipv4 = getIPV4();
|
|
270
|
+
if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
|
|
271
|
+
else userConfig.remoteIpStrategy = 'inherit';
|
|
272
|
+
var devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
273
|
+
var corsWarnMsgs = [
|
|
274
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
275
|
+
];
|
|
276
|
+
if ((void 0 === devServerConfig ? "undefined" : _type_of__(devServerConfig)) !== 'object' || !('headers' in devServerConfig)) corsWarnMsgs.unshift('Detect devServer.headers is empty, mf modern plugin will add default cors header: devServer.headers["Access-Control-Allow-Headers"] = "*". It is recommended to specify an allowlist of trusted origins instead.');
|
|
277
|
+
var exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
278
|
+
var hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
279
|
+
if (corsWarnMsgs.length > 1 && hasExposes) logger.warn(corsWarnMsgs.join('\n'));
|
|
280
|
+
var corsHeaders = hasExposes ? {
|
|
281
|
+
'Access-Control-Allow-Origin': '*',
|
|
282
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
283
|
+
'Access-Control-Allow-Headers': '*'
|
|
284
|
+
} : void 0;
|
|
285
|
+
var defineConfig = {
|
|
286
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
287
|
+
};
|
|
288
|
+
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
289
|
+
var _ref;
|
|
290
|
+
return {
|
|
291
|
+
tools: {
|
|
292
|
+
devServer: {
|
|
293
|
+
headers: corsHeaders
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
resolve: {
|
|
297
|
+
alias: {
|
|
298
|
+
'@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
source: {
|
|
302
|
+
define: defineConfig,
|
|
303
|
+
enableAsyncEntry: 'rspack' === bundlerType ? null != (_ref = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry) ? _ref : true : null == (_modernjsConfig_source1 = modernjsConfig.source) ? void 0 : _modernjsConfig_source1.enableAsyncEntry
|
|
304
|
+
},
|
|
305
|
+
dev: {
|
|
306
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
});
|
|
310
|
+
return [
|
|
311
|
+
2
|
|
312
|
+
];
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
})();
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
var configPlugin = moduleFederationConfigPlugin;
|
|
320
|
+
export { addMyTypes2Ignored, configPlugin as default, getMFConfig, isWebTarget, moduleFederationConfigPlugin, patchBundlerConfig, patchMFConfig, setEnv, skipByTarget };
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
|
+
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
4
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
5
|
+
import { AsyncBoundaryPlugin, ModuleFederationPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
|
|
6
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
|
+
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
8
|
+
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
9
|
+
import { isWebTarget } from "./utils.mjs";
|
|
10
|
+
var moduleFederationPlugin = function() {
|
|
11
|
+
var userConfig = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
12
|
+
var _userConfig_fetchServerQuery;
|
|
13
|
+
var internalModernPluginOptions = {
|
|
14
|
+
csrConfig: void 0,
|
|
15
|
+
ssrConfig: void 0,
|
|
16
|
+
browserPlugin: void 0,
|
|
17
|
+
nodePlugin: void 0,
|
|
18
|
+
assetResources: {},
|
|
19
|
+
distOutputDir: '',
|
|
20
|
+
originPluginOptions: _object_spread__({}, userConfig),
|
|
21
|
+
remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
|
|
22
|
+
userConfig: userConfig || {},
|
|
23
|
+
assetFileNames: {},
|
|
24
|
+
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
name: '@modern-js/plugin-module-federation',
|
|
28
|
+
setup: function(api) {
|
|
29
|
+
return _(function() {
|
|
30
|
+
var modernjsConfig;
|
|
31
|
+
return _ts_generator__(this, function(_state) {
|
|
32
|
+
modernjsConfig = api.getConfig();
|
|
33
|
+
api.modifyBundlerChain(function(chain) {
|
|
34
|
+
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
35
|
+
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
36
|
+
var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
37
|
+
if (isWebTarget(chain.get('target'))) chain.plugin('plugin-module-federation').use(MFPlugin, [
|
|
38
|
+
browserPluginOptions
|
|
39
|
+
]).init(function(Plugin, args) {
|
|
40
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
41
|
+
return internalModernPluginOptions.browserPlugin;
|
|
42
|
+
});
|
|
43
|
+
if ('webpack' === bundlerType) {
|
|
44
|
+
var _modernjsConfig_source;
|
|
45
|
+
var enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
46
|
+
if (!enableAsyncEntry && false !== browserPluginOptions.async) {
|
|
47
|
+
var asyncBoundaryPluginOptions = 'object' === _type_of__(browserPluginOptions.async) ? browserPluginOptions.async : {
|
|
48
|
+
eager: function(module) {
|
|
49
|
+
return module && /\.federation/.test((null == module ? void 0 : module.request) || '');
|
|
50
|
+
},
|
|
51
|
+
excludeChunk: function(chunk) {
|
|
52
|
+
return chunk.name === browserPluginOptions.name;
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
chain.plugin('async-boundary-plugin').use(AsyncBoundaryPlugin, [
|
|
56
|
+
asyncBoundaryPluginOptions
|
|
57
|
+
]);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
api._internalServerPlugins(function(param) {
|
|
62
|
+
var plugins = param.plugins;
|
|
63
|
+
plugins.push({
|
|
64
|
+
name: '@module-federation/modern-js/server'
|
|
65
|
+
});
|
|
66
|
+
return {
|
|
67
|
+
plugins: plugins
|
|
68
|
+
};
|
|
69
|
+
});
|
|
70
|
+
return [
|
|
71
|
+
2
|
|
72
|
+
];
|
|
73
|
+
});
|
|
74
|
+
})();
|
|
75
|
+
},
|
|
76
|
+
usePlugins: [
|
|
77
|
+
moduleFederationConfigPlugin(internalModernPluginOptions),
|
|
78
|
+
moduleFederationSSRPlugin(internalModernPluginOptions)
|
|
79
|
+
]
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
var cli = moduleFederationPlugin;
|
|
83
|
+
export { createModuleFederationConfig, cli as default, moduleFederationPlugin };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import node_fetch from "node-fetch";
|
|
2
|
+
var injectNodeFetchPlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'inject-node-fetch-plugin',
|
|
5
|
+
beforeInit: function(args) {
|
|
6
|
+
if (!globalThis.fetch) globalThis.fetch = node_fetch;
|
|
7
|
+
return args;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
var inject_node_fetch = injectNodeFetchPlugin;
|
|
12
|
+
export { inject_node_fetch as default };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
|
+
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
+
import { LOCALHOST } from "../../constant.mjs";
|
|
4
|
+
var ipv4 = "u" > typeof FEDERATION_IPV4 ? FEDERATION_IPV4 : '127.0.0.1';
|
|
5
|
+
var remoteIpStrategy = "u" > typeof REMOTE_IP_STRATEGY ? REMOTE_IP_STRATEGY : 'inherit';
|
|
6
|
+
function replaceObjectLocalhost(key, obj) {
|
|
7
|
+
if ('ipv4' !== remoteIpStrategy) return;
|
|
8
|
+
if (!(key in obj)) return;
|
|
9
|
+
var remote = obj[key];
|
|
10
|
+
if (remote && 'string' == typeof remote && remote.includes(LOCALHOST)) obj[key] = replaceLocalhost(remote);
|
|
11
|
+
}
|
|
12
|
+
function replaceLocalhost(url) {
|
|
13
|
+
return url.replace(LOCALHOST, ipv4);
|
|
14
|
+
}
|
|
15
|
+
var resolveEntryIpv4Plugin = function() {
|
|
16
|
+
return {
|
|
17
|
+
name: 'resolve-entry-ipv4',
|
|
18
|
+
beforeRegisterRemote: function(args) {
|
|
19
|
+
var remote = args.remote;
|
|
20
|
+
replaceObjectLocalhost('entry', remote);
|
|
21
|
+
return args;
|
|
22
|
+
},
|
|
23
|
+
afterResolve: function(args) {
|
|
24
|
+
return _(function() {
|
|
25
|
+
var remoteInfo;
|
|
26
|
+
return _ts_generator__(this, function(_state) {
|
|
27
|
+
remoteInfo = args.remoteInfo;
|
|
28
|
+
replaceObjectLocalhost('entry', remoteInfo);
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
args
|
|
32
|
+
];
|
|
33
|
+
});
|
|
34
|
+
})();
|
|
35
|
+
},
|
|
36
|
+
beforeLoadRemoteSnapshot: function(args) {
|
|
37
|
+
var moduleInfo = args.moduleInfo;
|
|
38
|
+
if ('entry' in moduleInfo) {
|
|
39
|
+
replaceObjectLocalhost('entry', moduleInfo);
|
|
40
|
+
return args;
|
|
41
|
+
}
|
|
42
|
+
if ('version' in moduleInfo) replaceObjectLocalhost('version', moduleInfo);
|
|
43
|
+
return args;
|
|
44
|
+
},
|
|
45
|
+
loadRemoteSnapshot: function(args) {
|
|
46
|
+
var remoteSnapshot = args.remoteSnapshot;
|
|
47
|
+
if ('publicPath' in remoteSnapshot) replaceObjectLocalhost('publicPath', remoteSnapshot);
|
|
48
|
+
if ('getPublicPath' in remoteSnapshot) replaceObjectLocalhost('getPublicPath', remoteSnapshot);
|
|
49
|
+
if (remoteSnapshot.remotesInfo) Object.keys(remoteSnapshot.remotesInfo).forEach(function(key) {
|
|
50
|
+
var remoteInfo = remoteSnapshot.remotesInfo[key];
|
|
51
|
+
replaceObjectLocalhost('matchedVersion', remoteInfo);
|
|
52
|
+
});
|
|
53
|
+
return args;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
var resolve_entry_ipv4 = resolveEntryIpv4Plugin;
|
|
58
|
+
export { resolve_entry_ipv4 as default };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
var sharedStrategy = function() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'shared-strategy-plugin',
|
|
4
|
+
beforeInit: function(args) {
|
|
5
|
+
var userOptions = args.userOptions;
|
|
6
|
+
var shared = userOptions.shared;
|
|
7
|
+
if (shared) Object.keys(shared).forEach(function(sharedKey) {
|
|
8
|
+
var sharedConfigs = shared[sharedKey];
|
|
9
|
+
var arraySharedConfigs = Array.isArray(sharedConfigs) ? sharedConfigs : [
|
|
10
|
+
sharedConfigs
|
|
11
|
+
];
|
|
12
|
+
arraySharedConfigs.forEach(function(s) {
|
|
13
|
+
s.strategy = 'loaded-first';
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return args;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
var shared_strategy = sharedStrategy;
|
|
21
|
+
export { shared_strategy as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import data_fetch_server_middleware from "@module-federation/bridge-react/data-fetch-server-middleware";
|
|
2
|
+
var dataFetchServePlugin = function() {
|
|
3
|
+
return {
|
|
4
|
+
name: 'mf-data-fetch-server-plugin',
|
|
5
|
+
setup: function(api) {
|
|
6
|
+
api.onPrepare(function() {
|
|
7
|
+
var middlewares = api.getServerContext().middlewares;
|
|
8
|
+
middlewares.push({
|
|
9
|
+
name: 'module-federation-serve-manifest',
|
|
10
|
+
handler: data_fetch_server_middleware
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
var data_fetch_server_plugin = dataFetchServePlugin;
|
|
17
|
+
export { data_fetch_server_plugin as default };
|