@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.
@@ -30,9 +30,8 @@ var utils_exports = {};
30
30
  __export(utils_exports, {
31
31
  getIPV4: () => getIPV4,
32
32
  getMFConfig: () => getMFConfig,
33
- getTargetEnvConfig: () => getTargetEnvConfig,
34
- patchMFConfig: () => patchMFConfig,
35
- patchWebpackConfig: () => patchWebpackConfig
33
+ patchBundlerConfig: () => patchBundlerConfig,
34
+ patchMFConfig: () => patchMFConfig
36
35
  });
37
36
  module.exports = __toCommonJS(utils_exports);
38
37
  var import_sdk = require("@module-federation/sdk");
@@ -50,13 +49,6 @@ const getMFConfig = async (userConfig) => {
50
49
  const mfConfigPath = configPath ? configPath : defaultPath;
51
50
  const preBundlePath = await (0, import_node_bundle_require.bundle)(mfConfigPath);
52
51
  const mfConfig = (await Promise.resolve().then(() => __toESM(require(preBundlePath)))).default;
53
- await replaceRemoteUrl(mfConfig);
54
- if (mfConfig.remoteType === void 0) {
55
- mfConfig.remoteType = "script";
56
- }
57
- if (!mfConfig.name) {
58
- throw new Error(`${import_constant.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
59
- }
60
52
  return mfConfig;
61
53
  };
62
54
  const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
@@ -64,7 +56,7 @@ const injectRuntimePlugins = (runtimePlugin, runtimePlugins) => {
64
56
  runtimePlugins.push(runtimePlugin);
65
57
  }
66
58
  };
67
- const replaceRemoteUrl = async (mfConfig) => {
59
+ const replaceRemoteUrl = (mfConfig) => {
68
60
  if (!mfConfig.remotes) {
69
61
  return;
70
62
  }
@@ -127,6 +119,13 @@ const patchDTSConfig = (mfConfig, isServer) => {
127
119
  }
128
120
  };
129
121
  const patchMFConfig = (mfConfig, isServer) => {
122
+ replaceRemoteUrl(mfConfig);
123
+ if (mfConfig.remoteType === void 0) {
124
+ mfConfig.remoteType = "script";
125
+ }
126
+ if (!mfConfig.name) {
127
+ throw new Error(`${import_constant.PLUGIN_IDENTIFIER} mfConfig.name can not be empty!`);
128
+ }
130
129
  const runtimePlugins = [
131
130
  ...mfConfig.runtimePlugins || []
132
131
  ];
@@ -140,44 +139,33 @@ const patchMFConfig = (mfConfig, isServer) => {
140
139
  injectRuntimePlugins(require.resolve("@module-federation/node/record-dynamic-remote-entry-hash-plugin"), runtimePlugins);
141
140
  }
142
141
  injectRuntimePlugins(import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js"), runtimePlugins);
143
- }
144
- if (!isServer) {
145
- return {
146
- ...mfConfig,
147
- runtimePlugins
148
- };
149
- }
150
- return {
151
- ...mfConfig,
152
- runtimePlugins,
153
- dts: false,
154
- dev: false
155
- };
156
- };
157
- function getTargetEnvConfig(mfConfig, isServer) {
158
- var _patchedMFConfig_library;
159
- const patchedMFConfig = patchMFConfig(mfConfig, isServer);
160
- if (isServer) {
161
- return {
162
- library: {
142
+ if (!mfConfig.library) {
143
+ mfConfig.library = {
163
144
  type: "commonjs-module",
164
145
  name: mfConfig.name
165
- },
166
- ...patchedMFConfig
167
- };
168
- }
169
- if (((_patchedMFConfig_library = patchedMFConfig.library) === null || _patchedMFConfig_library === void 0 ? void 0 : _patchedMFConfig_library.type) === "commonjs-module") {
170
- return {
171
- ...patchedMFConfig,
172
- library: {
173
- ...mfConfig.library,
174
- type: "global"
146
+ };
147
+ } else {
148
+ if (!mfConfig.library.type) {
149
+ mfConfig.library.type = "commonjs-module";
175
150
  }
176
- };
151
+ if (!mfConfig.library.name) {
152
+ mfConfig.library.name = mfConfig.name;
153
+ }
154
+ }
177
155
  }
178
- return patchedMFConfig;
179
- }
180
- function patchWebpackConfig(options) {
156
+ mfConfig.runtimePlugins = runtimePlugins;
157
+ if (!isServer) {
158
+ var _mfConfig_library;
159
+ if (((_mfConfig_library = mfConfig.library) === null || _mfConfig_library === void 0 ? void 0 : _mfConfig_library.type) === "commonjs-module") {
160
+ mfConfig.library.type = "global";
161
+ }
162
+ return mfConfig;
163
+ }
164
+ mfConfig.dts = false;
165
+ mfConfig.dev = false;
166
+ return mfConfig;
167
+ };
168
+ function patchBundlerConfig(options) {
181
169
  var _modernjsConfig_server, _bundlerConfig_optimization, _bundlerConfig_optimization1, _bundlerConfig_output, _modernjsConfig_deploy;
182
170
  const { bundlerConfig, modernjsConfig, isServer, mfConfig } = options;
183
171
  const enableSSR = Boolean((_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
@@ -298,7 +286,6 @@ function autoDeleteSplitChunkCacheGroups(mfConfig, bundlerConfig) {
298
286
  0 && (module.exports = {
299
287
  getIPV4,
300
288
  getMFConfig,
301
- getTargetEnvConfig,
302
- patchMFConfig,
303
- patchWebpackConfig
289
+ patchBundlerConfig,
290
+ patchMFConfig
304
291
  });
@@ -41,10 +41,12 @@ const mfConfig = {
41
41
  }
42
42
  }
43
43
  };
44
- (0, import_vitest.describe)("getTargetEnvConfig", async () => {
45
- (0, import_vitest.it)("getTargetEnvConfig: server", async () => {
46
- const targetEnvConfig = (0, import_utils.getTargetEnvConfig)(mfConfig, true);
47
- (0, import_vitest.expect)(targetEnvConfig).toStrictEqual({
44
+ (0, import_vitest.describe)("patchMFConfig", async () => {
45
+ (0, import_vitest.it)("patchMFConfig: server", async () => {
46
+ const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
47
+ (0, import_utils.patchMFConfig)(patchedConfig, true);
48
+ const ipv4 = (0, import_utils.getIPV4)();
49
+ (0, import_vitest.expect)(patchedConfig).toStrictEqual({
48
50
  dev: false,
49
51
  dts: false,
50
52
  filename: "remoteEntry.js",
@@ -54,8 +56,9 @@ const mfConfig = {
54
56
  },
55
57
  name: "host",
56
58
  remotes: {
57
- remote: "http://localhost:3000/remoteEntry.js"
59
+ remote: `http://${ipv4}:3000/remoteEntry.js`
58
60
  },
61
+ remoteType: "script",
59
62
  runtimePlugins: [
60
63
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js"),
61
64
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/inject-node-fetch.js")
@@ -72,14 +75,17 @@ const mfConfig = {
72
75
  }
73
76
  });
74
77
  });
75
- (0, import_vitest.it)("getTargetEnvConfig: client", async () => {
76
- const targetEnvConfig = (0, import_utils.getTargetEnvConfig)(mfConfig, false);
77
- (0, import_vitest.expect)(targetEnvConfig).toStrictEqual({
78
+ (0, import_vitest.it)("patchMFConfig: client", async () => {
79
+ const patchedConfig = JSON.parse(JSON.stringify(mfConfig));
80
+ (0, import_utils.patchMFConfig)(patchedConfig, false);
81
+ const ipv4 = (0, import_utils.getIPV4)();
82
+ (0, import_vitest.expect)(patchedConfig).toStrictEqual({
78
83
  filename: "remoteEntry.js",
79
84
  name: "host",
80
85
  remotes: {
81
- remote: "http://localhost:3000/remoteEntry.js"
86
+ remote: `http://${ipv4}:3000/remoteEntry.js`
82
87
  },
88
+ remoteType: "script",
83
89
  runtimePlugins: [
84
90
  import_path.default.resolve(__dirname, "./mfRuntimePlugins/shared-strategy.js")
85
91
  ],
@@ -103,14 +109,14 @@ const mfConfig = {
103
109
  });
104
110
  });
105
111
  });
106
- (0, import_vitest.describe)("patchWebpackConfig", async () => {
107
- (0, import_vitest.it)("patchWebpackConfig: server", async () => {
112
+ (0, import_vitest.describe)("patchBundlerConfig", async () => {
113
+ (0, import_vitest.it)("patchBundlerConfig: server", async () => {
108
114
  const bundlerConfig = {
109
115
  output: {
110
116
  publicPath: "auto"
111
117
  }
112
118
  };
113
- (0, import_utils.patchWebpackConfig)({
119
+ (0, import_utils.patchBundlerConfig)({
114
120
  bundlerConfig,
115
121
  isServer: true,
116
122
  modernjsConfig: {
@@ -130,13 +136,13 @@ const mfConfig = {
130
136
  }
131
137
  });
132
138
  });
133
- (0, import_vitest.it)("patchWebpackConfig: client", async () => {
139
+ (0, import_vitest.it)("patchBundlerConfig: client", async () => {
134
140
  const bundlerConfig = {
135
141
  output: {
136
142
  publicPath: "auto"
137
143
  }
138
144
  };
139
- (0, import_utils.patchWebpackConfig)({
145
+ (0, import_utils.patchBundlerConfig)({
140
146
  bundlerConfig,
141
147
  isServer: false,
142
148
  modernjsConfig: {
@@ -28,13 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var plugin_exports = {};
30
30
  __export(plugin_exports, {
31
- mfPluginSSR: () => mfPluginSSR
31
+ mfSSRPlugin: () => mfSSRPlugin
32
32
  });
33
33
  module.exports = __toCommonJS(plugin_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
36
36
  var import_SSRLiveReload = require("./SSRLiveReload");
37
- const mfPluginSSR = () => ({
37
+ const mfSSRPlugin = () => ({
38
38
  name: "@module-federation/modern-js",
39
39
  setup: () => {
40
40
  return {
@@ -75,5 +75,5 @@ const mfPluginSSR = () => ({
75
75
  });
76
76
  // Annotate the CommonJS export names for ESM import in node:
77
77
  0 && (module.exports = {
78
- mfPluginSSR
78
+ mfSSRPlugin
79
79
  });
@@ -0,0 +1,132 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import path from "path";
4
+ import { patchBundlerConfig, getIPV4, getMFConfig, patchMFConfig } from "./utils";
5
+ function setEnv(enableSSR) {
6
+ if (enableSSR) {
7
+ process.env["MF_DISABLE_EMIT_STATS"] = "true";
8
+ process.env["MF_SSR_PRJ"] = "true";
9
+ }
10
+ }
11
+ function modifyBundlerConfig(options) {
12
+ var mfConfig = options.mfConfig, config = options.config, isServer = options.isServer, modernjsConfig = options.modernjsConfig, bundlerType = options.bundlerType;
13
+ patchMFConfig(mfConfig, isServer);
14
+ patchBundlerConfig({
15
+ bundlerConfig: config,
16
+ isServer,
17
+ modernjsConfig,
18
+ mfConfig
19
+ });
20
+ if (bundlerType === "webpack") {
21
+ config.ignoreWarnings = config.ignoreWarnings || [];
22
+ config.ignoreWarnings.push(function(warning) {
23
+ if (warning.message.includes("external script")) {
24
+ return true;
25
+ }
26
+ return false;
27
+ });
28
+ }
29
+ }
30
+ var moduleFederationConfigPlugin = function(userConfig) {
31
+ return {
32
+ name: "@modern-js/plugin-module-federation-config",
33
+ post: [
34
+ "@modern-js/plugin-module-federation"
35
+ ],
36
+ setup: function() {
37
+ var _ref = _async_to_generator(function(param) {
38
+ var useConfigContext, useAppContext, modernjsConfig, mfConfig, csrConfig, ssrConfig;
39
+ return _ts_generator(this, function(_state) {
40
+ switch (_state.label) {
41
+ case 0:
42
+ useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
43
+ console.log("config plugin");
44
+ modernjsConfig = useConfigContext();
45
+ return [
46
+ 4,
47
+ getMFConfig(userConfig.originPluginOptions)
48
+ ];
49
+ case 1:
50
+ mfConfig = _state.sent();
51
+ csrConfig = userConfig.csrConfig || JSON.parse(JSON.stringify(mfConfig));
52
+ ssrConfig = userConfig.ssrConfig || JSON.parse(JSON.stringify(mfConfig));
53
+ userConfig.ssrConfig = ssrConfig;
54
+ userConfig.csrConfig = csrConfig;
55
+ return [
56
+ 2,
57
+ {
58
+ config: /* @__PURE__ */ _async_to_generator(function() {
59
+ var _modernjsConfig_dev, bundlerType, ipv4;
60
+ return _ts_generator(this, function(_state2) {
61
+ bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
62
+ ipv4 = getIPV4();
63
+ return [
64
+ 2,
65
+ {
66
+ tools: {
67
+ rspack: function rspack(config, param2) {
68
+ var isServer = param2.isServer;
69
+ var _config_output;
70
+ modifyBundlerConfig({
71
+ bundlerType,
72
+ mfConfig: isServer ? ssrConfig : csrConfig,
73
+ config,
74
+ isServer,
75
+ // MFBundlerPlugin,
76
+ modernjsConfig
77
+ });
78
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
79
+ },
80
+ webpack: function webpack(config, param2) {
81
+ var isServer = param2.isServer;
82
+ var _config_output;
83
+ modifyBundlerConfig({
84
+ bundlerType,
85
+ mfConfig: isServer ? ssrConfig : csrConfig,
86
+ config,
87
+ isServer,
88
+ modernjsConfig
89
+ });
90
+ userConfig.distOutputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
91
+ },
92
+ devServer: {
93
+ headers: {
94
+ "Access-Control-Allow-Origin": "*",
95
+ "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
96
+ "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
97
+ }
98
+ }
99
+ },
100
+ source: {
101
+ alias: {
102
+ "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
103
+ },
104
+ define: {
105
+ FEDERATION_IPV4: JSON.stringify(ipv4)
106
+ }
107
+ },
108
+ dev: {
109
+ 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
110
+ }
111
+ }
112
+ ];
113
+ });
114
+ })
115
+ }
116
+ ];
117
+ }
118
+ });
119
+ });
120
+ return function(_) {
121
+ return _ref.apply(this, arguments);
122
+ };
123
+ }()
124
+ };
125
+ };
126
+ var configPlugin_default = moduleFederationConfigPlugin;
127
+ export {
128
+ configPlugin_default as default,
129
+ modifyBundlerConfig,
130
+ moduleFederationConfigPlugin,
131
+ setEnv
132
+ };
@@ -0,0 +1,4 @@
1
+ var isDev = process.env.NODE_ENV === "development";
2
+ export {
3
+ isDev
4
+ };
@@ -1,224 +1,86 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
- import path from "path";
4
- import { fs } from "@modern-js/utils";
5
3
  import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
6
4
  import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
7
- import { StreamingTargetPlugin, EntryChunkTrackerPlugin } from "@module-federation/node";
8
- import { getMFConfig, getTargetEnvConfig, patchWebpackConfig, getIPV4 } from "./utils";
9
- import { updateStatsAndManifest } from "./manifest";
10
- import { MODERN_JS_SERVER_DIR, PLUGIN_IDENTIFIER } from "../constant";
11
- var SSR_PLUGIN_IDENTIFIER = "mfPluginSSR";
12
- var isDev = process.env.NODE_ENV === "development";
5
+ import { moduleFederationConfigPlugin } from "./configPlugin";
6
+ import { moduleFederationSSRPlugin } from "./ssrPlugin";
13
7
  var moduleFederationPlugin = function() {
14
8
  var userConfig = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
9
+ var internalModernPluginOptions = {
10
+ csrConfig: void 0,
11
+ ssrConfig: void 0,
12
+ browserPlugin: void 0,
13
+ nodePlugin: void 0,
14
+ distOutputDir: "",
15
+ originPluginOptions: userConfig
16
+ };
15
17
  return {
16
18
  name: "@modern-js/plugin-module-federation",
17
19
  setup: function() {
18
20
  var _ref = _async_to_generator(function(param) {
19
- var useConfigContext, useAppContext, _modernjsConfig_server, modernjsConfig, enableSSR, mfConfig, outputDir, browserPlugin, nodePlugin;
21
+ var useConfigContext, modernjsConfig;
20
22
  return _ts_generator(this, function(_state) {
21
- switch (_state.label) {
22
- case 0:
23
- useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
24
- modernjsConfig = useConfigContext();
25
- enableSSR = Boolean(modernjsConfig === null || modernjsConfig === void 0 ? void 0 : (_modernjsConfig_server = modernjsConfig.server) === null || _modernjsConfig_server === void 0 ? void 0 : _modernjsConfig_server.ssr);
26
- return [
27
- 4,
28
- getMFConfig(userConfig)
29
- ];
30
- case 1:
31
- mfConfig = _state.sent();
32
- outputDir = "";
33
- return [
34
- 2,
35
- {
36
- config: /* @__PURE__ */ _async_to_generator(function() {
37
- var _modernjsConfig_dev, bundlerType, WebpackPluginConstructor, RspackPluginConstructor, MFBundlerPlugin, modifyBundlerConfig, ipv4;
38
- return _ts_generator(this, function(_state2) {
39
- bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
40
- WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
41
- RspackPluginConstructor = userConfig.rspackPluginImplementation || RspackModuleFederationPlugin;
42
- MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
43
- if (enableSSR) {
44
- process.env["MF_DISABLE_EMIT_STATS"] = "true";
45
- process.env["MF_SSR_PRJ"] = "true";
46
- }
47
- modifyBundlerConfig = function(config, isServer) {
48
- var envConfig = getTargetEnvConfig(mfConfig, isServer);
49
- if (isServer) {
50
- var _config_plugins, _config_plugins1;
51
- nodePlugin = new MFBundlerPlugin(envConfig);
52
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
53
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
54
- if (isDev) {
55
- var _config_plugins2;
56
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(new EntryChunkTrackerPlugin());
23
+ useConfigContext = param.useConfigContext;
24
+ console.log("main plugin");
25
+ modernjsConfig = useConfigContext();
26
+ return [
27
+ 2,
28
+ {
29
+ config: /* @__PURE__ */ _async_to_generator(function() {
30
+ return _ts_generator(this, function(_state2) {
31
+ return [
32
+ 2,
33
+ {
34
+ tools: {
35
+ rspack: function rspack(config, param2) {
36
+ var isServer = param2.isServer;
37
+ var browserPluginOptions = internalModernPluginOptions.csrConfig;
38
+ if (!isServer) {
39
+ var _config_plugins;
40
+ internalModernPluginOptions.browserPlugin = new RspackModuleFederationPlugin(browserPluginOptions);
41
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
57
42
  }
58
- } else {
59
- var _config_output, _config_plugins3;
60
- outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
61
- browserPlugin = new MFBundlerPlugin(envConfig);
62
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(browserPlugin);
63
- }
64
- patchWebpackConfig({
65
- bundlerConfig: config,
66
- isServer,
67
- modernjsConfig,
68
- mfConfig: envConfig
69
- });
70
- };
71
- ipv4 = getIPV4();
72
- return [
73
- 2,
74
- {
75
- tools: {
76
- rspack: function rspack(config) {
77
- if (enableSSR) {
78
- throw new Error("".concat(PLUGIN_IDENTIFIER, " not support ssr for rspack bundler yet!"));
79
- }
80
- modifyBundlerConfig(config, false);
81
- },
82
- webpack: function webpack(config, param2) {
83
- var isServer = param2.isServer;
84
- var _modernjsConfig_source;
85
- modifyBundlerConfig(config, isServer);
86
- var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
87
- if (!enableAsyncEntry && mfConfig.async !== false) {
88
- var _config_plugins;
89
- var asyncBoundaryPluginOptions = typeof mfConfig.async === "object" ? mfConfig.async : {
90
- eager: function(module) {
91
- return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
92
- },
93
- excludeChunk: function(chunk) {
94
- return chunk.name === mfConfig.name;
95
- }
96
- };
97
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
98
- }
99
- config.ignoreWarnings = config.ignoreWarnings || [];
100
- config.ignoreWarnings.push(function(warning) {
101
- if (warning.message.includes("external script")) {
102
- return true;
103
- }
104
- return false;
105
- });
106
- },
107
- devServer: {
108
- headers: {
109
- "Access-Control-Allow-Origin": "*",
110
- "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
111
- "Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
43
+ },
44
+ webpack: function webpack(config, param2) {
45
+ var isServer = param2.isServer;
46
+ var _modernjsConfig_source;
47
+ var browserPluginOptions = internalModernPluginOptions.csrConfig;
48
+ if (!isServer) {
49
+ var _config_plugins;
50
+ internalModernPluginOptions.browserPlugin = new WebpackModuleFederationPlugin(browserPluginOptions);
51
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(internalModernPluginOptions.browserPlugin);
52
+ }
53
+ var enableAsyncEntry = (_modernjsConfig_source = modernjsConfig.source) === null || _modernjsConfig_source === void 0 ? void 0 : _modernjsConfig_source.enableAsyncEntry;
54
+ if (!enableAsyncEntry && browserPluginOptions.async !== false) {
55
+ var _config_plugins1;
56
+ var asyncBoundaryPluginOptions = typeof browserPluginOptions.async === "object" ? browserPluginOptions.async : {
57
+ eager: function(module) {
58
+ return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
112
59
  },
113
- before: [
114
- function(req, res, next) {
115
- if (!enableSSR) {
116
- next();
117
- return;
118
- }
119
- try {
120
- var _req_url, _req_url1, _req_url2;
121
- var SERVER_PREFIX = "/".concat(MODERN_JS_SERVER_DIR);
122
- 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"))) {
123
- var filepath = path.join(process.cwd(), "dist".concat(req.url));
124
- fs.statSync(filepath);
125
- res.setHeader("Access-Control-Allow-Origin", "*");
126
- res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, PATCH, OPTIONS");
127
- res.setHeader("Access-Control-Allow-Headers", "X-Requested-With, content-type, Authorization");
128
- fs.createReadStream(filepath).pipe(res);
129
- } else {
130
- next();
131
- }
132
- } catch (err) {
133
- if (process.env.FEDERATION_DEBUG) {
134
- console.error(err);
135
- }
136
- next();
137
- }
138
- }
139
- ]
140
- },
141
- bundlerChain: function bundlerChain(chain, param2) {
142
- var isServer = param2.isServer;
143
- if (isDev && !isServer) {
144
- chain.externals({
145
- "@module-federation/node/utils": "NOT_USED_IN_BROWSER"
146
- });
60
+ excludeChunk: function(chunk) {
61
+ return chunk.name === browserPluginOptions.name;
147
62
  }
148
- }
149
- },
150
- source: {
151
- alias: {
152
- "@modern-js/runtime/mf": require.resolve("@module-federation/modern-js/runtime")
153
- },
154
- define: {
155
- FEDERATION_IPV4: JSON.stringify(ipv4)
156
- }
157
- },
158
- dev: {
159
- 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
63
+ };
64
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
160
65
  }
161
66
  }
162
- ];
163
- });
164
- }),
165
- modifyEntryImports: function modifyEntryImports(param2) {
166
- var entrypoint = param2.entrypoint, imports = param2.imports;
167
- if (!enableSSR || !isDev) {
168
- return {
169
- entrypoint,
170
- imports
171
- };
172
- }
173
- imports.push({
174
- value: "@module-federation/modern-js/ssr-runtime",
175
- specifiers: [
176
- {
177
- imported: SSR_PLUGIN_IDENTIFIER
178
- }
179
- ]
180
- });
181
- return {
182
- entrypoint,
183
- imports
184
- };
185
- },
186
- modifyEntryRuntimePlugins: function modifyEntryRuntimePlugins(param2) {
187
- var entrypoint = param2.entrypoint, plugins = param2.plugins;
188
- if (!enableSSR || !isDev) {
189
- return {
190
- entrypoint,
191
- plugins
192
- };
193
- }
194
- plugins.unshift({
195
- name: SSR_PLUGIN_IDENTIFIER,
196
- options: JSON.stringify({})
197
- });
198
- return {
199
- entrypoint,
200
- plugins
201
- };
202
- },
203
- afterBuild: function() {
204
- if (enableSSR) {
205
- updateStatsAndManifest(nodePlugin, browserPlugin, outputDir);
206
- }
207
- },
208
- afterDev: function() {
209
- if (enableSSR) {
210
- updateStatsAndManifest(nodePlugin, browserPlugin, outputDir);
67
+ }
211
68
  }
212
- }
213
- }
214
- ];
215
- }
69
+ ];
70
+ });
71
+ })
72
+ }
73
+ ];
216
74
  });
217
75
  });
218
76
  return function(_) {
219
77
  return _ref.apply(this, arguments);
220
78
  };
221
- }()
79
+ }(),
80
+ usePlugins: [
81
+ moduleFederationConfigPlugin(internalModernPluginOptions),
82
+ moduleFederationSSRPlugin(internalModernPluginOptions)
83
+ ]
222
84
  };
223
85
  };
224
86
  var cli_default = moduleFederationPlugin;