@module-federation/modern-js 0.9.1 → 0.11.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 +29 -44
- package/dist/cjs/cli/index.js +25 -30
- package/dist/cjs/cli/manifest.js +9 -10
- package/dist/cjs/cli/ssrPlugin.js +46 -40
- package/dist/cjs/cli/utils.js +49 -62
- package/dist/cjs/cli/utils.spec.js +0 -60
- package/dist/cjs/runtime/index.js +2 -0
- package/dist/esm/cli/configPlugin.js +26 -47
- package/dist/esm/cli/index.js +28 -35
- package/dist/esm/cli/manifest.js +9 -10
- package/dist/esm/cli/ssrPlugin.js +45 -44
- package/dist/esm/cli/utils.js +46 -59
- package/dist/esm/cli/utils.spec.js +1 -78
- package/dist/esm/runtime/index.js +2 -1
- package/dist/esm-node/cli/configPlugin.js +27 -43
- package/dist/esm-node/cli/index.js +25 -30
- package/dist/esm-node/cli/manifest.js +9 -10
- package/dist/esm-node/cli/ssrPlugin.js +45 -40
- package/dist/esm-node/cli/utils.js +46 -60
- package/dist/esm-node/cli/utils.spec.js +1 -61
- package/dist/esm-node/runtime/index.js +2 -1
- package/dist/types/cli/configPlugin.d.ts +3 -11
- package/dist/types/cli/manifest.d.ts +1 -1
- package/dist/types/cli/ssrPlugin.d.ts +1 -0
- package/dist/types/cli/utils.d.ts +7 -6
- package/dist/types/runtime/index.d.ts +1 -1
- package/dist/types/types/index.d.ts +1 -1
- package/package.json +13 -13
|
@@ -29,9 +29,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
var configPlugin_exports = {};
|
|
30
30
|
__export(configPlugin_exports, {
|
|
31
31
|
default: () => configPlugin_default,
|
|
32
|
-
|
|
32
|
+
isWebTarget: () => import_utils.isWebTarget,
|
|
33
33
|
moduleFederationConfigPlugin: () => moduleFederationConfigPlugin,
|
|
34
|
-
setEnv: () => setEnv
|
|
34
|
+
setEnv: () => setEnv,
|
|
35
|
+
skipByTarget: () => import_utils.skipByTarget
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(configPlugin_exports);
|
|
37
38
|
var import_path = __toESM(require("path"));
|
|
@@ -42,17 +43,6 @@ function setEnv(enableSSR) {
|
|
|
42
43
|
process.env["MF_SSR_PRJ"] = "true";
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
function modifyBundlerConfig(options) {
|
|
46
|
-
const { mfConfig, config, isServer, modernjsConfig, remoteIpStrategy = "ipv4", bundlerType } = options;
|
|
47
|
-
(0, import_utils.patchMFConfig)(mfConfig, isServer, remoteIpStrategy);
|
|
48
|
-
(0, import_utils.patchBundlerConfig)({
|
|
49
|
-
bundlerType,
|
|
50
|
-
bundlerConfig: config,
|
|
51
|
-
isServer,
|
|
52
|
-
modernjsConfig,
|
|
53
|
-
mfConfig
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
46
|
const moduleFederationConfigPlugin = (userConfig) => ({
|
|
57
47
|
name: "@modern-js/plugin-module-federation-config",
|
|
58
48
|
pre: [
|
|
@@ -62,17 +52,38 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
62
52
|
"@modern-js/plugin-module-federation"
|
|
63
53
|
],
|
|
64
54
|
setup: async (api) => {
|
|
55
|
+
var _userConfig_userConfig, _modernjsConfig_server;
|
|
65
56
|
const modernjsConfig = api.getConfig();
|
|
66
57
|
const mfConfig = await (0, import_utils.getMFConfig)(userConfig.originPluginOptions);
|
|
67
58
|
const csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
68
59
|
const ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
|
|
69
60
|
userConfig.ssrConfig = ssrConfig;
|
|
70
61
|
userConfig.csrConfig = csrConfig;
|
|
62
|
+
var _userConfig_userConfig_ssr;
|
|
63
|
+
const enableSSR = (_userConfig_userConfig_ssr = (_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) !== null && _userConfig_userConfig_ssr !== void 0 ? _userConfig_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
64
|
+
api.modifyBundlerChain((chain) => {
|
|
65
|
+
const target = chain.get("target");
|
|
66
|
+
if ((0, import_utils.skipByTarget)(target)) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const isWeb = (0, import_utils.isWebTarget)(target);
|
|
70
|
+
(0, import_utils.addMyTypes2Ignored)(chain, !isWeb ? ssrConfig : csrConfig);
|
|
71
|
+
const targetMFConfig = !isWeb ? ssrConfig : csrConfig;
|
|
72
|
+
(0, import_utils.patchMFConfig)(targetMFConfig, !isWeb, userConfig.remoteIpStrategy || "ipv4");
|
|
73
|
+
(0, import_utils.patchBundlerConfig)({
|
|
74
|
+
// @ts-expect-error chain type is not correct
|
|
75
|
+
chain,
|
|
76
|
+
isServer: !isWeb,
|
|
77
|
+
modernjsConfig,
|
|
78
|
+
mfConfig,
|
|
79
|
+
enableSSR
|
|
80
|
+
});
|
|
81
|
+
userConfig.distOutputDir = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
82
|
+
});
|
|
71
83
|
api.config(() => {
|
|
72
|
-
var
|
|
84
|
+
var _modernjsConfig_source, _modernjsConfig_source1, _modernjsConfig_dev;
|
|
73
85
|
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
74
86
|
const ipv4 = (0, import_utils.getIPV4)();
|
|
75
|
-
const enableSSR = ((_userConfig_userConfig = userConfig.userConfig) === null || _userConfig_userConfig === void 0 ? void 0 : _userConfig_userConfig.ssr) === false ? false : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
76
87
|
if (userConfig.remoteIpStrategy === void 0) {
|
|
77
88
|
if (!enableSSR) {
|
|
78
89
|
userConfig.remoteIpStrategy = "inherit";
|
|
@@ -83,33 +94,6 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
83
94
|
var _modernjsConfig_source_enableAsyncEntry;
|
|
84
95
|
return {
|
|
85
96
|
tools: {
|
|
86
|
-
bundlerChain(chain, { isServer }) {
|
|
87
|
-
(0, import_utils.addMyTypes2Ignored)(chain, isServer ? ssrConfig : csrConfig);
|
|
88
|
-
},
|
|
89
|
-
rspack(config, { isServer }) {
|
|
90
|
-
var _config_output;
|
|
91
|
-
modifyBundlerConfig({
|
|
92
|
-
bundlerType,
|
|
93
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
94
|
-
config,
|
|
95
|
-
isServer,
|
|
96
|
-
modernjsConfig,
|
|
97
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
98
|
-
});
|
|
99
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
100
|
-
},
|
|
101
|
-
webpack(config, { isServer }) {
|
|
102
|
-
var _config_output;
|
|
103
|
-
modifyBundlerConfig({
|
|
104
|
-
bundlerType,
|
|
105
|
-
mfConfig: isServer ? ssrConfig : csrConfig,
|
|
106
|
-
config,
|
|
107
|
-
isServer,
|
|
108
|
-
modernjsConfig,
|
|
109
|
-
remoteIpStrategy: userConfig.remoteIpStrategy
|
|
110
|
-
});
|
|
111
|
-
userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
112
|
-
},
|
|
113
97
|
devServer: {
|
|
114
98
|
headers: {
|
|
115
99
|
"Access-Control-Allow-Origin": "*",
|
|
@@ -138,7 +122,8 @@ const moduleFederationConfigPlugin = (userConfig) => ({
|
|
|
138
122
|
var configPlugin_default = moduleFederationConfigPlugin;
|
|
139
123
|
// Annotate the CommonJS export names for ESM import in node:
|
|
140
124
|
0 && (module.exports = {
|
|
141
|
-
|
|
125
|
+
isWebTarget,
|
|
142
126
|
moduleFederationConfigPlugin,
|
|
143
|
-
setEnv
|
|
127
|
+
setEnv,
|
|
128
|
+
skipByTarget
|
|
144
129
|
});
|
package/dist/cjs/cli/index.js
CHANGED
|
@@ -27,6 +27,7 @@ var import_enhanced = require("@module-federation/enhanced");
|
|
|
27
27
|
var import_rspack = require("@module-federation/enhanced/rspack");
|
|
28
28
|
var import_configPlugin = require("./configPlugin");
|
|
29
29
|
var import_ssrPlugin = require("./ssrPlugin");
|
|
30
|
+
var import_utils = require("./utils");
|
|
30
31
|
var import_enhanced2 = require("@module-federation/enhanced");
|
|
31
32
|
const moduleFederationPlugin = (userConfig = {}) => {
|
|
32
33
|
const internalModernPluginOptions = {
|
|
@@ -43,37 +44,31 @@ const moduleFederationPlugin = (userConfig = {}) => {
|
|
|
43
44
|
name: "@modern-js/plugin-module-federation",
|
|
44
45
|
setup: async (api) => {
|
|
45
46
|
const modernjsConfig = api.getConfig();
|
|
46
|
-
api.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
70
|
-
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
71
|
-
};
|
|
72
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
47
|
+
api.modifyBundlerChain((chain) => {
|
|
48
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
49
|
+
const browserPluginOptions = internalModernPluginOptions.csrConfig;
|
|
50
|
+
const MFPlugin = bundlerType === "webpack" ? import_enhanced.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
51
|
+
if ((0, import_utils.isWebTarget)(chain.get("target"))) {
|
|
52
|
+
chain.plugin("plugin-module-federation").use(MFPlugin, [
|
|
53
|
+
browserPluginOptions
|
|
54
|
+
]).init((Plugin, args) => {
|
|
55
|
+
internalModernPluginOptions.browserPlugin = new Plugin(args[0]);
|
|
56
|
+
return internalModernPluginOptions.browserPlugin;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (bundlerType === "webpack") {
|
|
60
|
+
var _modernjsConfig_source;
|
|
61
|
+
const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
|
|
62
|
+
if (!enableAsyncEntry && browserPluginOptions.async !== false) {
|
|
63
|
+
const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
|
|
64
|
+
eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
|
|
65
|
+
excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
|
|
66
|
+
};
|
|
67
|
+
chain.plugin("async-boundary-plugin").use(import_enhanced.AsyncBoundaryPlugin, [
|
|
68
|
+
asyncBoundaryPluginOptions
|
|
69
|
+
]);
|
|
75
70
|
}
|
|
76
|
-
}
|
|
71
|
+
}
|
|
77
72
|
});
|
|
78
73
|
},
|
|
79
74
|
usePlugins: [
|
package/dist/cjs/cli/manifest.js
CHANGED
|
@@ -33,27 +33,26 @@ __export(manifest_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(manifest_exports);
|
|
34
34
|
var import_path = __toESM(require("path"));
|
|
35
35
|
var import_utils = require("@modern-js/utils");
|
|
36
|
-
|
|
37
|
-
function mergeStats(browserStats, nodeStats) {
|
|
36
|
+
function mergeStats(browserStats, nodeStats, ssrDir) {
|
|
38
37
|
const ssrRemoteEntry = nodeStats.metaData.remoteEntry;
|
|
39
|
-
ssrRemoteEntry.path =
|
|
38
|
+
ssrRemoteEntry.path = ssrDir;
|
|
40
39
|
browserStats.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
41
40
|
return browserStats;
|
|
42
41
|
}
|
|
43
|
-
function mergeManifest(browserManifest, nodeManifest) {
|
|
42
|
+
function mergeManifest(browserManifest, nodeManifest, ssrDir) {
|
|
44
43
|
const ssrRemoteEntry = nodeManifest.metaData.remoteEntry;
|
|
45
|
-
ssrRemoteEntry.path =
|
|
44
|
+
ssrRemoteEntry.path = ssrDir;
|
|
46
45
|
browserManifest.metaData.ssrRemoteEntry = ssrRemoteEntry;
|
|
47
46
|
return browserManifest;
|
|
48
47
|
}
|
|
49
|
-
function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
48
|
+
function mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir) {
|
|
50
49
|
const nodeResourceInfo = nodePlugin.statsResourceInfo;
|
|
51
50
|
const browserResourceInfo = browserPlugin.statsResourceInfo;
|
|
52
51
|
if (!browserResourceInfo || !nodeResourceInfo || !browserResourceInfo.stats || !nodeResourceInfo.stats || !browserResourceInfo.manifest || !nodeResourceInfo.manifest) {
|
|
53
52
|
throw new Error("can not get browserResourceInfo or nodeResourceInfo");
|
|
54
53
|
}
|
|
55
|
-
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats);
|
|
56
|
-
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest);
|
|
54
|
+
const mergedStats = mergeStats(browserResourceInfo.stats.stats, nodeResourceInfo.stats.stats, ssrDir);
|
|
55
|
+
const mergedManifest = mergeManifest(browserResourceInfo.manifest.manifest, nodeResourceInfo.manifest.manifest, ssrDir);
|
|
57
56
|
return {
|
|
58
57
|
mergedStats,
|
|
59
58
|
mergedStatsFilePath: browserResourceInfo.stats.filename,
|
|
@@ -61,8 +60,8 @@ function mergeStatsAndManifest(nodePlugin, browserPlugin) {
|
|
|
61
60
|
mergedManifestFilePath: browserResourceInfo.manifest.filename
|
|
62
61
|
};
|
|
63
62
|
}
|
|
64
|
-
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir) {
|
|
65
|
-
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin);
|
|
63
|
+
function updateStatsAndManifest(nodePlugin, browserPlugin, outputDir, ssrDir) {
|
|
64
|
+
const { mergedStats, mergedStatsFilePath, mergedManifest, mergedManifestFilePath } = mergeStatsAndManifest(nodePlugin, browserPlugin, ssrDir);
|
|
66
65
|
import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedStatsFilePath), JSON.stringify(mergedStats, null, 2));
|
|
67
66
|
import_utils.fs.writeFileSync(import_path.default.resolve(outputDir, mergedManifestFilePath), JSON.stringify(mergedManifest, null, 2));
|
|
68
67
|
}
|
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var ssrPlugin_exports = {};
|
|
30
30
|
__export(ssrPlugin_exports, {
|
|
31
|
+
CHAIN_MF_PLUGIN_ID: () => CHAIN_MF_PLUGIN_ID,
|
|
31
32
|
default: () => ssrPlugin_default,
|
|
32
33
|
moduleFederationSSRPlugin: () => moduleFederationSSRPlugin,
|
|
33
34
|
setEnv: () => setEnv
|
|
@@ -40,11 +41,14 @@ var import_rspack = require("@module-federation/enhanced/rspack");
|
|
|
40
41
|
var import_universe_entry_chunk_tracker_plugin = __toESM(require("@module-federation/node/universe-entry-chunk-tracker-plugin"));
|
|
41
42
|
var import_manifest = require("./manifest");
|
|
42
43
|
var import_constant = require("./constant");
|
|
44
|
+
var import_constant2 = require("../constant");
|
|
43
45
|
var import_logger = __toESM(require("./logger"));
|
|
46
|
+
var import_utils2 = require("./utils");
|
|
44
47
|
function setEnv() {
|
|
45
48
|
process.env["MF_DISABLE_EMIT_STATS"] = "true";
|
|
46
49
|
process.env["MF_SSR_PRJ"] = "true";
|
|
47
50
|
}
|
|
51
|
+
const CHAIN_MF_PLUGIN_ID = "plugin-module-federation-server";
|
|
48
52
|
const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
49
53
|
name: "@modern-js/plugin-module-federation-ssr",
|
|
50
54
|
pre: [
|
|
@@ -54,7 +58,10 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
54
58
|
setup: async (api) => {
|
|
55
59
|
var _pluginOptions_userConfig, _modernjsConfig_server;
|
|
56
60
|
const modernjsConfig = api.getConfig();
|
|
57
|
-
|
|
61
|
+
var _pluginOptions_userConfig_ssr;
|
|
62
|
+
const enableSSR = (_pluginOptions_userConfig_ssr = (_pluginOptions_userConfig = pluginOptions.userConfig) === null || _pluginOptions_userConfig === void 0 ? void 0 : _pluginOptions_userConfig.ssr) !== null && _pluginOptions_userConfig_ssr !== void 0 ? _pluginOptions_userConfig_ssr : Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
63
|
+
let csrOutputPath = "";
|
|
64
|
+
let ssrOutputPath = "";
|
|
58
65
|
if (!enableSSR) {
|
|
59
66
|
return;
|
|
60
67
|
}
|
|
@@ -76,33 +83,44 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
76
83
|
plugins
|
|
77
84
|
};
|
|
78
85
|
});
|
|
86
|
+
api.modifyBundlerChain((chain) => {
|
|
87
|
+
const target = chain.get("target");
|
|
88
|
+
if ((0, import_utils2.skipByTarget)(target)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const bundlerType = api.getAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
|
|
92
|
+
const MFPlugin = bundlerType === "webpack" ? import_webpack.ModuleFederationPlugin : import_rspack.ModuleFederationPlugin;
|
|
93
|
+
const isWeb = (0, import_utils2.isWebTarget)(target);
|
|
94
|
+
if (!isWeb) {
|
|
95
|
+
if (!chain.plugins.has(CHAIN_MF_PLUGIN_ID)) {
|
|
96
|
+
chain.plugin(CHAIN_MF_PLUGIN_ID).use(MFPlugin, [
|
|
97
|
+
pluginOptions.ssrConfig
|
|
98
|
+
]).init((Plugin, args) => {
|
|
99
|
+
pluginOptions.nodePlugin = new Plugin(args[0]);
|
|
100
|
+
return pluginOptions.nodePlugin;
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
if (!isWeb) {
|
|
105
|
+
chain.target("async-node");
|
|
106
|
+
if (import_constant.isDev) {
|
|
107
|
+
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (import_constant.isDev && isWeb) {
|
|
111
|
+
chain.externals({
|
|
112
|
+
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (!isWeb) {
|
|
116
|
+
ssrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), `dist/${import_constant2.MODERN_JS_SERVER_DIR}`);
|
|
117
|
+
} else {
|
|
118
|
+
csrOutputPath = chain.output.get("path") || import_path.default.resolve(process.cwd(), "dist");
|
|
119
|
+
}
|
|
120
|
+
});
|
|
79
121
|
api.config(() => {
|
|
80
122
|
return {
|
|
81
123
|
tools: {
|
|
82
|
-
rspack(config, { isServer }) {
|
|
83
|
-
if (isServer) {
|
|
84
|
-
if (!pluginOptions.nodePlugin) {
|
|
85
|
-
var _config_plugins;
|
|
86
|
-
pluginOptions.nodePlugin = new import_rspack.ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
87
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
88
|
-
}
|
|
89
|
-
} else {
|
|
90
|
-
var _config_output;
|
|
91
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
webpack(config, { isServer }) {
|
|
95
|
-
if (isServer) {
|
|
96
|
-
if (!pluginOptions.nodePlugin) {
|
|
97
|
-
var _config_plugins;
|
|
98
|
-
pluginOptions.nodePlugin = new import_webpack.ModuleFederationPlugin(pluginOptions.ssrConfig);
|
|
99
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(pluginOptions.nodePlugin);
|
|
100
|
-
}
|
|
101
|
-
} else {
|
|
102
|
-
var _config_output;
|
|
103
|
-
pluginOptions.distOutputDir = pluginOptions.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
124
|
devServer: {
|
|
107
125
|
before: [
|
|
108
126
|
(req, res, next) => {
|
|
@@ -128,36 +146,24 @@ const moduleFederationSSRPlugin = (pluginOptions) => ({
|
|
|
128
146
|
}
|
|
129
147
|
}
|
|
130
148
|
]
|
|
131
|
-
},
|
|
132
|
-
bundlerChain(chain, { isServer }) {
|
|
133
|
-
if (isServer) {
|
|
134
|
-
chain.target("async-node");
|
|
135
|
-
if (import_constant.isDev) {
|
|
136
|
-
chain.plugin("UniverseEntryChunkTrackerPlugin").use(import_universe_entry_chunk_tracker_plugin.default);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (import_constant.isDev && !isServer) {
|
|
140
|
-
chain.externals({
|
|
141
|
-
"@module-federation/node/utils": "NOT_USED_IN_BROWSER"
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
149
|
}
|
|
145
150
|
}
|
|
146
151
|
};
|
|
147
152
|
});
|
|
148
153
|
api.onAfterBuild(() => {
|
|
149
154
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
150
|
-
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
155
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir, import_path.default.relative(csrOutputPath, ssrOutputPath));
|
|
151
156
|
});
|
|
152
157
|
api.onDevCompileDone(() => {
|
|
153
158
|
const { nodePlugin, browserPlugin, distOutputDir } = pluginOptions;
|
|
154
|
-
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir);
|
|
159
|
+
(0, import_manifest.updateStatsAndManifest)(nodePlugin, browserPlugin, distOutputDir, import_path.default.relative(csrOutputPath, ssrOutputPath));
|
|
155
160
|
});
|
|
156
161
|
}
|
|
157
162
|
});
|
|
158
163
|
var ssrPlugin_default = moduleFederationSSRPlugin;
|
|
159
164
|
// Annotate the CommonJS export names for ESM import in node:
|
|
160
165
|
0 && (module.exports = {
|
|
166
|
+
CHAIN_MF_PLUGIN_ID,
|
|
161
167
|
moduleFederationSSRPlugin,
|
|
162
168
|
setEnv
|
|
163
169
|
});
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -31,9 +31,10 @@ __export(utils_exports, {
|
|
|
31
31
|
addMyTypes2Ignored: () => addMyTypes2Ignored,
|
|
32
32
|
getIPV4: () => getIPV4,
|
|
33
33
|
getMFConfig: () => getMFConfig,
|
|
34
|
+
isWebTarget: () => isWebTarget,
|
|
34
35
|
patchBundlerConfig: () => patchBundlerConfig,
|
|
35
|
-
|
|
36
|
-
|
|
36
|
+
patchMFConfig: () => patchMFConfig,
|
|
37
|
+
skipByTarget: () => skipByTarget
|
|
37
38
|
});
|
|
38
39
|
module.exports = __toCommonJS(utils_exports);
|
|
39
40
|
var import_os = __toESM(require("os"));
|
|
@@ -173,19 +174,20 @@ const patchMFConfig = (mfConfig, isServer, remoteIpStrategy) => {
|
|
|
173
174
|
mfConfig.dev = false;
|
|
174
175
|
return mfConfig;
|
|
175
176
|
};
|
|
176
|
-
function patchIgnoreWarning(
|
|
177
|
-
|
|
177
|
+
function patchIgnoreWarning(chain) {
|
|
178
|
+
const ignoreWarnings = chain.get("ignoreWarnings") || [];
|
|
178
179
|
const ignoredMsgs = [
|
|
179
180
|
"external script",
|
|
180
181
|
"process.env.WS_NO_BUFFER_UTIL",
|
|
181
182
|
`Can't resolve 'utf-8-validate`
|
|
182
183
|
];
|
|
183
|
-
|
|
184
|
+
ignoreWarnings.push((warning) => {
|
|
184
185
|
if (ignoredMsgs.some((msg) => warning.message.includes(msg))) {
|
|
185
186
|
return true;
|
|
186
187
|
}
|
|
187
188
|
return false;
|
|
188
189
|
});
|
|
190
|
+
chain.ignoreWarnings(ignoreWarnings);
|
|
189
191
|
}
|
|
190
192
|
function addMyTypes2Ignored(chain, mfConfig) {
|
|
191
193
|
const watchOptions = chain.get("watchOptions");
|
|
@@ -224,55 +226,43 @@ function addMyTypes2Ignored(chain, mfConfig) {
|
|
|
224
226
|
});
|
|
225
227
|
}
|
|
226
228
|
function patchBundlerConfig(options) {
|
|
227
|
-
var
|
|
228
|
-
const {
|
|
229
|
-
|
|
230
|
-
(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
238
|
-
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
239
|
-
}
|
|
229
|
+
var _modernjsConfig_deploy;
|
|
230
|
+
const { chain, modernjsConfig, isServer, mfConfig, enableSSR } = options;
|
|
231
|
+
chain.optimization.delete("runtimeChunk");
|
|
232
|
+
patchIgnoreWarning(chain);
|
|
233
|
+
if (!chain.output.get("chunkLoadingGlobal")) {
|
|
234
|
+
chain.output.chunkLoadingGlobal(`chunk_${mfConfig.name}`);
|
|
235
|
+
}
|
|
236
|
+
if (!chain.output.get("uniqueName")) {
|
|
237
|
+
chain.output.uniqueName(mfConfig.name);
|
|
240
238
|
}
|
|
239
|
+
const splitChunkConfig = chain.optimization.splitChunks.entries();
|
|
241
240
|
if (!isServer) {
|
|
242
|
-
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig,
|
|
241
|
+
(0, import_utils.autoDeleteSplitChunkCacheGroups)(mfConfig, splitChunkConfig);
|
|
243
242
|
}
|
|
244
|
-
if (!isServer && enableSSR &&
|
|
245
|
-
|
|
243
|
+
if (!isServer && enableSSR && splitChunkConfig && typeof splitChunkConfig === "object" && splitChunkConfig.cacheGroups) {
|
|
244
|
+
splitChunkConfig.chunks = "async";
|
|
246
245
|
import_logger.default.warn(`splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
247
246
|
}
|
|
248
|
-
if (isDev &&
|
|
249
|
-
var _modernjsConfig_dev,
|
|
250
|
-
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((
|
|
247
|
+
if (isDev && chain.output.get("publicPath") === "auto") {
|
|
248
|
+
var _modernjsConfig_dev, _modernjsConfig_server;
|
|
249
|
+
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.port) || 8080;
|
|
251
250
|
const publicPath = `http://localhost:${port}/`;
|
|
252
|
-
|
|
251
|
+
chain.output.publicPath(publicPath);
|
|
253
252
|
}
|
|
254
253
|
if (isServer && enableSSR) {
|
|
255
|
-
const
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
if (output && typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
254
|
+
const uniqueName = mfConfig.name || chain.output.get("uniqueName");
|
|
255
|
+
const chunkFileName = chain.output.get("chunkFilename");
|
|
256
|
+
if (typeof chunkFileName === "string" && uniqueName && !chunkFileName.includes(uniqueName)) {
|
|
259
257
|
const suffix = `${(0, import_sdk.encodeName)(uniqueName)}-[chunkhash].js`;
|
|
260
|
-
output.chunkFilename
|
|
258
|
+
chain.output.chunkFilename(chunkFileName.replace(".js", suffix));
|
|
261
259
|
}
|
|
262
260
|
}
|
|
263
261
|
if (isDev && enableSSR && !isServer) {
|
|
264
|
-
|
|
265
|
-
...bundlerConfig.resolve.fallback,
|
|
266
|
-
crypto: false,
|
|
267
|
-
stream: false,
|
|
268
|
-
vm: false
|
|
269
|
-
};
|
|
262
|
+
chain.resolve.fallback.set("crypto", false).set("stream", false).set("vm", false);
|
|
270
263
|
}
|
|
271
264
|
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
272
|
-
|
|
273
|
-
bundlerConfig.optimization = {};
|
|
274
|
-
}
|
|
275
|
-
bundlerConfig.optimization.usedExports = false;
|
|
265
|
+
chain.optimization.usedExports(false);
|
|
276
266
|
}
|
|
277
267
|
}
|
|
278
268
|
const localIpv4 = "127.0.0.1";
|
|
@@ -300,34 +290,31 @@ const getIPV4 = () => {
|
|
|
300
290
|
};
|
|
301
291
|
return ipv4Interface.address;
|
|
302
292
|
};
|
|
303
|
-
const
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
293
|
+
const isWebTarget = (target) => {
|
|
294
|
+
const WEB_TARGET = "web";
|
|
295
|
+
if (Array.isArray(target)) {
|
|
296
|
+
return target.includes(WEB_TARGET);
|
|
297
|
+
} else if (typeof target === "string") {
|
|
298
|
+
return target === WEB_TARGET;
|
|
299
|
+
}
|
|
300
|
+
return false;
|
|
311
301
|
};
|
|
312
|
-
const
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
"
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
antd: SPLIT_CHUNK_MAP.ANTD,
|
|
321
|
-
"@arco-design/web-react": SPLIT_CHUNK_MAP.ARCO,
|
|
322
|
-
"@douyinfe/semi-ui": SPLIT_CHUNK_MAP.SEMI,
|
|
323
|
-
axios: SPLIT_CHUNK_MAP.AXIOS
|
|
302
|
+
const skipByTarget = (target) => {
|
|
303
|
+
const IGNORE_TARGET = "webworker";
|
|
304
|
+
if (Array.isArray(target)) {
|
|
305
|
+
return target.includes(IGNORE_TARGET);
|
|
306
|
+
} else if (typeof target === "string") {
|
|
307
|
+
return target === IGNORE_TARGET;
|
|
308
|
+
}
|
|
309
|
+
return false;
|
|
324
310
|
};
|
|
325
311
|
// Annotate the CommonJS export names for ESM import in node:
|
|
326
312
|
0 && (module.exports = {
|
|
327
313
|
addMyTypes2Ignored,
|
|
328
314
|
getIPV4,
|
|
329
315
|
getMFConfig,
|
|
316
|
+
isWebTarget,
|
|
330
317
|
patchBundlerConfig,
|
|
331
|
-
|
|
332
|
-
|
|
318
|
+
patchMFConfig,
|
|
319
|
+
skipByTarget
|
|
333
320
|
});
|
|
@@ -109,63 +109,3 @@ const mfConfig = {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
});
|
|
112
|
-
(0, import_vitest.describe)("patchBundlerConfig", async () => {
|
|
113
|
-
(0, import_vitest.it)("patchBundlerConfig: server", async () => {
|
|
114
|
-
const bundlerConfig = {
|
|
115
|
-
output: {
|
|
116
|
-
publicPath: "auto"
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
(0, import_utils.patchBundlerConfig)({
|
|
120
|
-
bundlerType: "webpack",
|
|
121
|
-
bundlerConfig,
|
|
122
|
-
isServer: true,
|
|
123
|
-
modernjsConfig: {
|
|
124
|
-
server: {
|
|
125
|
-
ssr: {
|
|
126
|
-
mode: "stream"
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
mfConfig
|
|
131
|
-
});
|
|
132
|
-
const expectedConfig = {
|
|
133
|
-
output: {
|
|
134
|
-
chunkLoadingGlobal: "chunk_host",
|
|
135
|
-
publicPath: "auto",
|
|
136
|
-
uniqueName: "host"
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
140
|
-
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
141
|
-
});
|
|
142
|
-
(0, import_vitest.it)("patchBundlerConfig: client", async () => {
|
|
143
|
-
const bundlerConfig = {
|
|
144
|
-
output: {
|
|
145
|
-
publicPath: "auto"
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
(0, import_utils.patchBundlerConfig)({
|
|
149
|
-
bundlerType: "webpack",
|
|
150
|
-
bundlerConfig,
|
|
151
|
-
isServer: false,
|
|
152
|
-
modernjsConfig: {
|
|
153
|
-
server: {
|
|
154
|
-
ssr: {
|
|
155
|
-
mode: "stream"
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
mfConfig
|
|
160
|
-
});
|
|
161
|
-
const expectedConfig = {
|
|
162
|
-
output: {
|
|
163
|
-
chunkLoadingGlobal: "chunk_host",
|
|
164
|
-
publicPath: "auto",
|
|
165
|
-
uniqueName: "host"
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
bundlerConfig === null || bundlerConfig === void 0 ? true : delete bundlerConfig.ignoreWarnings;
|
|
169
|
-
(0, import_vitest.expect)(bundlerConfig).toStrictEqual(expectedConfig);
|
|
170
|
-
});
|
|
171
|
-
});
|
|
@@ -19,6 +19,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var runtime_exports = {};
|
|
21
21
|
__export(runtime_exports, {
|
|
22
|
+
collectSSRAssets: () => import_createRemoteSSRComponent.collectSSRAssets,
|
|
22
23
|
createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(runtime_exports);
|
|
@@ -26,6 +27,7 @@ __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), modu
|
|
|
26
27
|
var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
|
|
27
28
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
29
|
0 && (module.exports = {
|
|
30
|
+
collectSSRAssets,
|
|
29
31
|
createRemoteSSRComponent,
|
|
30
32
|
...require("@module-federation/enhanced/runtime")
|
|
31
33
|
});
|