@module-federation/modern-js 0.22.1 → 0.24.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 +278 -258
- package/dist/cjs/cli/index.js +13 -4
- package/dist/cjs/cli/ssrPlugin.js +17 -5
- package/dist/cjs/ssr-runtime/SSRLiveReload.js +1 -0
- package/dist/esm/cli/configPlugin.mjs +28 -13
- package/dist/esm/cli/index.mjs +15 -6
- package/dist/esm/cli/ssrPlugin.mjs +17 -5
- package/dist/esm/ssr-runtime/SSRLiveReload.mjs +1 -0
- package/dist/esm-node/cli/configPlugin.mjs +26 -6
- package/dist/esm-node/cli/index.mjs +15 -6
- package/dist/esm-node/cli/ssrPlugin.mjs +17 -5
- package/dist/esm-node/ssr-runtime/SSRLiveReload.mjs +1 -0
- package/dist/types/ssr-runtime/SSRLiveReload.d.ts +2 -1
- package/dist/types/types/index.d.ts +2 -0
- package/package.json +16 -16
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
jiti (module) {
|
|
4
|
+
module.exports = require("jiti");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
3
17
|
(()=>{
|
|
4
18
|
__webpack_require__.n = (module)=>{
|
|
5
19
|
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
@@ -31,282 +45,288 @@ var __webpack_require__ = {};
|
|
|
31
45
|
};
|
|
32
46
|
})();
|
|
33
47
|
var __webpack_exports__ = {};
|
|
34
|
-
|
|
35
|
-
__webpack_require__.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const external_path_namespaceObject = require("path");
|
|
47
|
-
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
48
|
-
const external_utils_js_namespaceObject = require("./utils.js");
|
|
49
|
-
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
50
|
-
const node_bundle_require_namespaceObject = require("@modern-js/node-bundle-require");
|
|
51
|
-
const external_constant_js_namespaceObject = require("../constant.js");
|
|
52
|
-
const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
|
|
53
|
-
const external_logger_js_namespaceObject = require("../logger.js");
|
|
54
|
-
var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
|
|
55
|
-
const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
|
|
56
|
-
function setEnv(enableSSR) {
|
|
57
|
-
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
58
|
-
}
|
|
59
|
-
const getMFConfig = async (userConfig)=>{
|
|
60
|
-
const { config, configPath } = userConfig;
|
|
61
|
-
if (config) return config;
|
|
62
|
-
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
63
|
-
const preBundlePath = await (0, node_bundle_require_namespaceObject.bundle)(mfConfigPath);
|
|
64
|
-
const mfConfig = (await import(preBundlePath)).default;
|
|
65
|
-
return mfConfig;
|
|
66
|
-
};
|
|
67
|
-
const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
|
|
68
|
-
const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
69
|
-
const hasPlugin = runtimePlugins.some((existingPlugin)=>{
|
|
70
|
-
if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
|
|
71
|
-
return existingPlugin[0] === pluginName;
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
51
|
+
patchMFConfig: ()=>patchMFConfig,
|
|
52
|
+
default: ()=>configPlugin,
|
|
53
|
+
getMFConfig: ()=>getMFConfig,
|
|
54
|
+
isWebTarget: ()=>external_utils_js_namespaceObject.isWebTarget,
|
|
55
|
+
moduleFederationConfigPlugin: ()=>moduleFederationConfigPlugin,
|
|
56
|
+
addMyTypes2Ignored: ()=>addMyTypes2Ignored,
|
|
57
|
+
skipByTarget: ()=>external_utils_js_namespaceObject.skipByTarget,
|
|
58
|
+
setEnv: ()=>setEnv,
|
|
59
|
+
patchBundlerConfig: ()=>patchBundlerConfig
|
|
72
60
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
const external_path_namespaceObject = require("path");
|
|
62
|
+
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
63
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
64
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
65
|
+
const external_constant_js_namespaceObject = require("../constant.js");
|
|
66
|
+
const utils_namespaceObject = require("@module-federation/rsbuild-plugin/utils");
|
|
67
|
+
const external_logger_js_namespaceObject = require("../logger.js");
|
|
68
|
+
var external_logger_js_default = /*#__PURE__*/ __webpack_require__.n(external_logger_js_namespaceObject);
|
|
69
|
+
const defaultPath = external_path_default().resolve(process.cwd(), 'module-federation.config.ts');
|
|
70
|
+
function setEnv(enableSSR) {
|
|
71
|
+
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
72
|
+
}
|
|
73
|
+
const getMFConfig = async (userConfig)=>{
|
|
74
|
+
const { config, configPath } = userConfig;
|
|
75
|
+
if (config) return config;
|
|
76
|
+
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
77
|
+
const { createJiti } = __webpack_require__("jiti");
|
|
78
|
+
const jit = createJiti(__filename, {
|
|
79
|
+
interopDefault: true,
|
|
80
|
+
esmResolve: true
|
|
85
81
|
});
|
|
82
|
+
const configModule = await jit(mfConfigPath);
|
|
83
|
+
const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
|
|
84
|
+
return resolvedConfig;
|
|
86
85
|
};
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
86
|
+
const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
|
|
87
|
+
const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
88
|
+
const hasPlugin = runtimePlugins.some((existingPlugin)=>{
|
|
89
|
+
if ('string' == typeof existingPlugin) return existingPlugin === pluginName;
|
|
90
|
+
return existingPlugin[0] === pluginName;
|
|
91
|
+
});
|
|
92
|
+
if (!hasPlugin) runtimePlugins.push(runtimePlugin);
|
|
93
|
+
};
|
|
94
|
+
const replaceRemoteUrl = (mfConfig, remoteIpStrategy)=>{
|
|
95
|
+
if (remoteIpStrategy && 'inherit' === remoteIpStrategy) return;
|
|
96
|
+
if (!mfConfig.remotes) return;
|
|
97
|
+
const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
|
|
98
|
+
const handleRemoteObject = (remoteObject)=>{
|
|
99
|
+
Object.keys(remoteObject).forEach((remoteKey)=>{
|
|
100
|
+
const remote = remoteObject[remoteKey];
|
|
101
|
+
if (Array.isArray(remote)) return;
|
|
102
|
+
if ('string' == typeof remote && remote.includes(external_constant_js_namespaceObject.LOCALHOST)) remoteObject[remoteKey] = remote.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
|
|
103
|
+
if ('object' == typeof remote && !Array.isArray(remote.external) && remote.external.includes(external_constant_js_namespaceObject.LOCALHOST)) remote.external = remote.external.replace(external_constant_js_namespaceObject.LOCALHOST, ipv4);
|
|
104
|
+
});
|
|
104
105
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
if (Array.isArray(mfConfig.remotes)) mfConfig.remotes.forEach((remoteObject)=>{
|
|
107
|
+
if ('string' == typeof remoteObject) return;
|
|
108
|
+
handleRemoteObject(remoteObject);
|
|
109
|
+
});
|
|
110
|
+
else if ('string' != typeof mfConfig.remotes) handleRemoteObject(mfConfig.remotes);
|
|
111
|
+
};
|
|
112
|
+
const patchDTSConfig = (mfConfig, isServer)=>{
|
|
113
|
+
if (isServer) return;
|
|
114
|
+
const ModernJSRuntime = '@module-federation/modern-js/runtime';
|
|
115
|
+
if (false !== mfConfig.dts) {
|
|
116
|
+
var _mfConfig_dts, _mfConfig_dts1;
|
|
117
|
+
if ('boolean' == typeof mfConfig.dts || void 0 === mfConfig.dts) mfConfig.dts = {
|
|
118
|
+
consumeTypes: {
|
|
119
|
+
runtimePkgs: [
|
|
120
|
+
ModernJSRuntime
|
|
121
|
+
]
|
|
122
|
+
}
|
|
111
123
|
};
|
|
112
|
-
else {
|
|
113
|
-
|
|
114
|
-
if (
|
|
124
|
+
else if ((null == (_mfConfig_dts = mfConfig.dts) ? void 0 : _mfConfig_dts.consumeTypes) || (null == (_mfConfig_dts1 = mfConfig.dts) ? void 0 : _mfConfig_dts1.consumeTypes) === void 0) {
|
|
125
|
+
var _mfConfig_dts2;
|
|
126
|
+
if ('boolean' == typeof mfConfig.dts.consumeTypes || (null == (_mfConfig_dts2 = mfConfig.dts) ? void 0 : _mfConfig_dts2.consumeTypes) === void 0) mfConfig.dts.consumeTypes = {
|
|
127
|
+
runtimePkgs: [
|
|
128
|
+
ModernJSRuntime
|
|
129
|
+
]
|
|
130
|
+
};
|
|
131
|
+
else {
|
|
132
|
+
mfConfig.dts.consumeTypes.runtimePkgs = mfConfig.dts.consumeTypes.runtimePkgs || [];
|
|
133
|
+
if (!mfConfig.dts.consumeTypes.runtimePkgs.includes(ModernJSRuntime)) mfConfig.dts.consumeTypes.runtimePkgs.push(ModernJSRuntime);
|
|
134
|
+
}
|
|
115
135
|
}
|
|
116
136
|
}
|
|
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
|
-
|
|
137
|
+
};
|
|
138
|
+
const patchMFConfig = (mfConfig, isServer, remoteIpStrategy, enableSSR)=>{
|
|
139
|
+
replaceRemoteUrl(mfConfig, remoteIpStrategy);
|
|
140
|
+
(0, utils_namespaceObject.addDataFetchExposes)(mfConfig.exposes, isServer);
|
|
141
|
+
if (void 0 === mfConfig.remoteType) mfConfig.remoteType = "script";
|
|
142
|
+
if (!mfConfig.name) throw new Error(`${external_constant_js_namespaceObject.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
143
|
+
const runtimePlugins = [
|
|
144
|
+
...mfConfig.runtimePlugins || []
|
|
145
|
+
];
|
|
146
|
+
patchDTSConfig(mfConfig, isServer);
|
|
147
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/shared-strategy'), runtimePlugins);
|
|
148
|
+
if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/modern-js/resolve-entry-ipv4'), runtimePlugins);
|
|
149
|
+
if (isServer) {
|
|
150
|
+
injectRuntimePlugins(require.resolve('@module-federation/node/runtimePlugin'), runtimePlugins);
|
|
151
|
+
if ((0, external_utils_js_namespaceObject.isDev)()) injectRuntimePlugins(require.resolve('@module-federation/node/record-dynamic-remote-entry-hash-plugin'), runtimePlugins);
|
|
152
|
+
injectRuntimePlugins(require.resolve('@module-federation/modern-js/inject-node-fetch'), runtimePlugins);
|
|
153
|
+
if (mfConfig.library) {
|
|
154
|
+
if (!mfConfig.library.type) mfConfig.library.type = 'commonjs-module';
|
|
155
|
+
if (!mfConfig.library.name) mfConfig.library.name = mfConfig.name;
|
|
156
|
+
} else mfConfig.library = {
|
|
157
|
+
type: 'commonjs-module',
|
|
158
|
+
name: mfConfig.name
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
mfConfig.runtimePlugins = runtimePlugins;
|
|
162
|
+
if (!isServer) {
|
|
163
|
+
var _mfConfig_library;
|
|
164
|
+
if ((null == (_mfConfig_library = mfConfig.library) ? void 0 : _mfConfig_library.type) === 'commonjs-module') mfConfig.library.type = 'global';
|
|
165
|
+
return mfConfig;
|
|
166
|
+
}
|
|
167
|
+
mfConfig.dts = false;
|
|
168
|
+
mfConfig.dev = false;
|
|
146
169
|
return mfConfig;
|
|
170
|
+
};
|
|
171
|
+
function patchIgnoreWarning(chain) {
|
|
172
|
+
const ignoreWarnings = chain.get('ignoreWarnings') || [];
|
|
173
|
+
const ignoredMsgs = [
|
|
174
|
+
"external script",
|
|
175
|
+
'process.env.WS_NO_BUFFER_UTIL',
|
|
176
|
+
"Can't resolve 'utf-8-validate"
|
|
177
|
+
];
|
|
178
|
+
ignoreWarnings.push((warning)=>{
|
|
179
|
+
if (ignoredMsgs.some((msg)=>warning.message.includes(msg))) return true;
|
|
180
|
+
return false;
|
|
181
|
+
});
|
|
182
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
147
183
|
}
|
|
148
|
-
mfConfig
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
|
|
168
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
169
|
-
});
|
|
170
|
-
const ignored = watchOptions.ignored;
|
|
171
|
-
const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
|
|
172
|
-
if (Array.isArray(ignored)) {
|
|
173
|
-
if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
|
|
184
|
+
function addMyTypes2Ignored(chain, mfConfig) {
|
|
185
|
+
const watchOptions = chain.get('watchOptions');
|
|
186
|
+
if (!watchOptions || !watchOptions.ignored) return void chain.watchOptions({
|
|
187
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
188
|
+
});
|
|
189
|
+
const ignored = watchOptions.ignored;
|
|
190
|
+
const DEFAULT_IGNORED_GLOB = '**/@mf-types/**';
|
|
191
|
+
if (Array.isArray(ignored)) {
|
|
192
|
+
if (false !== mfConfig.dts && 'object' == typeof mfConfig.dts && 'object' == typeof mfConfig.dts.consumeTypes && mfConfig.dts.consumeTypes.remoteTypesFolder) chain.watchOptions({
|
|
193
|
+
...watchOptions,
|
|
194
|
+
ignored: ignored.concat(`**/${mfConfig.dts.consumeTypes.remoteTypesFolder}/**`)
|
|
195
|
+
});
|
|
196
|
+
else chain.watchOptions({
|
|
197
|
+
...watchOptions,
|
|
198
|
+
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
199
|
+
});
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
if ('string' != typeof ignored) return void chain.watchOptions({
|
|
174
203
|
...watchOptions,
|
|
175
|
-
ignored:
|
|
204
|
+
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
176
205
|
});
|
|
177
|
-
|
|
206
|
+
chain.watchOptions({
|
|
178
207
|
...watchOptions,
|
|
179
208
|
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
180
209
|
});
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
if ('string' != typeof ignored) return void chain.watchOptions({
|
|
184
|
-
...watchOptions,
|
|
185
|
-
ignored: /[\\/](?:\.git|node_modules|@mf-types)[\\/]/
|
|
186
|
-
});
|
|
187
|
-
chain.watchOptions({
|
|
188
|
-
...watchOptions,
|
|
189
|
-
ignored: ignored.concat(DEFAULT_IGNORED_GLOB)
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function patchBundlerConfig(options) {
|
|
193
|
-
var _modernjsConfig_deploy;
|
|
194
|
-
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
195
|
-
chain.optimization.delete('runtimeChunk');
|
|
196
|
-
patchIgnoreWarning(chain);
|
|
197
|
-
if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
198
|
-
if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
|
|
199
|
-
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
200
|
-
if (!isServer) (0, utils_namespaceObject.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
|
|
201
|
-
if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
|
|
202
|
-
splitChunkConfig.chunks = 'async';
|
|
203
|
-
external_logger_js_default().warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
204
|
-
}
|
|
205
|
-
if ((0, external_utils_js_namespaceObject.isDev)() && 'auto' === chain.output.get('publicPath')) {
|
|
206
|
-
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
207
|
-
const port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
208
|
-
const publicPath = `http://localhost:${port}/`;
|
|
209
|
-
chain.output.publicPath(publicPath);
|
|
210
210
|
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
const
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
211
|
+
function patchBundlerConfig(options) {
|
|
212
|
+
var _modernjsConfig_deploy;
|
|
213
|
+
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
214
|
+
chain.optimization.delete('runtimeChunk');
|
|
215
|
+
patchIgnoreWarning(chain);
|
|
216
|
+
if (!chain.output.get('chunkLoadingGlobal')) chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
217
|
+
if (!chain.output.get('uniqueName')) chain.output.uniqueName(mfConfig.name);
|
|
218
|
+
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
219
|
+
if (!isServer) (0, utils_namespaceObject.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
|
|
220
|
+
if (!isServer && enableSSR && splitChunkConfig && 'object' == typeof splitChunkConfig && splitChunkConfig.cacheGroups) {
|
|
221
|
+
splitChunkConfig.chunks = 'async';
|
|
222
|
+
external_logger_js_default().warn('splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"');
|
|
217
223
|
}
|
|
224
|
+
if ((0, external_utils_js_namespaceObject.isDev)() && 'auto' === chain.output.get('publicPath')) {
|
|
225
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
226
|
+
const port = (null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.port) || (null == (_modernjsConfig_server = modernjsConfig.server) ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
227
|
+
const publicPath = `http://localhost:${port}/`;
|
|
228
|
+
chain.output.publicPath(publicPath);
|
|
229
|
+
}
|
|
230
|
+
if (isServer && enableSSR) {
|
|
231
|
+
const uniqueName = mfConfig.name || chain.output.get('uniqueName');
|
|
232
|
+
const chunkFileName = chain.output.get('chunkFilename');
|
|
233
|
+
if ('string' == typeof chunkFileName && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
234
|
+
const suffix = `${(0, sdk_namespaceObject.encodeName)(uniqueName)}-[contenthash].js`;
|
|
235
|
+
chain.output.chunkFilename(chunkFileName.replace('.js', suffix));
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
if ((0, external_utils_js_namespaceObject.isDev)() && enableSSR && !isServer) chain.resolve.fallback.set('crypto', false).set('stream', false).set('vm', false);
|
|
239
|
+
if ((null == (_modernjsConfig_deploy = modernjsConfig.deploy) ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) chain.optimization.usedExports(false);
|
|
218
240
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
'@modern-js/plugin-module-federation'
|
|
229
|
-
],
|
|
230
|
-
setup: async (api)=>{
|
|
231
|
-
var _userConfig_userConfig, _modernjsConfig_server;
|
|
232
|
-
const modernjsConfig = api.getConfig();
|
|
233
|
-
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
234
|
-
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
235
|
-
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
236
|
-
userConfig.ssrConfig = ssrConfig;
|
|
237
|
-
userConfig.csrConfig = csrConfig;
|
|
238
|
-
var _ref;
|
|
239
|
-
const 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));
|
|
240
|
-
api.modifyBundlerChain((chain)=>{
|
|
241
|
-
const target = chain.get('target');
|
|
242
|
-
if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
|
|
243
|
-
const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
|
|
244
|
-
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
245
|
-
const targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
246
|
-
patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
|
|
247
|
-
patchBundlerConfig({
|
|
248
|
-
chain,
|
|
249
|
-
isServer: !isWeb,
|
|
250
|
-
modernjsConfig,
|
|
251
|
-
mfConfig,
|
|
252
|
-
enableSSR
|
|
253
|
-
});
|
|
254
|
-
if (isWeb) userConfig.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist');
|
|
255
|
-
else if (enableSSR) {
|
|
256
|
-
var _userConfig, _userConfig_userConfig;
|
|
257
|
-
(_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
|
|
258
|
-
(_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
|
|
259
|
-
if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
|
|
260
|
-
userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist/bundles');
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
api.config(()=>{
|
|
264
|
-
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
265
|
-
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
266
|
-
const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
|
|
267
|
-
if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
|
|
268
|
-
else userConfig.remoteIpStrategy = 'inherit';
|
|
269
|
-
const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
270
|
-
const corsWarnMsgs = [
|
|
271
|
-
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
272
|
-
];
|
|
273
|
-
if ('object' != typeof devServerConfig || !('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.');
|
|
274
|
-
const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
275
|
-
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
276
|
-
if (corsWarnMsgs.length > 1 && hasExposes) external_logger_js_default().warn(corsWarnMsgs.join('\n'));
|
|
277
|
-
const corsHeaders = hasExposes ? {
|
|
278
|
-
'Access-Control-Allow-Origin': '*',
|
|
279
|
-
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
280
|
-
'Access-Control-Allow-Headers': '*'
|
|
281
|
-
} : void 0;
|
|
282
|
-
const defineConfig = {
|
|
283
|
-
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
284
|
-
};
|
|
285
|
-
if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
241
|
+
const moduleFederationConfigPlugin = (userConfig)=>({
|
|
242
|
+
name: '@modern-js/plugin-module-federation-config',
|
|
243
|
+
pre: [
|
|
244
|
+
'@modern-js/plugin-initialize'
|
|
245
|
+
],
|
|
246
|
+
post: [
|
|
247
|
+
'@modern-js/plugin-module-federation'
|
|
248
|
+
],
|
|
249
|
+
setup: async (api)=>{
|
|
286
250
|
var _ref;
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
251
|
+
var _userConfig_userConfig, _modernjsConfig_server;
|
|
252
|
+
const modernjsConfig = api.getConfig();
|
|
253
|
+
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
254
|
+
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
255
|
+
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
256
|
+
userConfig.ssrConfig = ssrConfig;
|
|
257
|
+
userConfig.csrConfig = csrConfig;
|
|
258
|
+
const 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));
|
|
259
|
+
api.modifyBundlerChain((chain)=>{
|
|
260
|
+
const target = chain.get('target');
|
|
261
|
+
if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
|
|
262
|
+
const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
|
|
263
|
+
addMyTypes2Ignored(chain, isWeb ? csrConfig : ssrConfig);
|
|
264
|
+
const targetMFConfig = isWeb ? csrConfig : ssrConfig;
|
|
265
|
+
patchMFConfig(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || 'ipv4', enableSSR);
|
|
266
|
+
patchBundlerConfig({
|
|
267
|
+
chain,
|
|
268
|
+
isServer: !isWeb,
|
|
269
|
+
modernjsConfig,
|
|
270
|
+
mfConfig,
|
|
271
|
+
enableSSR
|
|
272
|
+
});
|
|
273
|
+
if (isWeb) userConfig.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist');
|
|
274
|
+
else if (enableSSR) {
|
|
275
|
+
var _userConfig, _userConfig_userConfig;
|
|
276
|
+
(_userConfig = userConfig).userConfig || (_userConfig.userConfig = {});
|
|
277
|
+
(_userConfig_userConfig = userConfig.userConfig).ssr || (_userConfig_userConfig.ssr = {});
|
|
278
|
+
if (true === userConfig.userConfig.ssr) userConfig.userConfig.ssr = {};
|
|
279
|
+
userConfig.userConfig.ssr.distOutputDir = chain.output.get('path') || external_path_default().resolve(process.cwd(), 'dist/bundles');
|
|
304
280
|
}
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
const
|
|
281
|
+
});
|
|
282
|
+
api.config(()=>{
|
|
283
|
+
var _ref;
|
|
284
|
+
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
285
|
+
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
286
|
+
const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
|
|
287
|
+
if (void 0 === userConfig.remoteIpStrategy) if (enableSSR) userConfig.remoteIpStrategy = 'ipv4';
|
|
288
|
+
else userConfig.remoteIpStrategy = 'inherit';
|
|
289
|
+
const devServerConfig = null == (_modernjsConfig_tools = modernjsConfig.tools) ? void 0 : _modernjsConfig_tools.devServer;
|
|
290
|
+
const corsWarnMsgs = [
|
|
291
|
+
'View https://module-federation.io/guide/troubleshooting/other.html#cors-warn for more details.'
|
|
292
|
+
];
|
|
293
|
+
if ('object' != typeof devServerConfig || !('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.');
|
|
294
|
+
const exposes = null == (_userConfig_csrConfig = userConfig.csrConfig) ? void 0 : _userConfig_csrConfig.exposes;
|
|
295
|
+
const hasExposes = exposes && Array.isArray(exposes) ? exposes.length : Object.keys(null != exposes ? exposes : {}).length;
|
|
296
|
+
if (corsWarnMsgs.length > 1 && hasExposes) external_logger_js_default().warn(corsWarnMsgs.join('\n'));
|
|
297
|
+
const corsHeaders = hasExposes ? {
|
|
298
|
+
'Access-Control-Allow-Origin': '*',
|
|
299
|
+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
|
|
300
|
+
'Access-Control-Allow-Headers': '*'
|
|
301
|
+
} : void 0;
|
|
302
|
+
const defineConfig = {
|
|
303
|
+
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
304
|
+
};
|
|
305
|
+
if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
306
|
+
return {
|
|
307
|
+
tools: {
|
|
308
|
+
devServer: {
|
|
309
|
+
headers: corsHeaders
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
resolve: {
|
|
313
|
+
alias: {
|
|
314
|
+
'@modern-js/runtime/mf': require.resolve('@module-federation/modern-js/runtime')
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
source: {
|
|
318
|
+
define: defineConfig,
|
|
319
|
+
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
|
|
320
|
+
},
|
|
321
|
+
dev: {
|
|
322
|
+
assetPrefix: (null == modernjsConfig ? void 0 : null == (_modernjsConfig_dev = modernjsConfig.dev) ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
const configPlugin = moduleFederationConfigPlugin;
|
|
329
|
+
})();
|
|
310
330
|
exports.addMyTypes2Ignored = __webpack_exports__.addMyTypes2Ignored;
|
|
311
331
|
exports["default"] = __webpack_exports__["default"];
|
|
312
332
|
exports.getMFConfig = __webpack_exports__.getMFConfig;
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -34,7 +34,7 @@ const external_configPlugin_js_namespaceObject = require("./configPlugin.js");
|
|
|
34
34
|
const external_ssrPlugin_js_namespaceObject = require("./ssrPlugin.js");
|
|
35
35
|
const external_utils_js_namespaceObject = require("./utils.js");
|
|
36
36
|
const moduleFederationPlugin = (userConfig = {})=>{
|
|
37
|
-
var _userConfig_fetchServerQuery;
|
|
37
|
+
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
38
38
|
const internalModernPluginOptions = {
|
|
39
39
|
csrConfig: void 0,
|
|
40
40
|
ssrConfig: void 0,
|
|
@@ -48,7 +48,8 @@ const moduleFederationPlugin = (userConfig = {})=>{
|
|
|
48
48
|
remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
|
|
49
49
|
userConfig: userConfig || {},
|
|
50
50
|
assetFileNames: {},
|
|
51
|
-
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
|
|
51
|
+
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
|
|
52
|
+
secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
|
|
52
53
|
};
|
|
53
54
|
return {
|
|
54
55
|
name: '@modern-js/plugin-module-federation',
|
|
@@ -57,14 +58,22 @@ const moduleFederationPlugin = (userConfig = {})=>{
|
|
|
57
58
|
api.modifyBundlerChain((chain)=>{
|
|
58
59
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
59
60
|
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
61
|
+
const { secondarySharedTreeShaking } = internalModernPluginOptions;
|
|
60
62
|
const MFPlugin = 'webpack' === bundlerType ? enhanced_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
|
|
61
|
-
|
|
63
|
+
const TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_namespaceObject.TreeShakingSharedPlugin : rspack_namespaceObject.TreeShakingSharedPlugin;
|
|
64
|
+
if ((0, external_utils_js_namespaceObject.isWebTarget)(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(TreeShakingSharedPlugin, [
|
|
65
|
+
{
|
|
66
|
+
mfConfig: browserPluginOptions,
|
|
67
|
+
secondary: true
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
else chain.plugin('plugin-module-federation').use(MFPlugin, [
|
|
62
71
|
browserPluginOptions
|
|
63
72
|
]).init((Plugin, args)=>{
|
|
64
73
|
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
65
74
|
return internalModernPluginOptions.browserPlugin;
|
|
66
75
|
});
|
|
67
|
-
if ('webpack' === bundlerType) {
|
|
76
|
+
if ('webpack' === bundlerType && !secondarySharedTreeShaking) {
|
|
68
77
|
var _modernjsConfig_source;
|
|
69
78
|
const enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
70
79
|
if (!enableAsyncEntry && false !== browserPluginOptions.async) {
|
|
@@ -42,7 +42,7 @@ const external_path_namespaceObject = require("path");
|
|
|
42
42
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
43
|
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
44
44
|
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
45
|
-
const
|
|
45
|
+
const enhanced_namespaceObject = require("@module-federation/enhanced");
|
|
46
46
|
const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
|
|
47
47
|
const universe_entry_chunk_tracker_plugin_namespaceObject = require("@module-federation/node/universe-entry-chunk-tracker-plugin");
|
|
48
48
|
var universe_entry_chunk_tracker_plugin_default = /*#__PURE__*/ __webpack_require__.n(universe_entry_chunk_tracker_plugin_namespaceObject);
|
|
@@ -161,13 +161,18 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
161
161
|
'@modern-js/plugin-module-federation'
|
|
162
162
|
],
|
|
163
163
|
setup: async (api)=>{
|
|
164
|
+
var _ref;
|
|
164
165
|
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
165
166
|
const modernjsConfig = api.getConfig();
|
|
166
|
-
var _ref;
|
|
167
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
|
+
const { secondarySharedTreeShaking } = pluginOptions;
|
|
168
169
|
if (!enableSSR) return;
|
|
169
170
|
setEnv();
|
|
170
171
|
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
172
|
+
if (secondarySharedTreeShaking) return {
|
|
173
|
+
entrypoint,
|
|
174
|
+
plugins
|
|
175
|
+
};
|
|
171
176
|
const { fetchServerQuery } = pluginOptions;
|
|
172
177
|
plugins.push({
|
|
173
178
|
name: 'injectDataFetchFunction',
|
|
@@ -203,17 +208,24 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
203
208
|
const target = chain.get('target');
|
|
204
209
|
if ((0, external_utils_js_namespaceObject.skipByTarget)(target)) return;
|
|
205
210
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
206
|
-
const MFPlugin = 'webpack' === bundlerType ?
|
|
211
|
+
const MFPlugin = 'webpack' === bundlerType ? enhanced_namespaceObject.ModuleFederationPlugin : rspack_namespaceObject.ModuleFederationPlugin;
|
|
212
|
+
const TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_namespaceObject.TreeShakingSharedPlugin : rspack_namespaceObject.TreeShakingSharedPlugin;
|
|
207
213
|
const isWeb = (0, external_utils_js_namespaceObject.isWebTarget)(target);
|
|
208
214
|
if (!isWeb) {
|
|
209
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(
|
|
215
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) if (secondarySharedTreeShaking) chain.plugin(CHAIN_MF_PLUGIN_ID).use(TreeShakingSharedPlugin, [
|
|
216
|
+
{
|
|
217
|
+
mfConfig: pluginOptions.ssrConfig,
|
|
218
|
+
secondary: true
|
|
219
|
+
}
|
|
220
|
+
]);
|
|
221
|
+
else chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
210
222
|
pluginOptions.ssrConfig
|
|
211
223
|
]).init((Plugin, args)=>{
|
|
212
224
|
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
213
225
|
return pluginOptions.nodePlugin;
|
|
214
226
|
});
|
|
215
227
|
}
|
|
216
|
-
if (!isWeb) {
|
|
228
|
+
if (!isWeb && !secondarySharedTreeShaking) {
|
|
217
229
|
chain.target('async-node');
|
|
218
230
|
if ((0, external_utils_js_namespaceObject.isDev)()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin_default());
|
|
219
231
|
}
|
|
@@ -27,6 +27,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
27
27
|
SSRLiveReload: ()=>SSRLiveReload
|
|
28
28
|
});
|
|
29
29
|
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
30
|
+
require("react");
|
|
30
31
|
function SSRLiveReload() {
|
|
31
32
|
if ('development' !== process.env.NODE_ENV) return null;
|
|
32
33
|
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("script", {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as __rspack_external_jiti from "jiti";
|
|
1
2
|
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
3
|
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
4
|
import { _ as _object_spread_props__ } from "@swc/helpers/_/_object_spread_props";
|
|
@@ -7,17 +8,31 @@ import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
|
7
8
|
import path from "path";
|
|
8
9
|
import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
9
10
|
import { encodeName } from "@module-federation/sdk";
|
|
10
|
-
import { bundle } from "@modern-js/node-bundle-require";
|
|
11
11
|
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
12
12
|
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
13
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
|
+
}
|
|
14
29
|
var defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
15
30
|
function setEnv(enableSSR) {
|
|
16
31
|
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
17
32
|
}
|
|
18
33
|
var getMFConfig = function(userConfig) {
|
|
19
34
|
return _(function() {
|
|
20
|
-
var config, configPath, mfConfigPath,
|
|
35
|
+
var config, configPath, mfConfigPath, createJiti, jit, configModule, resolvedConfig;
|
|
21
36
|
return _ts_generator__(this, function(_state) {
|
|
22
37
|
switch(_state.label){
|
|
23
38
|
case 0:
|
|
@@ -27,21 +42,21 @@ var getMFConfig = function(userConfig) {
|
|
|
27
42
|
config
|
|
28
43
|
];
|
|
29
44
|
mfConfigPath = configPath ? configPath : defaultPath;
|
|
45
|
+
createJiti = __webpack_require__("jiti").createJiti;
|
|
46
|
+
jit = createJiti(__filename, {
|
|
47
|
+
interopDefault: true,
|
|
48
|
+
esmResolve: true
|
|
49
|
+
});
|
|
30
50
|
return [
|
|
31
51
|
4,
|
|
32
|
-
|
|
52
|
+
jit(mfConfigPath)
|
|
33
53
|
];
|
|
34
54
|
case 1:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
4,
|
|
38
|
-
import(preBundlePath)
|
|
39
|
-
];
|
|
40
|
-
case 2:
|
|
41
|
-
mfConfig = _state.sent().default;
|
|
55
|
+
configModule = _state.sent();
|
|
56
|
+
resolvedConfig = configModule && (void 0 === configModule ? "undefined" : _type_of__(configModule)) === 'object' && 'default' in configModule ? configModule.default : configModule;
|
|
42
57
|
return [
|
|
43
58
|
2,
|
|
44
|
-
|
|
59
|
+
resolvedConfig
|
|
45
60
|
];
|
|
46
61
|
}
|
|
47
62
|
});
|
|
@@ -209,7 +224,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
209
224
|
],
|
|
210
225
|
setup: function(api) {
|
|
211
226
|
return _(function() {
|
|
212
|
-
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig,
|
|
227
|
+
var _ref, _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, enableSSR;
|
|
213
228
|
return _ts_generator__(this, function(_state) {
|
|
214
229
|
switch(_state.label){
|
|
215
230
|
case 0:
|
|
@@ -249,6 +264,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
249
264
|
}
|
|
250
265
|
});
|
|
251
266
|
api.config(function() {
|
|
267
|
+
var _ref;
|
|
252
268
|
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
253
269
|
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
254
270
|
var ipv4 = getIPV4();
|
|
@@ -271,7 +287,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
271
287
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
272
288
|
};
|
|
273
289
|
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
274
|
-
var _ref;
|
|
275
290
|
return {
|
|
276
291
|
tools: {
|
|
277
292
|
devServer: {
|
package/dist/esm/cli/index.mjs
CHANGED
|
@@ -2,14 +2,14 @@ import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
|
2
2
|
import { _ as _object_spread__ } from "@swc/helpers/_/_object_spread";
|
|
3
3
|
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
4
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";
|
|
5
|
+
import { AsyncBoundaryPlugin, ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
|
|
6
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
7
7
|
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
8
8
|
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
9
9
|
import { isWebTarget } from "./utils.mjs";
|
|
10
10
|
var moduleFederationPlugin = function() {
|
|
11
11
|
var userConfig = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
|
|
12
|
-
var _userConfig_fetchServerQuery;
|
|
12
|
+
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
13
13
|
var internalModernPluginOptions = {
|
|
14
14
|
csrConfig: void 0,
|
|
15
15
|
ssrConfig: void 0,
|
|
@@ -21,7 +21,8 @@ var moduleFederationPlugin = function() {
|
|
|
21
21
|
remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
|
|
22
22
|
userConfig: userConfig || {},
|
|
23
23
|
assetFileNames: {},
|
|
24
|
-
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
|
|
24
|
+
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
|
|
25
|
+
secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
|
|
25
26
|
};
|
|
26
27
|
return {
|
|
27
28
|
name: '@modern-js/plugin-module-federation',
|
|
@@ -33,14 +34,22 @@ var moduleFederationPlugin = function() {
|
|
|
33
34
|
api.modifyBundlerChain(function(chain) {
|
|
34
35
|
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
35
36
|
var browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
37
|
+
var secondarySharedTreeShaking = internalModernPluginOptions.secondarySharedTreeShaking;
|
|
36
38
|
var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
37
|
-
|
|
39
|
+
var TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
40
|
+
if (isWebTarget(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(TreeShakingSharedPlugin, [
|
|
41
|
+
{
|
|
42
|
+
mfConfig: browserPluginOptions,
|
|
43
|
+
secondary: true
|
|
44
|
+
}
|
|
45
|
+
]);
|
|
46
|
+
else chain.plugin('plugin-module-federation').use(MFPlugin, [
|
|
38
47
|
browserPluginOptions
|
|
39
48
|
]).init(function(Plugin, args) {
|
|
40
49
|
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
41
50
|
return internalModernPluginOptions.browserPlugin;
|
|
42
51
|
});
|
|
43
|
-
if ('webpack' === bundlerType) {
|
|
52
|
+
if ('webpack' === bundlerType && !secondarySharedTreeShaking) {
|
|
44
53
|
var _modernjsConfig_source;
|
|
45
54
|
var enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
46
55
|
if (!enableAsyncEntry && false !== browserPluginOptions.async) {
|
|
@@ -4,8 +4,8 @@ import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
|
4
4
|
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
6
|
import fs_extra from "fs-extra";
|
|
7
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced
|
|
8
|
-
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
7
|
+
import { ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin } from "@module-federation/enhanced";
|
|
8
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
9
9
|
import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
10
10
|
import logger from "../logger.mjs";
|
|
11
11
|
import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
@@ -131,16 +131,21 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
131
131
|
],
|
|
132
132
|
setup: function(api) {
|
|
133
133
|
return _(function() {
|
|
134
|
-
var _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig,
|
|
134
|
+
var _ref, _pluginOptions_userConfig, _modernjsConfig_server, modernjsConfig, enableSSR, secondarySharedTreeShaking, writeMergedManifest;
|
|
135
135
|
return _ts_generator__(this, function(_state) {
|
|
136
136
|
modernjsConfig = api.getConfig();
|
|
137
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
|
+
secondarySharedTreeShaking = pluginOptions.secondarySharedTreeShaking;
|
|
138
139
|
if (!enableSSR) return [
|
|
139
140
|
2
|
|
140
141
|
];
|
|
141
142
|
setEnv();
|
|
142
143
|
api._internalRuntimePlugins(function(param) {
|
|
143
144
|
var entrypoint = param.entrypoint, plugins = param.plugins;
|
|
145
|
+
if (secondarySharedTreeShaking) return {
|
|
146
|
+
entrypoint: entrypoint,
|
|
147
|
+
plugins: plugins
|
|
148
|
+
};
|
|
144
149
|
var fetchServerQuery = pluginOptions.fetchServerQuery;
|
|
145
150
|
plugins.push({
|
|
146
151
|
name: 'injectDataFetchFunction',
|
|
@@ -178,16 +183,23 @@ var moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
178
183
|
if (skipByTarget(target)) return;
|
|
179
184
|
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
180
185
|
var MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
186
|
+
var TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
181
187
|
var isWeb = isWebTarget(target);
|
|
182
188
|
if (!isWeb) {
|
|
183
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(
|
|
189
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) if (secondarySharedTreeShaking) chain.plugin(CHAIN_MF_PLUGIN_ID).use(TreeShakingSharedPlugin, [
|
|
190
|
+
{
|
|
191
|
+
mfConfig: pluginOptions.ssrConfig,
|
|
192
|
+
secondary: true
|
|
193
|
+
}
|
|
194
|
+
]);
|
|
195
|
+
else chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
184
196
|
pluginOptions.ssrConfig
|
|
185
197
|
]).init(function(Plugin, args) {
|
|
186
198
|
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
187
199
|
return pluginOptions.nodePlugin;
|
|
188
200
|
});
|
|
189
201
|
}
|
|
190
|
-
if (!isWeb) {
|
|
202
|
+
if (!isWeb && !secondarySharedTreeShaking) {
|
|
191
203
|
chain.target('async-node');
|
|
192
204
|
if (isDev()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin);
|
|
193
205
|
}
|
|
@@ -1,10 +1,25 @@
|
|
|
1
|
+
import * as __rspack_external_jiti from "jiti";
|
|
1
2
|
import path from "path";
|
|
2
3
|
import { getIPV4, isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
3
4
|
import { encodeName } from "@module-federation/sdk";
|
|
4
|
-
import { bundle } from "@modern-js/node-bundle-require";
|
|
5
5
|
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant.mjs";
|
|
6
6
|
import { addDataFetchExposes, autoDeleteSplitChunkCacheGroups } from "@module-federation/rsbuild-plugin/utils";
|
|
7
7
|
import logger from "../logger.mjs";
|
|
8
|
+
var __webpack_modules__ = {
|
|
9
|
+
jiti (module) {
|
|
10
|
+
module.exports = __rspack_external_jiti;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
var __webpack_module_cache__ = {};
|
|
14
|
+
function __webpack_require__(moduleId) {
|
|
15
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
16
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
17
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
18
|
+
exports: {}
|
|
19
|
+
};
|
|
20
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
21
|
+
return module.exports;
|
|
22
|
+
}
|
|
8
23
|
const defaultPath = path.resolve(process.cwd(), 'module-federation.config.ts');
|
|
9
24
|
function setEnv(enableSSR) {
|
|
10
25
|
if (enableSSR) process.env['MF_SSR_PRJ'] = 'true';
|
|
@@ -13,9 +28,14 @@ const getMFConfig = async (userConfig)=>{
|
|
|
13
28
|
const { config, configPath } = userConfig;
|
|
14
29
|
if (config) return config;
|
|
15
30
|
const mfConfigPath = configPath ? configPath : defaultPath;
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
31
|
+
const { createJiti } = __webpack_require__("jiti");
|
|
32
|
+
const jit = createJiti(__filename, {
|
|
33
|
+
interopDefault: true,
|
|
34
|
+
esmResolve: true
|
|
35
|
+
});
|
|
36
|
+
const configModule = await jit(mfConfigPath);
|
|
37
|
+
const resolvedConfig = configModule && 'object' == typeof configModule && 'default' in configModule ? configModule.default : configModule;
|
|
38
|
+
return resolvedConfig;
|
|
19
39
|
};
|
|
20
40
|
const injectRuntimePlugins = (runtimePlugin, runtimePlugins)=>{
|
|
21
41
|
const pluginName = 'string' == typeof runtimePlugin ? runtimePlugin : runtimePlugin[0];
|
|
@@ -181,6 +201,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
181
201
|
'@modern-js/plugin-module-federation'
|
|
182
202
|
],
|
|
183
203
|
setup: async (api)=>{
|
|
204
|
+
var _ref;
|
|
184
205
|
var _userConfig_userConfig, _modernjsConfig_server;
|
|
185
206
|
const modernjsConfig = api.getConfig();
|
|
186
207
|
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
@@ -188,7 +209,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
188
209
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
189
210
|
userConfig.ssrConfig = ssrConfig;
|
|
190
211
|
userConfig.csrConfig = csrConfig;
|
|
191
|
-
var _ref;
|
|
192
212
|
const 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));
|
|
193
213
|
api.modifyBundlerChain((chain)=>{
|
|
194
214
|
const target = chain.get('target');
|
|
@@ -214,6 +234,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
214
234
|
}
|
|
215
235
|
});
|
|
216
236
|
api.config(()=>{
|
|
237
|
+
var _ref;
|
|
217
238
|
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
218
239
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
219
240
|
const ipv4 = getIPV4();
|
|
@@ -236,7 +257,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
236
257
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
237
258
|
};
|
|
238
259
|
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
239
|
-
var _ref;
|
|
240
260
|
return {
|
|
241
261
|
tools: {
|
|
242
262
|
devServer: {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { AsyncBoundaryPlugin, ModuleFederationPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
|
|
2
|
-
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
1
|
+
import { AsyncBoundaryPlugin, ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin, createModuleFederationConfig } from "@module-federation/enhanced";
|
|
2
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
3
3
|
import { moduleFederationConfigPlugin } from "./configPlugin.mjs";
|
|
4
4
|
import { moduleFederationSSRPlugin } from "./ssrPlugin.mjs";
|
|
5
5
|
import { isWebTarget } from "./utils.mjs";
|
|
6
6
|
const moduleFederationPlugin = (userConfig = {})=>{
|
|
7
|
-
var _userConfig_fetchServerQuery;
|
|
7
|
+
var _userConfig_fetchServerQuery, _userConfig_secondarySharedTreeShaking;
|
|
8
8
|
const internalModernPluginOptions = {
|
|
9
9
|
csrConfig: void 0,
|
|
10
10
|
ssrConfig: void 0,
|
|
@@ -18,7 +18,8 @@ const moduleFederationPlugin = (userConfig = {})=>{
|
|
|
18
18
|
remoteIpStrategy: null == userConfig ? void 0 : userConfig.remoteIpStrategy,
|
|
19
19
|
userConfig: userConfig || {},
|
|
20
20
|
assetFileNames: {},
|
|
21
|
-
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0
|
|
21
|
+
fetchServerQuery: null != (_userConfig_fetchServerQuery = userConfig.fetchServerQuery) ? _userConfig_fetchServerQuery : void 0,
|
|
22
|
+
secondarySharedTreeShaking: null != (_userConfig_secondarySharedTreeShaking = userConfig.secondarySharedTreeShaking) ? _userConfig_secondarySharedTreeShaking : false
|
|
22
23
|
};
|
|
23
24
|
return {
|
|
24
25
|
name: '@modern-js/plugin-module-federation',
|
|
@@ -27,14 +28,22 @@ const moduleFederationPlugin = (userConfig = {})=>{
|
|
|
27
28
|
api.modifyBundlerChain((chain)=>{
|
|
28
29
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
29
30
|
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
31
|
+
const { secondarySharedTreeShaking } = internalModernPluginOptions;
|
|
30
32
|
const MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
31
|
-
|
|
33
|
+
const TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
34
|
+
if (isWebTarget(chain.get('target'))) if (secondarySharedTreeShaking) chain.plugin('plugin-module-federation').use(TreeShakingSharedPlugin, [
|
|
35
|
+
{
|
|
36
|
+
mfConfig: browserPluginOptions,
|
|
37
|
+
secondary: true
|
|
38
|
+
}
|
|
39
|
+
]);
|
|
40
|
+
else chain.plugin('plugin-module-federation').use(MFPlugin, [
|
|
32
41
|
browserPluginOptions
|
|
33
42
|
]).init((Plugin, args)=>{
|
|
34
43
|
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
35
44
|
return internalModernPluginOptions.browserPlugin;
|
|
36
45
|
});
|
|
37
|
-
if ('webpack' === bundlerType) {
|
|
46
|
+
if ('webpack' === bundlerType && !secondarySharedTreeShaking) {
|
|
38
47
|
var _modernjsConfig_source;
|
|
39
48
|
const enableAsyncEntry = null == (_modernjsConfig_source = modernjsConfig.source) ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
40
49
|
if (!enableAsyncEntry && false !== browserPluginOptions.async) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import fs_extra from "fs-extra";
|
|
3
|
-
import { ModuleFederationPlugin } from "@module-federation/enhanced
|
|
4
|
-
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
|
|
3
|
+
import { ModuleFederationPlugin, TreeShakingSharedPlugin as enhanced_TreeShakingSharedPlugin } from "@module-federation/enhanced";
|
|
4
|
+
import { ModuleFederationPlugin as rspack_ModuleFederationPlugin, TreeShakingSharedPlugin as rspack_TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
5
5
|
import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
6
6
|
import logger from "../logger.mjs";
|
|
7
7
|
import { isDev, isWebTarget, skipByTarget } from "./utils.mjs";
|
|
@@ -117,13 +117,18 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
117
117
|
'@modern-js/plugin-module-federation'
|
|
118
118
|
],
|
|
119
119
|
setup: async (api)=>{
|
|
120
|
+
var _ref;
|
|
120
121
|
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
121
122
|
const modernjsConfig = api.getConfig();
|
|
122
|
-
var _ref;
|
|
123
123
|
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);
|
|
124
|
+
const { secondarySharedTreeShaking } = pluginOptions;
|
|
124
125
|
if (!enableSSR) return;
|
|
125
126
|
setEnv();
|
|
126
127
|
api._internalRuntimePlugins(({ entrypoint, plugins })=>{
|
|
128
|
+
if (secondarySharedTreeShaking) return {
|
|
129
|
+
entrypoint,
|
|
130
|
+
plugins
|
|
131
|
+
};
|
|
127
132
|
const { fetchServerQuery } = pluginOptions;
|
|
128
133
|
plugins.push({
|
|
129
134
|
name: 'injectDataFetchFunction',
|
|
@@ -160,16 +165,23 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
160
165
|
if (skipByTarget(target)) return;
|
|
161
166
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
162
167
|
const MFPlugin = 'webpack' === bundlerType ? ModuleFederationPlugin : rspack_ModuleFederationPlugin;
|
|
168
|
+
const TreeShakingSharedPlugin = 'webpack' === bundlerType ? enhanced_TreeShakingSharedPlugin : rspack_TreeShakingSharedPlugin;
|
|
163
169
|
const isWeb = isWebTarget(target);
|
|
164
170
|
if (!isWeb) {
|
|
165
|
-
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) chain.plugin(CHAIN_MF_PLUGIN_ID).use(
|
|
171
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) if (secondarySharedTreeShaking) chain.plugin(CHAIN_MF_PLUGIN_ID).use(TreeShakingSharedPlugin, [
|
|
172
|
+
{
|
|
173
|
+
mfConfig: pluginOptions.ssrConfig,
|
|
174
|
+
secondary: true
|
|
175
|
+
}
|
|
176
|
+
]);
|
|
177
|
+
else chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
166
178
|
pluginOptions.ssrConfig
|
|
167
179
|
]).init((Plugin, args)=>{
|
|
168
180
|
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
169
181
|
return pluginOptions.nodePlugin;
|
|
170
182
|
});
|
|
171
183
|
}
|
|
172
|
-
if (!isWeb) {
|
|
184
|
+
if (!isWeb && !secondarySharedTreeShaking) {
|
|
173
185
|
chain.target('async-node');
|
|
174
186
|
if (isDev()) chain.plugin('UniverseEntryChunkTrackerPlugin').use(universe_entry_chunk_tracker_plugin);
|
|
175
187
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare function SSRLiveReload(): React.JSX.Element | null;
|
|
@@ -8,6 +8,7 @@ export interface PluginOptions {
|
|
|
8
8
|
} | boolean;
|
|
9
9
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
10
10
|
fetchServerQuery?: Record<string, unknown>;
|
|
11
|
+
secondarySharedTreeShaking?: boolean;
|
|
11
12
|
}
|
|
12
13
|
export type AssetFileNames = {
|
|
13
14
|
statsFileName: string;
|
|
@@ -31,5 +32,6 @@ export interface InternalModernPluginOptions {
|
|
|
31
32
|
remoteIpStrategy?: 'ipv4' | 'inherit';
|
|
32
33
|
userConfig?: PluginOptions;
|
|
33
34
|
fetchServerQuery?: Record<string, unknown>;
|
|
35
|
+
secondarySharedTreeShaking?: boolean;
|
|
34
36
|
}
|
|
35
37
|
export type BundlerPlugin = any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -133,33 +133,33 @@
|
|
|
133
133
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
134
134
|
"license": "MIT",
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@modern-js/utils": "2.
|
|
137
|
-
"@modern-js/node-bundle-require": "2.69.3",
|
|
136
|
+
"@modern-js/utils": "2.70.2",
|
|
138
137
|
"fs-extra": "11.3.0",
|
|
139
138
|
"lru-cache": "10.4.3",
|
|
140
139
|
"@swc/helpers": "^0.5.17",
|
|
141
140
|
"node-fetch": "~3.3.0",
|
|
141
|
+
"jiti": "2.4.2",
|
|
142
142
|
"react-error-boundary": "4.1.2",
|
|
143
|
-
"@module-federation/
|
|
144
|
-
"@module-federation/
|
|
145
|
-
"@module-federation/enhanced": "0.
|
|
146
|
-
"@module-federation/node": "2.7.
|
|
147
|
-
"@module-federation/
|
|
148
|
-
"@module-federation/
|
|
149
|
-
"@module-federation/
|
|
143
|
+
"@module-federation/rsbuild-plugin": "0.24.0",
|
|
144
|
+
"@module-federation/bridge-react": "0.24.0",
|
|
145
|
+
"@module-federation/enhanced": "0.24.0",
|
|
146
|
+
"@module-federation/node": "2.7.29",
|
|
147
|
+
"@module-federation/runtime": "0.24.0",
|
|
148
|
+
"@module-federation/sdk": "0.24.0",
|
|
149
|
+
"@module-federation/cli": "0.24.0"
|
|
150
150
|
},
|
|
151
151
|
"devDependencies": {
|
|
152
152
|
"@rsbuild/plugin-react": "1.4.2",
|
|
153
153
|
"@rslib/core": "0.18.5",
|
|
154
154
|
"@rsbuild/core": "1.3.21",
|
|
155
|
-
"@modern-js/app-tools": "2.
|
|
156
|
-
"@modern-js/server-runtime": "2.
|
|
157
|
-
"@modern-js/module-tools": "2.
|
|
158
|
-
"@modern-js/runtime": "2.
|
|
159
|
-
"@modern-js/tsconfig": "2.
|
|
155
|
+
"@modern-js/app-tools": "2.70.2",
|
|
156
|
+
"@modern-js/server-runtime": "2.70.2",
|
|
157
|
+
"@modern-js/module-tools": "2.70.2",
|
|
158
|
+
"@modern-js/runtime": "2.70.2",
|
|
159
|
+
"@modern-js/tsconfig": "2.70.2",
|
|
160
160
|
"@types/react": "^18.3.11",
|
|
161
161
|
"@types/react-dom": "^18.3.0",
|
|
162
|
-
"@module-federation/manifest": "0.
|
|
162
|
+
"@module-federation/manifest": "0.24.0"
|
|
163
163
|
},
|
|
164
164
|
"peerDependencies": {
|
|
165
165
|
"react": ">=17",
|