@module-federation/modern-js 0.0.0-next-20240625070454 → 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.
@@ -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) => {
@@ -123,7 +127,6 @@ const patchDTSConfig = (mfConfig, isServer) => {
123
127
  }
124
128
  };
125
129
  const patchMFConfig = (mfConfig, isServer) => {
126
- const isDev = process.env.NODE_ENV === "development";
127
130
  const runtimePlugins = [
128
131
  ...mfConfig.runtimePlugins || []
129
132
  ];
@@ -175,10 +178,19 @@ function getTargetEnvConfig(mfConfig, isServer) {
175
178
  return patchedMFConfig;
176
179
  }
177
180
  function patchWebpackConfig(options) {
178
- var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
181
+ var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
179
182
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
180
183
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
181
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
+ }
182
194
  if (!isServer) {
183
195
  autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
184
196
  }
@@ -186,7 +198,7 @@ function patchWebpackConfig(options) {
186
198
  bundlerConfig.optimization.splitChunks.chunks = "async";
187
199
  console.warn(`${import_constant.PLUGIN_IDENTIFIER} splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
188
200
  }
189
- 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") {
190
202
  var _modernjsConfig_dev, _modernjsConfig_server1;
191
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;
192
204
  const publicPath = `http://localhost:${port}/`;
@@ -201,7 +213,6 @@ function patchWebpackConfig(options) {
201
213
  output.chunkFilename = chunkFileName.replace(".js", suffix);
202
214
  }
203
215
  }
204
- const isDev = process.env.NODE_ENV === "development";
205
216
  if (isDev && enableSSR && !isServer) {
206
217
  bundlerConfig.resolve.fallback = {
207
218
  ...bundlerConfig.resolve.fallback,
@@ -210,6 +221,12 @@ function patchWebpackConfig(options) {
210
221
  vm: false
211
222
  };
212
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
+ }
213
230
  }
214
231
  const localIpv4 = "127.0.0.1";
215
232
  const getIpv4Interfaces = () => {
@@ -124,7 +124,9 @@ const mfConfig = {
124
124
  });
125
125
  (0, import_vitest.expect)(bundlerConfig).toStrictEqual({
126
126
  output: {
127
- publicPath: "http://localhost:8080/"
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
- publicPath: "http://localhost:8080/"
153
+ chunkLoadingGlobal: "chunk_host",
154
+ publicPath: "auto",
155
+ uniqueName: "host"
152
156
  }
153
157
  });
154
158
  });
@@ -9,6 +9,7 @@ import os from "os";
9
9
  import { bundle } from "@modern-js/node-bundle-require";
10
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
@@ -136,7 +140,6 @@ var patchDTSConfig = function(mfConfig, isServer) {
136
140
  }
137
141
  };
138
142
  var patchMFConfig = function(mfConfig, isServer) {
139
- var isDev = process.env.NODE_ENV === "development";
140
143
  var runtimePlugins = _to_consumable_array(mfConfig.runtimePlugins || []);
141
144
  patchDTSConfig(mfConfig, isServer);
142
145
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"), runtimePlugins);
@@ -181,10 +184,19 @@ function getTargetEnvConfig(mfConfig, isServer) {
181
184
  return patchedMFConfig;
182
185
  }
183
186
  function patchWebpackConfig(options) {
184
- var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
187
+ var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
185
188
  var bundlerConfig = options.bundlerConfig, modernjsConfig = options.modernjsConfig, isServer = options.isServer, mfConfig = options.mfConfig;
186
189
  var enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
187
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
+ }
188
200
  if (!isServer) {
189
201
  autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
190
202
  }
@@ -192,7 +204,7 @@ function patchWebpackConfig(options) {
192
204
  bundlerConfig.optimization.splitChunks.chunks = "async";
193
205
  console.warn("".concat(PLUGIN_IDENTIFIER, ' splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"'));
194
206
  }
195
- 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") {
196
208
  var _modernjsConfig_dev, _modernjsConfig_server1;
197
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;
198
210
  var publicPath = "http://localhost:".concat(port, "/");
@@ -207,7 +219,6 @@ function patchWebpackConfig(options) {
207
219
  output.chunkFilename = chunkFileName.replace(".js", suffix);
208
220
  }
209
221
  }
210
- var isDev = process.env.NODE_ENV === "development";
211
222
  if (isDev && enableSSR && !isServer) {
212
223
  bundlerConfig.resolve.fallback = _object_spread_props(_object_spread({}, bundlerConfig.resolve.fallback), {
213
224
  crypto: false,
@@ -215,6 +226,12 @@ function patchWebpackConfig(options) {
215
226
  vm: false
216
227
  });
217
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
+ }
218
235
  }
219
236
  var localIpv4 = "127.0.0.1";
220
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
- publicPath: "http://localhost:8080/"
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
- publicPath: "http://localhost:8080/"
158
+ chunkLoadingGlobal: "chunk_host",
159
+ publicPath: "auto",
160
+ uniqueName: "host"
157
161
  }
158
162
  });
159
163
  return [
@@ -4,6 +4,7 @@ import os from "os";
4
4
  import { bundle } from "@modern-js/node-bundle-require";
5
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) => {
@@ -86,7 +90,6 @@ const patchDTSConfig = (mfConfig, isServer) => {
86
90
  }
87
91
  };
88
92
  const patchMFConfig = (mfConfig, isServer) => {
89
- const isDev = process.env.NODE_ENV === "development";
90
93
  const runtimePlugins = [
91
94
  ...mfConfig.runtimePlugins || []
92
95
  ];
@@ -138,10 +141,19 @@ function getTargetEnvConfig(mfConfig, isServer) {
138
141
  return patchedMFConfig;
139
142
  }
140
143
  function patchWebpackConfig(options) {
141
- var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output;
144
+ var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
142
145
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
143
146
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
144
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
+ }
145
157
  if (!isServer) {
146
158
  autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig);
147
159
  }
@@ -149,7 +161,7 @@ function patchWebpackConfig(options) {
149
161
  bundlerConfig.optimization.splitChunks.chunks = "async";
150
162
  console.warn(`${PLUGIN_IDENTIFIER} splitChunks.chunks = async is not allowed with stream SSR mode, it will auto changed to "async"`);
151
163
  }
152
- 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") {
153
165
  var _modernjsConfig_dev, _modernjsConfig_server1;
154
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;
155
167
  const publicPath = `http://localhost:${port}/`;
@@ -164,7 +176,6 @@ function patchWebpackConfig(options) {
164
176
  output.chunkFilename = chunkFileName.replace(".js", suffix);
165
177
  }
166
178
  }
167
- const isDev = process.env.NODE_ENV === "development";
168
179
  if (isDev && enableSSR && !isServer) {
169
180
  bundlerConfig.resolve.fallback = {
170
181
  ...bundlerConfig.resolve.fallback,
@@ -173,6 +184,12 @@ function patchWebpackConfig(options) {
173
184
  vm: false
174
185
  };
175
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
+ }
176
193
  }
177
194
  const localIpv4 = "127.0.0.1";
178
195
  const getIpv4Interfaces = () => {
@@ -101,7 +101,9 @@ describe("patchWebpackConfig", async () => {
101
101
  });
102
102
  expect(bundlerConfig).toStrictEqual({
103
103
  output: {
104
- publicPath: "http://localhost:8080/"
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
- publicPath: "http://localhost:8080/"
130
+ chunkLoadingGlobal: "chunk_host",
131
+ publicPath: "auto",
132
+ uniqueName: "host"
129
133
  }
130
134
  });
131
135
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240625070454",
3
+ "version": "0.0.0-next-20240626050252",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -47,9 +47,9 @@
47
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-20240625070454",
51
- "@module-federation/enhanced": "0.0.0-next-20240625070454",
52
- "@module-federation/node": "0.0.0-next-20240625070454"
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
55
  "@modern-js/app-tools": "^2.54.2",
@@ -57,7 +57,7 @@
57
57
  "@modern-js/runtime": "^2.54.2",
58
58
  "@modern-js/module-tools": "^2.54.2",
59
59
  "@modern-js/tsconfig": "^2.54.2",
60
- "@module-federation/manifest": "0.0.0-next-20240625070454"
60
+ "@module-federation/manifest": "0.0.0-next-20240626050252"
61
61
  },
62
62
  "peerDependencies": {
63
63
  "react": ">=17",