@module-federation/modern-js 0.0.0-next-20240625025206 → 0.0.0-next-20240626050252
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/README.md +1 -1
- package/dist/cjs/cli/index.js +1 -1
- package/dist/cjs/cli/utils.js +32 -9
- package/dist/cjs/cli/utils.spec.js +6 -2
- package/dist/cjs/constant.js +5 -2
- package/dist/esm/cli/index.js +2 -2
- package/dist/esm/cli/utils.js +31 -8
- package/dist/esm/cli/utils.spec.js +6 -2
- package/dist/esm/constant.js +3 -1
- package/dist/esm-node/cli/index.js +2 -2
- package/dist/esm-node/cli/utils.js +33 -10
- package/dist/esm-node/cli/utils.spec.js +6 -2
- package/dist/esm-node/constant.js +3 -1
- package/dist/types/constant.d.ts +1 -0
- package/package.json +12 -12
package/README.md
CHANGED
package/dist/cjs/cli/index.js
CHANGED
|
@@ -94,7 +94,7 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
94
94
|
tools: {
|
|
95
95
|
rspack(config) {
|
|
96
96
|
if (enableSSR) {
|
|
97
|
-
throw new Error(
|
|
97
|
+
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} not support ssr for rspack bundler yet!`);
|
|
98
98
|
}
|
|
99
99
|
modifyBundlerConfig(config, false);
|
|
100
100
|
},
|
package/dist/cjs/cli/utils.js
CHANGED
|
@@ -41,6 +41,7 @@ var import_os = __toESM(require("os"));
|
|
|
41
41
|
var import_node_bundle_require = require("@modern-js/node-bundle-require");
|
|
42
42
|
var import_constant = require("../constant");
|
|
43
43
|
const defaultPath = import_path.default.resolve(process.cwd(), "module-federation.config.ts");
|
|
44
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
44
45
|
const getMFConfig = async (userConfig) => {
|
|
45
46
|
const { config, configPath } = userConfig;
|
|
46
47
|
if (config) {
|
|
@@ -53,6 +54,9 @@ const getMFConfig = async (userConfig) => {
|
|
|
53
54
|
if (mfConfig.remoteType === void 0) {
|
|
54
55
|
mfConfig.remoteType = "script";
|
|
55
56
|
}
|
|
57
|
+
if (!mfConfig.name) {
|
|
58
|
+
throw new Error(`${import_constant.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
59
|
+
}
|
|
56
60
|
return mfConfig;
|
|
57
61
|
};
|
|
58
62
|
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
@@ -90,11 +94,10 @@ const replaceRemoteUrl = async (mfConfig) => {
|
|
|
90
94
|
handleRemoteObject(mfConfig.remotes);
|
|
91
95
|
}
|
|
92
96
|
};
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
];
|
|
97
|
+
const patchDTSConfig = (mfConfig, isServer) => {
|
|
98
|
+
if (isServer) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
98
101
|
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
99
102
|
if (mfConfig.dts !== false) {
|
|
100
103
|
var _mfConfig_dts, _mfConfig_dts1;
|
|
@@ -122,6 +125,12 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
}
|
|
128
|
+
};
|
|
129
|
+
const patchMFConfig = (mfConfig, isServer) => {
|
|
130
|
+
const runtimePlugins = [
|
|
131
|
+
...mfConfig.runtimePlugins || []
|
|
132
|
+
];
|
|
133
|
+
patchDTSConfig(mfConfig, isServer);
|
|
125
134
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
126
135
|
if (isDev) {
|
|
127
136
|
injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -169,18 +178,27 @@ function getTargetEnvConfig(mfConfig, isServer) {
|
|
|
169
178
|
return patchedMFConfig;
|
|
170
179
|
}
|
|
171
180
|
function patchWebpackConfig(options) {
|
|
172
|
-
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
|
|
181
|
+
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
173
182
|
const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
|
|
174
183
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
175
184
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
185
|
+
if (bundlerConfig.output) {
|
|
186
|
+
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
187
|
+
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
188
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${mfConfig.name}`;
|
|
189
|
+
}
|
|
190
|
+
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
191
|
+
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
176
194
|
if (!isServer) {
|
|
177
195
|
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
178
196
|
}
|
|
179
197
|
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
180
198
|
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
181
|
-
console.warn(
|
|
199
|
+
console.warn(`${import_constant.PLUGIN_IDENTIFIER} splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
182
200
|
}
|
|
183
|
-
if (((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
201
|
+
if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
184
202
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
185
203
|
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server1 = modernjsConfig.server) === null || _modernjsConfig_server1 === void 0 ? void 0 : _modernjsConfig_server1.port) || 8080;
|
|
186
204
|
const publicPath = `http://localhost:${port}/`;
|
|
@@ -195,7 +213,6 @@ function patchWebpackConfig(options) {
|
|
|
195
213
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
196
214
|
}
|
|
197
215
|
}
|
|
198
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
199
216
|
if (isDev && enableSSR && !isServer) {
|
|
200
217
|
bundlerConfig.resolve.fallback = {
|
|
201
218
|
...bundlerConfig.resolve.fallback,
|
|
@@ -204,6 +221,12 @@ function patchWebpackConfig(options) {
|
|
|
204
221
|
vm: false
|
|
205
222
|
};
|
|
206
223
|
}
|
|
224
|
+
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
225
|
+
if (!bundlerConfig.optimization) {
|
|
226
|
+
bundlerConfig.optimization = {};
|
|
227
|
+
}
|
|
228
|
+
bundlerConfig.optimization.usedExports = false;
|
|
229
|
+
}
|
|
207
230
|
}
|
|
208
231
|
const localIpv4 = "127.0.0.1";
|
|
209
232
|
const getIpv4Interfaces = () => {
|
|
@@ -124,7 +124,9 @@ const mfConfig = {
|
|
|
124
124
|
});
|
|
125
125
|
(0, import_vitest.expect)(bundlerConfig).toStrictEqual({
|
|
126
126
|
output: {
|
|
127
|
-
|
|
127
|
+
chunkLoadingGlobal: "chunk_host",
|
|
128
|
+
publicPath: "auto",
|
|
129
|
+
uniqueName: "host"
|
|
128
130
|
}
|
|
129
131
|
});
|
|
130
132
|
});
|
|
@@ -148,7 +150,9 @@ const mfConfig = {
|
|
|
148
150
|
});
|
|
149
151
|
(0, import_vitest.expect)(bundlerConfig).toStrictEqual({
|
|
150
152
|
output: {
|
|
151
|
-
|
|
153
|
+
chunkLoadingGlobal: "chunk_host",
|
|
154
|
+
publicPath: "auto",
|
|
155
|
+
uniqueName: "host"
|
|
152
156
|
}
|
|
153
157
|
});
|
|
154
158
|
});
|
package/dist/cjs/constant.js
CHANGED
|
@@ -19,13 +19,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var constant_exports = {};
|
|
20
20
|
__export(constant_exports, {
|
|
21
21
|
LOCALHOST: () => LOCALHOST,
|
|
22
|
-
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR
|
|
22
|
+
MODERN_JS_SERVER_DIR: () => MODERN_JS_SERVER_DIR,
|
|
23
|
+
PLUGIN_IDENTIFIER: () => PLUGIN_IDENTIFIER
|
|
23
24
|
});
|
|
24
25
|
module.exports = __toCommonJS(constant_exports);
|
|
25
26
|
const MODERN_JS_SERVER_DIR = "bundles";
|
|
26
27
|
const LOCALHOST = "localhost";
|
|
28
|
+
const PLUGIN_IDENTIFIER = "[ Modern.js Module Federation ]";
|
|
27
29
|
// Annotate the CommonJS export names for ESM import in node:
|
|
28
30
|
0 && (module.exports = {
|
|
29
31
|
LOCALHOST,
|
|
30
|
-
MODERN_JS_SERVER_DIR
|
|
32
|
+
MODERN_JS_SERVER_DIR,
|
|
33
|
+
PLUGIN_IDENTIFIER
|
|
31
34
|
});
|
package/dist/esm/cli/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
|
|
|
7
7
|
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
8
8
|
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
|
|
9
9
|
import { updateStatsAndManifest } from "./manifest";
|
|
10
|
-
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
10
|
+
import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
|
|
11
11
|
var SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
|
|
12
12
|
var isDev = process.env.NODE_ENV === "development";
|
|
13
13
|
var moduleFederationPlugin = function() {
|
|
@@ -75,7 +75,7 @@ var moduleFederationPlugin = function() {
|
|
|
75
75
|
tools: {
|
|
76
76
|
rspack: function rspack(config) {
|
|
77
77
|
if (enableSSR) {
|
|
78
|
-
throw new Error("
|
|
78
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " not support ssr for rspack bundler yet!"));
|
|
79
79
|
}
|
|
80
80
|
modifyBundlerConfig(config, false);
|
|
81
81
|
},
|
package/dist/esm/cli/utils.js
CHANGED
|
@@ -7,8 +7,9 @@ import { encodeName } from "@module-federation/sdk";
|
|
|
7
7
|
import path from "path";
|
|
8
8
|
import os from "os";
|
|
9
9
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
10
|
-
import { LOCALHOST } from "../constant";
|
|
10
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
11
11
|
var defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
12
|
+
var isDev = process.env.NODE_ENV === "development";
|
|
12
13
|
var getMFConfig = function() {
|
|
13
14
|
var _ref = _async_to_generator(function(userConfig) {
|
|
14
15
|
var config, configPath, mfConfigPath, preBundlePath, mfConfig;
|
|
@@ -44,6 +45,9 @@ var getMFConfig = function() {
|
|
|
44
45
|
if (mfConfig.remoteType === void 0) {
|
|
45
46
|
mfConfig.remoteType = "script";
|
|
46
47
|
}
|
|
48
|
+
if (!mfConfig.name) {
|
|
49
|
+
throw new Error("".concat(PLUGIN_IDENTIFIER, " mfConfig.name can not be empty!"));
|
|
50
|
+
}
|
|
47
51
|
return [
|
|
48
52
|
2,
|
|
49
53
|
mfConfig
|
|
@@ -103,9 +107,10 @@ var replaceRemoteUrl = function() {
|
|
|
103
107
|
return _ref.apply(this, arguments);
|
|
104
108
|
};
|
|
105
109
|
}();
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
var patchDTSConfig = function(mfConfig, isServer) {
|
|
111
|
+
if (isServer) {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
109
114
|
var ModernJSRuntime = "@modern-js/runtime/mf";
|
|
110
115
|
if (mfConfig.dts !== false) {
|
|
111
116
|
var _mfConfig_dts, _mfConfig_dts1;
|
|
@@ -133,6 +138,10 @@ var patchMFConfig = function(mfConfig, isServer) {
|
|
|
133
138
|
}
|
|
134
139
|
}
|
|
135
140
|
}
|
|
141
|
+
};
|
|
142
|
+
var patchMFConfig = function(mfConfig, isServer) {
|
|
143
|
+
var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
|
|
144
|
+
patchDTSConfig(mfConfig, isServer);
|
|
136
145
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
137
146
|
if (isDev) {
|
|
138
147
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -175,18 +184,27 @@ function getTargetEnvConfig(mfConfig, isServer) {
|
|
|
175
184
|
return patchedMFConfig;
|
|
176
185
|
}
|
|
177
186
|
function patchWebpackConfig(options) {
|
|
178
|
-
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
|
|
187
|
+
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
179
188
|
var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
|
|
180
189
|
var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
181
190
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
191
|
+
if (bundlerConfig.output) {
|
|
192
|
+
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
193
|
+
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
194
|
+
bundlerConfig.output.chunkLoadingGlobal = "chunk_".concat(mfConfig.name);
|
|
195
|
+
}
|
|
196
|
+
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
197
|
+
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
182
200
|
if (!isServer) {
|
|
183
201
|
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
184
202
|
}
|
|
185
203
|
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
186
204
|
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
187
|
-
console.warn(
|
|
205
|
+
console.warn("".concat(PLUGIN_IDENTIFIER, ' splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"'));
|
|
188
206
|
}
|
|
189
|
-
if (((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
207
|
+
if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
190
208
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
191
209
|
var port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server1 = modernjsConfig.server) === null || _modernjsConfig_server1 === void 0 ? void 0 : _modernjsConfig_server1.port) || 8080;
|
|
192
210
|
var publicPath = "http://localhost:".concat(port, "/");
|
|
@@ -201,7 +219,6 @@ function patchWebpackConfig(options) {
|
|
|
201
219
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
202
220
|
}
|
|
203
221
|
}
|
|
204
|
-
var isDev = process.env.NODE_ENV === "development";
|
|
205
222
|
if (isDev && enableSSR && !isServer) {
|
|
206
223
|
bundlerConfig.resolve.fallback = _object_spread_props(_object_spread({}, bundlerConfig.resolve.fallback), {
|
|
207
224
|
crypto: false,
|
|
@@ -209,6 +226,12 @@ function patchWebpackConfig(options) {
|
|
|
209
226
|
vm: false
|
|
210
227
|
});
|
|
211
228
|
}
|
|
229
|
+
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
230
|
+
if (!bundlerConfig.optimization) {
|
|
231
|
+
bundlerConfig.optimization = {};
|
|
232
|
+
}
|
|
233
|
+
bundlerConfig.optimization.usedExports = false;
|
|
234
|
+
}
|
|
212
235
|
}
|
|
213
236
|
var localIpv4 = "127.0.0.1";
|
|
214
237
|
var getIpv4Interfaces = function() {
|
|
@@ -123,7 +123,9 @@ describe("patchWebpackConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
123
123
|
});
|
|
124
124
|
expect(bundlerConfig).toStrictEqual({
|
|
125
125
|
output: {
|
|
126
|
-
|
|
126
|
+
chunkLoadingGlobal: "chunk_host",
|
|
127
|
+
publicPath: "auto",
|
|
128
|
+
uniqueName: "host"
|
|
127
129
|
}
|
|
128
130
|
});
|
|
129
131
|
return [
|
|
@@ -153,7 +155,9 @@ describe("patchWebpackConfig", /* @__PURE__ */ _async_to_generator(function() {
|
|
|
153
155
|
});
|
|
154
156
|
expect(bundlerConfig).toStrictEqual({
|
|
155
157
|
output: {
|
|
156
|
-
|
|
158
|
+
chunkLoadingGlobal: "chunk_host",
|
|
159
|
+
publicPath: "auto",
|
|
160
|
+
uniqueName: "host"
|
|
157
161
|
}
|
|
158
162
|
});
|
|
159
163
|
return [
|
package/dist/esm/constant.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-
|
|
|
5
5
|
import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
|
|
6
6
|
import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
|
|
7
7
|
import { updateStatsAndManifest } from "./manifest";
|
|
8
|
-
import { MODERN_JS_SERVER_DIR } from "../constant";
|
|
8
|
+
import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
|
|
9
9
|
const SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
|
|
10
10
|
const isDev = process.env.NODE_ENV === "development";
|
|
11
11
|
const moduleFederationPlugin = (userConfig = {}) => ({
|
|
@@ -58,7 +58,7 @@ const moduleFederationPlugin = (userConfig = {}) => ({
|
|
|
58
58
|
tools: {
|
|
59
59
|
rspack(config) {
|
|
60
60
|
if (enableSSR) {
|
|
61
|
-
throw new Error(
|
|
61
|
+
throw new Error(`${PLUGIN_IDENTIFIER} not support ssr for rspack bundler yet!`);
|
|
62
62
|
}
|
|
63
63
|
modifyBundlerConfig(config, false);
|
|
64
64
|
},
|
|
@@ -2,8 +2,9 @@ import { encodeName } from "@module-federation/sdk";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import os from "os";
|
|
4
4
|
import { bundle } from "@modern-js/node-bundle-require";
|
|
5
|
-
import { LOCALHOST } from "../constant";
|
|
5
|
+
import { LOCALHOST, PLUGIN_IDENTIFIER } from "../constant";
|
|
6
6
|
const defaultPath = path.resolve(process.cwd(), "module-federation.config.ts");
|
|
7
|
+
const isDev = process.env.NODE_ENV === "development";
|
|
7
8
|
const getMFConfig = async (userConfig) => {
|
|
8
9
|
const { config, configPath } = userConfig;
|
|
9
10
|
if (config) {
|
|
@@ -16,6 +17,9 @@ const getMFConfig = async (userConfig) => {
|
|
|
16
17
|
if (mfConfig.remoteType === void 0) {
|
|
17
18
|
mfConfig.remoteType = "script";
|
|
18
19
|
}
|
|
20
|
+
if (!mfConfig.name) {
|
|
21
|
+
throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
|
|
22
|
+
}
|
|
19
23
|
return mfConfig;
|
|
20
24
|
};
|
|
21
25
|
const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
|
|
@@ -53,11 +57,10 @@ const replaceRemoteUrl = async (mfConfig) => {
|
|
|
53
57
|
handleRemoteObject(mfConfig.remotes);
|
|
54
58
|
}
|
|
55
59
|
};
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
];
|
|
60
|
+
const patchDTSConfig = (mfConfig, isServer) => {
|
|
61
|
+
if (isServer) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
61
64
|
const ModernJSRuntime = "@modern-js/runtime/mf";
|
|
62
65
|
if (mfConfig.dts !== false) {
|
|
63
66
|
var _mfConfig_dts, _mfConfig_dts1;
|
|
@@ -85,6 +88,12 @@ const patchMFConfig = (mfConfig, isServer) => {
|
|
|
85
88
|
}
|
|
86
89
|
}
|
|
87
90
|
}
|
|
91
|
+
};
|
|
92
|
+
const patchMFConfig = (mfConfig, isServer) => {
|
|
93
|
+
const runtimePlugins = [
|
|
94
|
+
...mfConfig.runtimePlugins || []
|
|
95
|
+
];
|
|
96
|
+
patchDTSConfig(mfConfig, isServer);
|
|
88
97
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
|
|
89
98
|
if (isDev) {
|
|
90
99
|
injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/resolve-entry-ipv4.js"), runtimePlugins);
|
|
@@ -132,18 +141,27 @@ function getTargetEnvConfig(mfConfig, isServer) {
|
|
|
132
141
|
return patchedMFConfig;
|
|
133
142
|
}
|
|
134
143
|
function patchWebpackConfig(options) {
|
|
135
|
-
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
|
|
144
|
+
var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
|
|
136
145
|
const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
|
|
137
146
|
const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
|
|
138
147
|
(_bundlerConfig_optimization = bundlerConfig.optimization) === null || _bundlerConfig_optimization === void 0 ? true : delete _bundlerConfig_optimization.runtimeChunk;
|
|
148
|
+
if (bundlerConfig.output) {
|
|
149
|
+
var _bundlerConfig_output1, _bundlerConfig_output2;
|
|
150
|
+
if (!((_bundlerConfig_output1 = bundlerConfig.output) === null || _bundlerConfig_output1 === void 0 ? void 0 : _bundlerConfig_output1.chunkLoadingGlobal)) {
|
|
151
|
+
bundlerConfig.output.chunkLoadingGlobal = `chunk_${mfConfig.name}`;
|
|
152
|
+
}
|
|
153
|
+
if (!((_bundlerConfig_output2 = bundlerConfig.output) === null || _bundlerConfig_output2 === void 0 ? void 0 : _bundlerConfig_output2.uniqueName)) {
|
|
154
|
+
bundlerConfig.output.uniqueName = mfConfig.name;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
139
157
|
if (!isServer) {
|
|
140
158
|
autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
|
|
141
159
|
}
|
|
142
160
|
if (!isServer && enableSSR && typeof ((_bundlerConfig_optimization1 = bundlerConfig.optimization) === null || _bundlerConfig_optimization1 === void 0 ? void 0 : _bundlerConfig_optimization1.splitChunks) === "object" && bundlerConfig.optimization.splitChunks.cacheGroups) {
|
|
143
161
|
bundlerConfig.optimization.splitChunks.chunks = "async";
|
|
144
|
-
console.warn(
|
|
162
|
+
console.warn(`${PLUGIN_IDENTIFIER} splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
|
|
145
163
|
}
|
|
146
|
-
if (((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
164
|
+
if (isDev && ((_bundlerConfig_output = bundlerConfig.output) === null || _bundlerConfig_output === void 0 ? void 0 : _bundlerConfig_output.publicPath) === "auto") {
|
|
147
165
|
var _modernjsConfig_dev, _modernjsConfig_server1;
|
|
148
166
|
const port = ((_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.port) || ((_modernjsConfig_server1 = modernjsConfig.server) === null || _modernjsConfig_server1 === void 0 ? void 0 : _modernjsConfig_server1.port) || 8080;
|
|
149
167
|
const publicPath = `http://localhost:${port}/`;
|
|
@@ -158,7 +176,6 @@ function patchWebpackConfig(options) {
|
|
|
158
176
|
output.chunkFilename = chunkFileName.replace(".js", suffix);
|
|
159
177
|
}
|
|
160
178
|
}
|
|
161
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
162
179
|
if (isDev && enableSSR && !isServer) {
|
|
163
180
|
bundlerConfig.resolve.fallback = {
|
|
164
181
|
...bundlerConfig.resolve.fallback,
|
|
@@ -167,6 +184,12 @@ function patchWebpackConfig(options) {
|
|
|
167
184
|
vm: false
|
|
168
185
|
};
|
|
169
186
|
}
|
|
187
|
+
if (((_modernjsConfig_deploy = modernjsConfig.deploy) === null || _modernjsConfig_deploy === void 0 ? void 0 : _modernjsConfig_deploy.microFrontend) && Object.keys(mfConfig.exposes || {}).length) {
|
|
188
|
+
if (!bundlerConfig.optimization) {
|
|
189
|
+
bundlerConfig.optimization = {};
|
|
190
|
+
}
|
|
191
|
+
bundlerConfig.optimization.usedExports = false;
|
|
192
|
+
}
|
|
170
193
|
}
|
|
171
194
|
const localIpv4 = "127.0.0.1";
|
|
172
195
|
const getIpv4Interfaces = () => {
|
|
@@ -101,7 +101,9 @@ describe("patchWebpackConfig", async () => {
|
|
|
101
101
|
});
|
|
102
102
|
expect(bundlerConfig).toStrictEqual({
|
|
103
103
|
output: {
|
|
104
|
-
|
|
104
|
+
chunkLoadingGlobal: "chunk_host",
|
|
105
|
+
publicPath: "auto",
|
|
106
|
+
uniqueName: "host"
|
|
105
107
|
}
|
|
106
108
|
});
|
|
107
109
|
});
|
|
@@ -125,7 +127,9 @@ describe("patchWebpackConfig", async () => {
|
|
|
125
127
|
});
|
|
126
128
|
expect(bundlerConfig).toStrictEqual({
|
|
127
129
|
output: {
|
|
128
|
-
|
|
130
|
+
chunkLoadingGlobal: "chunk_host",
|
|
131
|
+
publicPath: "auto",
|
|
132
|
+
uniqueName: "host"
|
|
129
133
|
}
|
|
130
134
|
});
|
|
131
135
|
});
|
package/dist/types/constant.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20240626050252",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -43,21 +43,21 @@
|
|
|
43
43
|
"license": "MIT",
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@swc/helpers": "0.5.3",
|
|
46
|
-
"@modern-js/utils": "^2.
|
|
47
|
-
"@modern-js/node-bundle-require": "^2.
|
|
46
|
+
"@modern-js/utils": "^2.54.2",
|
|
47
|
+
"@modern-js/node-bundle-require": "^2.54.2",
|
|
48
48
|
"node-fetch": "~3.3.0",
|
|
49
49
|
"react-error-boundary": "4.0.13",
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
51
|
-
"@module-federation/enhanced": "0.0.0-next-
|
|
52
|
-
"@module-federation/node": "0.0.0-next-
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20240626050252",
|
|
51
|
+
"@module-federation/enhanced": "0.0.0-next-20240626050252",
|
|
52
|
+
"@module-federation/node": "0.0.0-next-20240626050252"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@modern-js/app-tools": "^2.
|
|
56
|
-
"@modern-js/core": "^2.
|
|
57
|
-
"@modern-js/runtime": "^2.
|
|
58
|
-
"@modern-js/module-tools": "^2.
|
|
59
|
-
"@modern-js/tsconfig": "^2.
|
|
60
|
-
"@module-federation/manifest": "0.0.0-next-
|
|
55
|
+
"@modern-js/app-tools": "^2.54.2",
|
|
56
|
+
"@modern-js/core": "^2.54.2",
|
|
57
|
+
"@modern-js/runtime": "^2.54.2",
|
|
58
|
+
"@modern-js/module-tools": "^2.54.2",
|
|
59
|
+
"@modern-js/tsconfig": "^2.54.2",
|
|
60
|
+
"@module-federation/manifest": "0.0.0-next-20240626050252"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=17",
|