@module-federation/modern-js 0.23.0 → 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +9 -9
|
@@ -247,6 +247,7 @@ var __webpack_exports__ = {};
|
|
|
247
247
|
'@modern-js/plugin-module-federation'
|
|
248
248
|
],
|
|
249
249
|
setup: async (api)=>{
|
|
250
|
+
var _ref;
|
|
250
251
|
var _userConfig_userConfig, _modernjsConfig_server;
|
|
251
252
|
const modernjsConfig = api.getConfig();
|
|
252
253
|
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
@@ -254,7 +255,6 @@ var __webpack_exports__ = {};
|
|
|
254
255
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
255
256
|
userConfig.ssrConfig = ssrConfig;
|
|
256
257
|
userConfig.csrConfig = csrConfig;
|
|
257
|
-
var _ref;
|
|
258
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
259
|
api.modifyBundlerChain((chain)=>{
|
|
260
260
|
const target = chain.get('target');
|
|
@@ -280,6 +280,7 @@ var __webpack_exports__ = {};
|
|
|
280
280
|
}
|
|
281
281
|
});
|
|
282
282
|
api.config(()=>{
|
|
283
|
+
var _ref;
|
|
283
284
|
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
284
285
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
285
286
|
const ipv4 = (0, external_utils_js_namespaceObject.getIPV4)();
|
|
@@ -302,7 +303,6 @@ var __webpack_exports__ = {};
|
|
|
302
303
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
303
304
|
};
|
|
304
305
|
if (enableSSR && (0, external_utils_js_namespaceObject.isDev)()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
305
|
-
var _ref;
|
|
306
306
|
return {
|
|
307
307
|
tools: {
|
|
308
308
|
devServer: {
|
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", {
|
|
@@ -224,7 +224,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
224
224
|
],
|
|
225
225
|
setup: function(api) {
|
|
226
226
|
return _(function() {
|
|
227
|
-
var _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig,
|
|
227
|
+
var _ref, _userConfig_userConfig, _modernjsConfig_server, modernjsConfig, mfConfig, csrConfig, ssrConfig, enableSSR;
|
|
228
228
|
return _ts_generator__(this, function(_state) {
|
|
229
229
|
switch(_state.label){
|
|
230
230
|
case 0:
|
|
@@ -264,6 +264,7 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
264
264
|
}
|
|
265
265
|
});
|
|
266
266
|
api.config(function() {
|
|
267
|
+
var _ref;
|
|
267
268
|
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
268
269
|
var bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
269
270
|
var ipv4 = getIPV4();
|
|
@@ -286,7 +287,6 @@ var moduleFederationConfigPlugin = function(userConfig) {
|
|
|
286
287
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
287
288
|
};
|
|
288
289
|
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
289
|
-
var _ref;
|
|
290
290
|
return {
|
|
291
291
|
tools: {
|
|
292
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
|
}
|
|
@@ -201,6 +201,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
201
201
|
'@modern-js/plugin-module-federation'
|
|
202
202
|
],
|
|
203
203
|
setup: async (api)=>{
|
|
204
|
+
var _ref;
|
|
204
205
|
var _userConfig_userConfig, _modernjsConfig_server;
|
|
205
206
|
const modernjsConfig = api.getConfig();
|
|
206
207
|
const mfConfig = await getMFConfig(userConfig.originPluginOptions);
|
|
@@ -208,7 +209,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
208
209
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
209
210
|
userConfig.ssrConfig = ssrConfig;
|
|
210
211
|
userConfig.csrConfig = csrConfig;
|
|
211
|
-
var _ref;
|
|
212
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));
|
|
213
213
|
api.modifyBundlerChain((chain)=>{
|
|
214
214
|
const target = chain.get('target');
|
|
@@ -234,6 +234,7 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
234
234
|
}
|
|
235
235
|
});
|
|
236
236
|
api.config(()=>{
|
|
237
|
+
var _ref;
|
|
237
238
|
var _modernjsConfig_tools, _userConfig_csrConfig, _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
238
239
|
const bundlerType = 'rspack' === api.getAppContext().bundlerType ? 'rspack' : 'webpack';
|
|
239
240
|
const ipv4 = getIPV4();
|
|
@@ -256,7 +257,6 @@ const moduleFederationConfigPlugin = (userConfig)=>({
|
|
|
256
257
|
REMOTE_IP_STRATEGY: JSON.stringify(userConfig.remoteIpStrategy)
|
|
257
258
|
};
|
|
258
259
|
if (enableSSR && isDev()) defineConfig['FEDERATION_IPV4'] = JSON.stringify(ipv4);
|
|
259
|
-
var _ref;
|
|
260
260
|
return {
|
|
261
261
|
tools: {
|
|
262
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",
|
|
@@ -140,13 +140,13 @@
|
|
|
140
140
|
"node-fetch": "~3.3.0",
|
|
141
141
|
"jiti": "2.4.2",
|
|
142
142
|
"react-error-boundary": "4.1.2",
|
|
143
|
-
"@module-federation/rsbuild-plugin": "0.
|
|
144
|
-
"@module-federation/bridge-react": "0.
|
|
145
|
-
"@module-federation/enhanced": "0.
|
|
146
|
-
"@module-federation/
|
|
147
|
-
"@module-federation/
|
|
148
|
-
"@module-federation/sdk": "0.
|
|
149
|
-
"@module-federation/cli": "0.
|
|
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",
|
|
@@ -159,7 +159,7 @@
|
|
|
159
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",
|