@module-federation/modern-js 0.0.0-next-20240712032032 → 0.0.0-next-20240715065227

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.
@@ -1,191 +1,62 @@
1
- import path from "path";
2
- import { fs } from "@modern-js/utils";
3
1
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
4
2
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
5
- import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
6
- import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
7
- import { updateStatsAndManifest } from "./manifest";
8
- import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
9
- const SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
10
- const isDev = process.env.NODE_ENV === "development";
11
- const moduleFederationPlugin = (userConfig = {}) => ({
12
- name: "@modern-js/plugin-module-federation",
13
- setup: async ({ useConfigContext, useAppContext }) => {
14
- var _modernjsConfig_server;
15
- const modernjsConfig = useConfigContext();
16
- const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
17
- const mfConfig = await getMFConfig(userConfig);
18
- let outputDir = "";
19
- let browserPlugin;
20
- let nodePlugin;
21
- return {
22
- config: async () => {
23
- var _modernjsConfig_dev;
24
- const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
25
- const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
26
- const RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
27
- const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
28
- if (enableSSR) {
29
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
30
- process.env["MF_SSR_PRJ"] = "true";
31
- }
32
- const modifyBundlerConfig = (config, isServer) => {
33
- const envConfig = getTargetEnvConfig(mfConfig, isServer);
34
- if (isServer) {
35
- var _config_plugins, _config_plugins1;
36
- nodePlugin = new MFBundlerPlugin(envConfig);
37
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
38
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
39
- if (isDev) {
40
- var _config_plugins2;
41
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
42
- }
43
- } else {
44
- var _config_output, _config_plugins3;
45
- outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
46
- browserPlugin = new MFBundlerPlugin(envConfig);
47
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
48
- }
49
- patchWebpackConfig({
50
- bundlerConfig: config,
51
- isServer,
52
- modernjsConfig,
53
- mfConfig: envConfig
54
- });
55
- };
56
- const ipv4 = getIPV4();
57
- return {
58
- tools: {
59
- rspack(config) {
60
- if (enableSSR) {
61
- throw new Error(`${PLUGIN_IDENTIFIER} not support ssr for rspack bundler yet!`);
62
- }
63
- modifyBundlerConfig(config, false);
64
- },
65
- webpack(config, { isServer }) {
66
- var _modernjsConfig_source;
67
- modifyBundlerConfig(config, isServer);
68
- const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
69
- if (!enableAsyncEntry && mfConfig.async !== false) {
70
- var _config_plugins;
71
- const asyncBoundaryPluginOptions = typeof mfConfig.async === "object" ? mfConfig.async : {
72
- eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
73
- excludeChunk: (chunk) => chunk.name === mfConfig.name
74
- };
75
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
76
- }
77
- config.ignoreWarnings = config.ignoreWarnings || [];
78
- config.ignoreWarnings.push((warning) => {
79
- if (warning.message.includes("external script")) {
80
- return true;
3
+ import { moduleFederationConfigPlugin } from "./configPlugin";
4
+ import { moduleFederationSSRPlugin } from "./ssrPlugin";
5
+ const moduleFederationPlugin = (userConfig = {}) => {
6
+ const internalModernPluginOptions = {
7
+ csrConfig: void 0,
8
+ ssrConfig: void 0,
9
+ browserPlugin: void 0,
10
+ nodePlugin: void 0,
11
+ distOutputDir: "",
12
+ originPluginOptions: userConfig
13
+ };
14
+ return {
15
+ name: "@modern-js/plugin-module-federation",
16
+ setup: async ({ useConfigContext }) => {
17
+ console.log("main plugin");
18
+ const modernjsConfig = useConfigContext();
19
+ return {
20
+ config: async () => {
21
+ return {
22
+ tools: {
23
+ rspack(config, { isServer }) {
24
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
25
+ if (!isServer) {
26
+ var _config_plugins;
27
+ internalModernPluginOptions.browserPlugin = new RspackModuleFederationPlugin(browserPluginOptions);
28
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
81
29
  }
82
- return false;
83
- });
84
- },
85
- devServer: {
86
- headers: {
87
- "Access-Control-Allow-Origin": "*",
88
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
89
- "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
90
30
  },
91
- before: [
92
- (req, res, next) => {
93
- if (!enableSSR) {
94
- next();
95
- return;
96
- }
97
- try {
98
- var _req_url, _req_url1, _req_url2;
99
- const SERVER_PREFIX = `/${MODERN_JS_SERVER_DIR}`;
100
- if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
101
- const filepath = path.join(process.cwd(), `dist${req.url}`);
102
- fs.statSync(filepath);
103
- res.setHeader("Access-Control-Allow-Origin", "*");
104
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
105
- res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
106
- fs.createReadStream(filepath).pipe(res);
107
- } else {
108
- next();
109
- }
110
- } catch (err) {
111
- if (process.env.FEDERATION_DEBUG) {
112
- console.error(err);
113
- }
114
- next();
115
- }
31
+ webpack(config, { isServer }) {
32
+ var _modernjsConfig_source;
33
+ const browserPluginOptions = internalModernPluginOptions.csrConfig;
34
+ if (!isServer) {
35
+ var _config_plugins;
36
+ internalModernPluginOptions.browserPlugin = new WebpackModuleFederationPlugin(browserPluginOptions);
37
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
38
+ }
39
+ const enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
40
+ if (!enableAsyncEntry && browserPluginOptions.async !== false) {
41
+ var _config_plugins1;
42
+ const asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
43
+ eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
44
+ excludeChunk: (chunk) => chunk.name === browserPluginOptions.name
45
+ };
46
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
116
47
  }
117
- ]
118
- },
119
- bundlerChain(chain, { isServer }) {
120
- if (isDev && !isServer) {
121
- chain.externals({
122
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
123
- });
124
48
  }
125
49
  }
126
- },
127
- source: {
128
- alias: {
129
- "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
130
- },
131
- define: {
132
- FEDERATION_IPV4: JSON.stringify(ipv4)
133
- }
134
- },
135
- dev: {
136
- assetPrefix: (modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_dev = modernjsConfig.dev) === null || _modernjsConfig_dev === void 0 ? void 0 : _modernjsConfig_dev.assetPrefix) ? modernjsConfig.dev.assetPrefix : true
137
- }
138
- };
139
- },
140
- modifyEntryImports({ entrypoint, imports }) {
141
- if (!enableSSR || !isDev) {
142
- return {
143
- entrypoint,
144
- imports
145
50
  };
146
51
  }
147
- imports.push({
148
- value: "@module-federation/modern-js/ssr-runtime",
149
- specifiers: [
150
- {
151
- imported: SSR_PLUGIN_IDENTIFIER
152
- }
153
- ]
154
- });
155
- return {
156
- entrypoint,
157
- imports
158
- };
159
- },
160
- modifyEntryRuntimePlugins({ entrypoint, plugins }) {
161
- if (!enableSSR || !isDev) {
162
- return {
163
- entrypoint,
164
- plugins
165
- };
166
- }
167
- plugins.unshift({
168
- name: SSR_PLUGIN_IDENTIFIER,
169
- options: JSON.stringify({})
170
- });
171
- return {
172
- entrypoint,
173
- plugins
174
- };
175
- },
176
- afterBuild: () => {
177
- if (enableSSR) {
178
- updateStatsAndManifest(nodePlugin, browserPlugin, outputDir);
179
- }
180
- },
181
- afterDev: () => {
182
- if (enableSSR) {
183
- updateStatsAndManifest(nodePlugin, browserPlugin, outputDir);
184
- }
185
- }
186
- };
187
- }
188
- });
52
+ };
53
+ },
54
+ usePlugins: [
55
+ moduleFederationConfigPlugin(internalModernPluginOptions),
56
+ moduleFederationSSRPlugin(internalModernPluginOptions)
57
+ ]
58
+ };
59
+ };
189
60
  var cli_default = moduleFederationPlugin;
190
61
  import { createModuleFederationConfig } from "@module-federation/enhanced";
191
62
  export {
@@ -0,0 +1,125 @@
1
+ import path from "path";
2
+ import { fs } from "@modern-js/utils";
3
+ import { ModuleFederationPlugin } from "@module-federation/enhanced";
4
+ import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
5
+ import { updateStatsAndManifest } from "./manifest";
6
+ import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
7
+ import { isDev } from "./constant";
8
+ function setEnv() {
9
+ process.env["MF_DISABLE_EMIT_STATS"] = "true";
10
+ process.env["MF_SSR_PRJ"] = "true";
11
+ }
12
+ const moduleFederationSSRPlugin = (userConfig) => ({
13
+ name: "@modern-js/plugin-module-federation-ssr",
14
+ pre: [
15
+ "@modern-js/plugin-module-federation-config",
16
+ "@modern-js/plugin-module-federation"
17
+ ],
18
+ setup: async ({ useConfigContext }) => {
19
+ var _modernjsConfig_server;
20
+ console.log("ssr plugin");
21
+ const modernjsConfig = useConfigContext();
22
+ const enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
23
+ if (!enableSSR) {
24
+ return {};
25
+ }
26
+ setEnv();
27
+ return {
28
+ _internalRuntimePlugins: ({ entrypoint, plugins }) => {
29
+ if (!isDev) {
30
+ return {
31
+ entrypoint,
32
+ plugins
33
+ };
34
+ }
35
+ plugins.push({
36
+ name: "mfSSR",
37
+ path: "@module-federation/modern-js/ssr-runtime",
38
+ config: {}
39
+ });
40
+ return {
41
+ entrypoint,
42
+ plugins
43
+ };
44
+ },
45
+ config: async () => {
46
+ return {
47
+ tools: {
48
+ rspack(config, { isServer }) {
49
+ if (isServer) {
50
+ throw new Error(`${PLUGIN_IDENTIFIER} Not support rspack ssr mode yet !`);
51
+ }
52
+ },
53
+ webpack(config, { isServer }) {
54
+ if (isServer) {
55
+ var _config_plugins, _config_plugins1;
56
+ if (!userConfig.nodePlugin) {
57
+ userConfig.nodePlugin = new ModuleFederationPlugin(userConfig.ssrConfig);
58
+ }
59
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(userConfig.nodePlugin);
60
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(userConfig.nodePlugin));
61
+ if (isDev) {
62
+ var _config_plugins2;
63
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
64
+ }
65
+ } else {
66
+ var _config_output;
67
+ userConfig.distOutputDir = userConfig.distOutputDir || ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
68
+ }
69
+ },
70
+ devServer: {
71
+ before: [
72
+ (req, res, next) => {
73
+ if (!enableSSR) {
74
+ next();
75
+ return;
76
+ }
77
+ try {
78
+ var _req_url, _req_url1, _req_url2;
79
+ const SERVER_PREFIX = `/${MODERN_JS_SERVER_DIR}`;
80
+ if (((_req_url = req.url) === null || _req_url === void 0 ? void 0 : _req_url.startsWith(SERVER_PREFIX)) || ((_req_url1 = req.url) === null || _req_url1 === void 0 ? void 0 : _req_url1.includes(".json")) && !((_req_url2 = req.url) === null || _req_url2 === void 0 ? void 0 : _req_url2.includes("hot-update"))) {
81
+ const filepath = path.join(process.cwd(), `dist${req.url}`);
82
+ fs.statSync(filepath);
83
+ res.setHeader("Access-Control-Allow-Origin", "*");
84
+ res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
85
+ res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
86
+ fs.createReadStream(filepath).pipe(res);
87
+ } else {
88
+ next();
89
+ }
90
+ } catch (err) {
91
+ if (process.env.FEDERATION_DEBUG) {
92
+ console.error(err);
93
+ }
94
+ next();
95
+ }
96
+ }
97
+ ]
98
+ },
99
+ bundlerChain(chain, { isServer }) {
100
+ if (isDev && !isServer) {
101
+ chain.externals({
102
+ "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
103
+ });
104
+ }
105
+ }
106
+ }
107
+ };
108
+ },
109
+ afterBuild: () => {
110
+ const { nodePlugin, browserPlugin, distOutputDir } = userConfig;
111
+ updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
112
+ },
113
+ afterDev: () => {
114
+ const { nodePlugin, browserPlugin, distOutputDir } = userConfig;
115
+ updateStatsAndManifest(nodePlugin, browserPlugin, distOutputDir);
116
+ }
117
+ };
118
+ }
119
+ });
120
+ var ssrPlugin_default = moduleFederationSSRPlugin;
121
+ export {
122
+ ssrPlugin_default as default,
123
+ moduleFederationSSRPlugin,
124
+ setEnv
125
+ };
@@ -13,13 +13,6 @@ const getMFConfig = async (userConfig) => {
13
13
  const mfConfigPath = configPath ? configPath : defaultPath;
14
14
  const preBundlePath = await bundle(mfConfigPath);
15
15
  const mfConfig = (await import(preBundlePath)).default;
16
- await replaceRemoteUrl(mfConfig);
17
- if (mfConfig.remoteType === void 0) {
18
- mfConfig.remoteType = "script";
19
- }
20
- if (!mfConfig.name) {
21
- throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
22
- }
23
16
  return mfConfig;
24
17
  };
25
18
  const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
@@ -27,7 +20,7 @@ const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
27
20
  runtimePlugins.push(runtimePlugin);
28
21
  }
29
22
  };
30
- const replaceRemoteUrl = async (mfConfig) => {
23
+ const replaceRemoteUrl = (mfConfig) => {
31
24
  if (!mfConfig.remotes) {
32
25
  return;
33
26
  }
@@ -90,6 +83,13 @@ const patchDTSConfig = (mfConfig, isServer) => {
90
83
  }
91
84
  };
92
85
  const patchMFConfig = (mfConfig, isServer) => {
86
+ replaceRemoteUrl(mfConfig);
87
+ if (mfConfig.remoteType === void 0) {
88
+ mfConfig.remoteType = "script";
89
+ }
90
+ if (!mfConfig.name) {
91
+ throw new Error(`${PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
92
+ }
93
93
  const runtimePlugins = [
94
94
  ...mfConfig.runtimePlugins || []
95
95
  ];
@@ -103,44 +103,33 @@ const patchMFConfig = (mfConfig, isServer) => {
103
103
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
104
104
  }
105
105
  injectRuntimePlugins(path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
106
- }
107
- if (!isServer) {
108
- return {
109
- ...mfConfig,
110
- runtimePlugins
111
- };
112
- }
113
- return {
114
- ...mfConfig,
115
- runtimePlugins,
116
- dts: false,
117
- dev: false
118
- };
119
- };
120
- function getTargetEnvConfig(mfConfig, isServer) {
121
- var _patchedMFConfig_library;
122
- const patchedMFConfig = patchMFConfig(mfConfig, isServer);
123
- if (isServer) {
124
- return {
125
- library: {
106
+ if (!mfConfig.library) {
107
+ mfConfig.library = {
126
108
  type: "commonjs-module",
127
109
  name: mfConfig.name
128
- },
129
- ...patchedMFConfig
130
- };
131
- }
132
- if (((_patchedMFConfig_library = patchedMFConfig.library) === null || _patchedMFConfig_library === void 0 ? void 0 : _patchedMFConfig_library.type) === "commonjs-module") {
133
- return {
134
- ...patchedMFConfig,
135
- library: {
136
- ...mfConfig.library,
137
- type: "global"
110
+ };
111
+ } else {
112
+ if (!mfConfig.library.type) {
113
+ mfConfig.library.type = "commonjs-module";
138
114
  }
139
- };
115
+ if (!mfConfig.library.name) {
116
+ mfConfig.library.name = mfConfig.name;
117
+ }
118
+ }
140
119
  }
141
- return patchedMFConfig;
142
- }
143
- function patchWebpackConfig(options) {
120
+ mfConfig.runtimePlugins = runtimePlugins;
121
+ if (!isServer) {
122
+ var _mfConfig_library;
123
+ if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
124
+ mfConfig.library.type = "global";
125
+ }
126
+ return mfConfig;
127
+ }
128
+ mfConfig.dts = false;
129
+ mfConfig.dev = false;
130
+ return mfConfig;
131
+ };
132
+ function patchBundlerConfig(options) {
144
133
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
145
134
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
146
135
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -260,7 +249,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
260
249
  export {
261
250
  getIPV4,
262
251
  getMFConfig,
263
- getTargetEnvConfig,
264
- patchMFConfig,
265
- patchWebpackConfig
252
+ patchBundlerConfig,
253
+ patchMFConfig
266
254
  };
@@ -1,6 +1,6 @@
1
1
  import { it, expect, describe } from "vitest";
2
2
  import path from "path";
3
- import { getTargetEnvConfig, patchWebpackConfig } from "./utils";
3
+ import { patchMFConfig, patchBundlerConfig, getIPV4 } from "./utils";
4
4
  const mfConfig = {
5
5
  name: "host",
6
6
  filename: "remoteEntry.js",
@@ -18,10 +18,12 @@ const mfConfig = {
18
18
  }
19
19
  }
20
20
  };
21
- describe("getTargetEnvConfig", async () => {
22
- it("getTargetEnvConfig: server", async () => {
23
- const targetEnvConfig = getTargetEnvConfig(mfConfig, true);
24
- expect(targetEnvConfig).toStrictEqual({
21
+ describe("patchMFConfig", async () => {
22
+ it("patchMFConfig: server", async () => {
23
+ const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
24
+ patchMFConfig(patchedConfig, true);
25
+ const ipv4 = getIPV4();
26
+ expect(patchedConfig).toStrictEqual({
25
27
  dev: false,
26
28
  dts: false,
27
29
  filename: "remoteEntry.js",
@@ -31,8 +33,9 @@ describe("getTargetEnvConfig", async () => {
31
33
  },
32
34
  name: "host",
33
35
  remotes: {
34
- remote: "http://localhost:3000/remoteEntry.js"
36
+ remote: `http://${ipv4}:3000/remoteEntry.js`
35
37
  },
38
+ remoteType: "script",
36
39
  runtimePlugins: [
37
40
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
38
41
  path.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
@@ -49,14 +52,17 @@ describe("getTargetEnvConfig", async () => {
49
52
  }
50
53
  });
51
54
  });
52
- it("getTargetEnvConfig: client", async () => {
53
- const targetEnvConfig = getTargetEnvConfig(mfConfig, false);
54
- expect(targetEnvConfig).toStrictEqual({
55
+ it("patchMFConfig: client", async () => {
56
+ const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
57
+ patchMFConfig(patchedConfig, false);
58
+ const ipv4 = getIPV4();
59
+ expect(patchedConfig).toStrictEqual({
55
60
  filename: "remoteEntry.js",
56
61
  name: "host",
57
62
  remotes: {
58
- remote: "http://localhost:3000/remoteEntry.js"
63
+ remote: `http://${ipv4}:3000/remoteEntry.js`
59
64
  },
65
+ remoteType: "script",
60
66
  runtimePlugins: [
61
67
  path.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
62
68
  ],
@@ -80,14 +86,14 @@ describe("getTargetEnvConfig", async () => {
80
86
  });
81
87
  });
82
88
  });
83
- describe("patchWebpackConfig", async () => {
84
- it("patchWebpackConfig: server", async () => {
89
+ describe("patchBundlerConfig", async () => {
90
+ it("patchBundlerConfig: server", async () => {
85
91
  const bundlerConfig = {
86
92
  output: {
87
93
  publicPath: "auto"
88
94
  }
89
95
  };
90
- patchWebpackConfig({
96
+ patchBundlerConfig({
91
97
  bundlerConfig,
92
98
  isServer: true,
93
99
  modernjsConfig: {
@@ -107,13 +113,13 @@ describe("patchWebpackConfig", async () => {
107
113
  }
108
114
  });
109
115
  });
110
- it("patchWebpackConfig: client", async () => {
116
+ it("patchBundlerConfig: client", async () => {
111
117
  const bundlerConfig = {
112
118
  output: {
113
119
  publicPath: "auto"
114
120
  }
115
121
  };
116
- patchWebpackConfig({
122
+ patchBundlerConfig({
117
123
  bundlerConfig,
118
124
  isServer: false,
119
125
  modernjsConfig: {
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import hoistNonReactStatics from "hoist-non-react-statics";
3
3
  import { SSRLiveReload } from "./SSRLiveReload";
4
- const mfPluginSSR = () => ({
4
+ const mfSSRPlugin = () => ({
5
5
  name: "@module-federation/modern-js",
6
6
  setup: () => {
7
7
  return {
@@ -41,5 +41,5 @@ const mfPluginSSR = () => ({
41
41
  }
42
42
  });
43
43
  export {
44
- mfPluginSSR
44
+ mfSSRPlugin
45
45
  };
@@ -0,0 +1,14 @@
1
+ import type { CliPlugin, AppTools, UserConfig, Bundler } from '@modern-js/app-tools';
2
+ import type { BundlerConfig } from '../interfaces/bundler';
3
+ import type { InternalModernPluginOptions } from '../types';
4
+ import { moduleFederationPlugin } from '@module-federation/sdk';
5
+ export declare function setEnv(enableSSR: boolean): void;
6
+ export declare function modifyBundlerConfig<T extends Bundler>(options: {
7
+ bundlerType: Bundler;
8
+ mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions;
9
+ config: BundlerConfig<T>;
10
+ isServer: boolean;
11
+ modernjsConfig: UserConfig<AppTools>;
12
+ }): void;
13
+ export declare const moduleFederationConfigPlugin: (userConfig: InternalModernPluginOptions) => CliPlugin<AppTools>;
14
+ export default moduleFederationConfigPlugin;
@@ -0,0 +1 @@
1
+ export declare const isDev: boolean;
@@ -0,0 +1,5 @@
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ import type { InternalModernPluginOptions } from '../types';
3
+ export declare function setEnv(): void;
4
+ export declare const moduleFederationSSRPlugin: (userConfig: Required<InternalModernPluginOptions>) => CliPlugin<AppTools>;
5
+ export default moduleFederationSSRPlugin;
@@ -4,43 +4,8 @@ import { PluginOptions } from '../types';
4
4
  import { BundlerConfig } from '../interfaces/bundler';
5
5
  export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
6
6
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
7
- export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => {
8
- runtimePlugins: string[];
9
- exposes?: moduleFederationPlugin.Exposes;
10
- filename?: string;
11
- library?: moduleFederationPlugin.LibraryOptions;
12
- name?: string;
13
- remoteType?: moduleFederationPlugin.ExternalsType;
14
- remotes?: moduleFederationPlugin.Remotes;
15
- runtime?: moduleFederationPlugin.EntryRuntime;
16
- shareScope?: string;
17
- shared?: moduleFederationPlugin.Shared;
18
- getPublicPath?: string;
19
- implementation?: string;
20
- manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
21
- dev?: boolean | moduleFederationPlugin.PluginDevOptions;
22
- dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
23
- async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
24
- };
25
- export declare function getTargetEnvConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean): {
26
- runtimePlugins: string[];
27
- exposes?: moduleFederationPlugin.Exposes;
28
- filename?: string;
29
- library?: moduleFederationPlugin.LibraryOptions;
30
- name?: string;
31
- remoteType?: moduleFederationPlugin.ExternalsType;
32
- remotes?: moduleFederationPlugin.Remotes;
33
- runtime?: moduleFederationPlugin.EntryRuntime;
34
- shareScope?: string;
35
- shared?: moduleFederationPlugin.Shared;
36
- getPublicPath?: string;
37
- implementation?: string;
38
- manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
39
- dev?: boolean | moduleFederationPlugin.PluginDevOptions;
40
- dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
41
- async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
42
- };
43
- export declare function patchWebpackConfig<T extends Bundler>(options: {
7
+ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => moduleFederationPlugin.ModuleFederationPluginOptions;
8
+ export declare function patchBundlerConfig<T extends Bundler>(options: {
44
9
  bundlerConfig: BundlerConfig<T>;
45
10
  isServer: boolean;
46
11
  modernjsConfig: UserConfig<AppTools>;
@@ -1,2 +1,2 @@
1
1
  import type { Plugin } from '@modern-js/runtime';
2
- export declare const mfPluginSSR: () => Plugin;
2
+ export declare const mfSSRPlugin: () => Plugin;