@module-federation/modern-js 0.0.0-next-20240515104620 → 0.0.0-next-20240515125630

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.
@@ -36,6 +36,7 @@ module.exports = __toCommonJS(cli_exports);
36
36
  var import_path = __toESM(require("path"));
37
37
  var import_utils = require("@modern-js/utils");
38
38
  var import_enhanced = require("@module-federation/enhanced");
39
+ var import_rspack = require("@module-federation/enhanced/rspack");
39
40
  var import_node = require("@module-federation/node");
40
41
  var import_utils2 = require("./utils");
41
42
  var import_manifest = require("./manifest");
@@ -43,13 +44,16 @@ var import_constant = require("../constant");
43
44
  var import_enhanced2 = require("@module-federation/enhanced");
44
45
  const moduleFederationPlugin = (userConfig = {}) => ({
45
46
  name: "@modern-js/plugin-module-federation",
46
- setup: async ({ useConfigContext }) => {
47
+ setup: async ({ useConfigContext, useAppContext }) => {
47
48
  var _useConfig_server;
48
49
  const useConfig = useConfigContext();
49
50
  const enableSSR = Boolean(useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.ssr);
50
51
  const mfConfig = await (0, import_utils2.getMFConfig)(userConfig);
51
52
  let outputDir = "";
53
+ const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
52
54
  const WebpackPluginConstructor = userConfig.webpackPluginImplementation || import_enhanced.ModuleFederationPlugin;
55
+ const RspackPluginConstructor = userConfig.webpackPluginImplementation || import_rspack.ModuleFederationPlugin;
56
+ const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
53
57
  let browserPlugin;
54
58
  let nodePlugin;
55
59
  return {
@@ -58,35 +62,41 @@ const moduleFederationPlugin = (userConfig = {}) => ({
58
62
  if (enableSSR) {
59
63
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
60
64
  }
65
+ const modifyBundlerConfig = (config, isServer) => {
66
+ const envConfig = (0, import_utils2.getTargetEnvConfig)(mfConfig, isServer);
67
+ if (isServer) {
68
+ var _config_plugins, _config_plugins1;
69
+ nodePlugin = new MFBundlerPlugin(envConfig);
70
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
71
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(envConfig));
72
+ } else {
73
+ var _config_output, _config_plugins2;
74
+ outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
75
+ browserPlugin = new MFBundlerPlugin(envConfig);
76
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
77
+ }
78
+ (0, import_utils2.patchWebpackConfig)({
79
+ config,
80
+ isServer,
81
+ useConfig
82
+ });
83
+ };
61
84
  return {
62
85
  tools: {
86
+ rspack(config) {
87
+ modifyBundlerConfig(config, false);
88
+ },
63
89
  webpack(config, { isServer }) {
64
90
  var _useConfig_source;
65
- const envConfig = (0, import_utils2.getTargetEnvConfig)(mfConfig, isServer);
66
- if (isServer) {
67
- var _config_plugins, _config_plugins1;
68
- nodePlugin = new WebpackPluginConstructor(envConfig);
69
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
70
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new import_node.StreamingTargetPlugin(envConfig));
71
- } else {
72
- var _config_output, _config_plugins2;
73
- outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || import_path.default.resolve(process.cwd(), "dist");
74
- browserPlugin = new WebpackPluginConstructor(envConfig);
75
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
76
- }
77
- (0, import_utils2.patchWebpackConfig)({
78
- config,
79
- isServer,
80
- useConfig
81
- });
91
+ modifyBundlerConfig(config, isServer);
82
92
  const enableAsyncEntry = (_useConfig_source = useConfig.source) === null || _useConfig_source === void 0 ? void 0 : _useConfig_source.enableAsyncEntry;
83
93
  if (!enableAsyncEntry && mfConfig.async) {
84
- var _config_plugins3;
94
+ var _config_plugins;
85
95
  const asyncBoundaryPluginOptions = {
86
96
  eager: (module2) => module2 && /\.federation/.test((module2 === null || module2 === void 0 ? void 0 : module2.request) || ""),
87
97
  excludeChunk: (chunk) => chunk.name === mfConfig.name
88
98
  };
89
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
99
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new import_enhanced.AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
90
100
  }
91
101
  },
92
102
  devServer: {
@@ -2,7 +2,8 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import path from "path";
4
4
  import { fs } from "@modern-js/utils";
5
- import { ModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
5
+ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
6
+ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
6
7
  import { StreamingTargetPlugin } from "@module-federation/node";
7
8
  import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
8
9
  import { updateStatsAndManifest } from "./manifest";
@@ -13,11 +14,11 @@ var moduleFederationPlugin = function() {
13
14
  name: "@modern-js/plugin-module-federation",
14
15
  setup: function() {
15
16
  var _ref = _async_to_generator(function(param) {
16
- var useConfigContext, _useConfig_server, useConfig, enableSSR, mfConfig, outputDir, WebpackPluginConstructor, browserPlugin, nodePlugin;
17
+ var useConfigContext, useAppContext, _useConfig_server, useConfig, enableSSR, mfConfig, outputDir, bundlerType, WebpackPluginConstructor, RspackPluginConstructor, MFBundlerPlugin, browserPlugin, nodePlugin;
17
18
  return _ts_generator(this, function(_state) {
18
19
  switch (_state.label) {
19
20
  case 0:
20
- useConfigContext = param.useConfigContext;
21
+ useConfigContext = param.useConfigContext, useAppContext = param.useAppContext;
21
22
  useConfig = useConfigContext();
22
23
  enableSSR = Boolean(useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.ssr);
23
24
  return [
@@ -27,7 +28,10 @@ var moduleFederationPlugin = function() {
27
28
  case 1:
28
29
  mfConfig = _state.sent();
29
30
  outputDir = "";
30
- WebpackPluginConstructor = userConfig.webpackPluginImplementation || ModuleFederationPlugin;
31
+ bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
32
+ WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
33
+ RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
34
+ MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
31
35
  return [
32
36
  2,
33
37
  {
@@ -36,31 +40,37 @@ var moduleFederationPlugin = function() {
36
40
  if (enableSSR) {
37
41
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
38
42
  }
43
+ var modifyBundlerConfig = function(config, isServer) {
44
+ var envConfig = getTargetEnvConfig(mfConfig, isServer);
45
+ if (isServer) {
46
+ var _config_plugins, _config_plugins1;
47
+ nodePlugin = new MFBundlerPlugin(envConfig);
48
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
49
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
50
+ } else {
51
+ var _config_output, _config_plugins2;
52
+ outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
53
+ browserPlugin = new MFBundlerPlugin(envConfig);
54
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
55
+ }
56
+ patchWebpackConfig({
57
+ config,
58
+ isServer,
59
+ useConfig
60
+ });
61
+ };
39
62
  return {
40
63
  tools: {
64
+ rspack: function rspack(config) {
65
+ modifyBundlerConfig(config, false);
66
+ },
41
67
  webpack: function webpack(config, param2) {
42
68
  var isServer = param2.isServer;
43
69
  var _useConfig_source;
44
- var envConfig = getTargetEnvConfig(mfConfig, isServer);
45
- if (isServer) {
46
- var _config_plugins, _config_plugins1;
47
- nodePlugin = new WebpackPluginConstructor(envConfig);
48
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
49
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
50
- } else {
51
- var _config_output, _config_plugins2;
52
- outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
53
- browserPlugin = new WebpackPluginConstructor(envConfig);
54
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
55
- }
56
- patchWebpackConfig({
57
- config,
58
- isServer,
59
- useConfig
60
- });
70
+ modifyBundlerConfig(config, isServer);
61
71
  var enableAsyncEntry = (_useConfig_source = useConfig.source) === null || _useConfig_source === void 0 ? void 0 : _useConfig_source.enableAsyncEntry;
62
72
  if (!enableAsyncEntry && mfConfig.async) {
63
- var _config_plugins3;
73
+ var _config_plugins;
64
74
  var asyncBoundaryPluginOptions = {
65
75
  eager: function(module) {
66
76
  return module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || "");
@@ -69,7 +79,7 @@ var moduleFederationPlugin = function() {
69
79
  return chunk.name === mfConfig.name;
70
80
  }
71
81
  };
72
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
82
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
73
83
  }
74
84
  },
75
85
  devServer: {
@@ -1,19 +1,23 @@
1
1
  import path from "path";
2
2
  import { fs } from "@modern-js/utils";
3
- import { ModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
3
+ import { ModuleFederationPlugin as WebpackModuleFederationPlugin, AsyncBoundaryPlugin } from "@module-federation/enhanced";
4
+ import { ModuleFederationPlugin as RspackModuleFederationPlugin } from "@module-federation/enhanced/rspack";
4
5
  import { StreamingTargetPlugin } from "@module-federation/node";
5
6
  import { getMFConfig, getTargetEnvConfig, patchWebpackConfig } from "./utils";
6
7
  import { updateStatsAndManifest } from "./manifest";
7
8
  import { MODERN_JS_SERVER_DIR } from "../constant";
8
9
  const moduleFederationPlugin = (userConfig = {}) => ({
9
10
  name: "@modern-js/plugin-module-federation",
10
- setup: async ({ useConfigContext }) => {
11
+ setup: async ({ useConfigContext, useAppContext }) => {
11
12
  var _useConfig_server;
12
13
  const useConfig = useConfigContext();
13
14
  const enableSSR = Boolean(useConfig === null || useConfig === void 0 ? void 0 : (_useConfig_server = useConfig.server) === null || _useConfig_server === void 0 ? void 0 : _useConfig_server.ssr);
14
15
  const mfConfig = await getMFConfig(userConfig);
15
16
  let outputDir = "";
16
- const WebpackPluginConstructor = userConfig.webpackPluginImplementation || ModuleFederationPlugin;
17
+ const bundlerType = useAppContext().bundlerType === "rspack" ? "rspack" : "webpack";
18
+ const WebpackPluginConstructor = userConfig.webpackPluginImplementation || WebpackModuleFederationPlugin;
19
+ const RspackPluginConstructor = userConfig.webpackPluginImplementation || RspackModuleFederationPlugin;
20
+ const MFBundlerPlugin = bundlerType === "rspack" ? RspackPluginConstructor : WebpackPluginConstructor;
17
21
  let browserPlugin;
18
22
  let nodePlugin;
19
23
  return {
@@ -22,35 +26,41 @@ const moduleFederationPlugin = (userConfig = {}) => ({
22
26
  if (enableSSR) {
23
27
  process.env["MF_DISABLE_EMIT_STATS"] = "true";
24
28
  }
29
+ const modifyBundlerConfig = (config, isServer) => {
30
+ const envConfig = getTargetEnvConfig(mfConfig, isServer);
31
+ if (isServer) {
32
+ var _config_plugins, _config_plugins1;
33
+ nodePlugin = new MFBundlerPlugin(envConfig);
34
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
35
+ (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
36
+ } else {
37
+ var _config_output, _config_plugins2;
38
+ outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
39
+ browserPlugin = new MFBundlerPlugin(envConfig);
40
+ (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
41
+ }
42
+ patchWebpackConfig({
43
+ config,
44
+ isServer,
45
+ useConfig
46
+ });
47
+ };
25
48
  return {
26
49
  tools: {
50
+ rspack(config) {
51
+ modifyBundlerConfig(config, false);
52
+ },
27
53
  webpack(config, { isServer }) {
28
54
  var _useConfig_source;
29
- const envConfig = getTargetEnvConfig(mfConfig, isServer);
30
- if (isServer) {
31
- var _config_plugins, _config_plugins1;
32
- nodePlugin = new WebpackPluginConstructor(envConfig);
33
- (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(nodePlugin);
34
- (_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(new StreamingTargetPlugin(envConfig));
35
- } else {
36
- var _config_output, _config_plugins2;
37
- outputDir = ((_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.path) || path.resolve(process.cwd(), "dist");
38
- browserPlugin = new WebpackPluginConstructor(envConfig);
39
- (_config_plugins2 = config.plugins) === null || _config_plugins2 === void 0 ? void 0 : _config_plugins2.push(browserPlugin);
40
- }
41
- patchWebpackConfig({
42
- config,
43
- isServer,
44
- useConfig
45
- });
55
+ modifyBundlerConfig(config, isServer);
46
56
  const enableAsyncEntry = (_useConfig_source = useConfig.source) === null || _useConfig_source === void 0 ? void 0 : _useConfig_source.enableAsyncEntry;
47
57
  if (!enableAsyncEntry && mfConfig.async) {
48
- var _config_plugins3;
58
+ var _config_plugins;
49
59
  const asyncBoundaryPluginOptions = {
50
60
  eager: (module) => module && /\.federation/.test((module === null || module === void 0 ? void 0 : module.request) || ""),
51
61
  excludeChunk: (chunk) => chunk.name === mfConfig.name
52
62
  };
53
- (_config_plugins3 = config.plugins) === null || _config_plugins3 === void 0 ? void 0 : _config_plugins3.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
63
+ (_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(new AsyncBoundaryPlugin(asyncBoundaryPluginOptions));
54
64
  }
55
65
  },
56
66
  devServer: {
@@ -1,2 +1,2 @@
1
- import { ModuleFederationPlugin } from '@module-federation/enhanced';
2
- export declare function updateStatsAndManifest(nodePlugin: ModuleFederationPlugin, browserPlugin: ModuleFederationPlugin, outputDir: string): void;
1
+ import { BundlerPlugin } from '../types';
2
+ export declare function updateStatsAndManifest(nodePlugin: BundlerPlugin, browserPlugin: BundlerPlugin, outputDir: string): void;
@@ -1,11 +1,12 @@
1
- import type { webpack, UserConfig, AppTools } from '@modern-js/app-tools';
1
+ import type { webpack, UserConfig, AppTools, Rspack } from '@modern-js/app-tools';
2
2
  import { moduleFederationPlugin } from '@module-federation/sdk';
3
3
  import { PluginOptions } from '../types';
4
+ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T extends 'rspack' ? Rspack.Configuration : never;
4
5
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
5
6
  export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => void;
6
7
  export declare function getTargetEnvConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean): moduleFederationPlugin.ModuleFederationPluginOptions;
7
- export declare function patchWebpackConfig(options: {
8
- config: webpack.Configuration;
8
+ export declare function patchWebpackConfig<T>(options: {
9
+ config: ConfigType<T>;
9
10
  isServer: boolean;
10
11
  useConfig: UserConfig<AppTools>;
11
12
  }): void;
@@ -7,3 +7,4 @@ export interface PluginOptions {
7
7
  webpackPluginImplementation?: typeof WebpackModuleFederationPlugin;
8
8
  rspackPluginImplementation?: typeof RspackModuleFederationPlugin;
9
9
  }
10
+ export type BundlerPlugin = WebpackModuleFederationPlugin | RspackModuleFederationPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240515104620",
3
+ "version": "0.0.0-next-20240515125630",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -38,9 +38,9 @@
38
38
  "@swc/helpers": "0.5.3",
39
39
  "@modern-js/utils": "^2.49.2",
40
40
  "@modern-js/node-bundle-require": "^2.49.2",
41
- "@module-federation/sdk": "0.0.0-next-20240515104620",
42
- "@module-federation/enhanced": "0.0.0-next-20240515104620",
43
- "@module-federation/node": "0.0.0-next-20240515104620"
41
+ "@module-federation/sdk": "0.0.0-next-20240515125630",
42
+ "@module-federation/enhanced": "0.0.0-next-20240515125630",
43
+ "@module-federation/node": "0.0.0-next-20240515125630"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@modern-js/app-tools": "^2.49.2",
@@ -48,7 +48,7 @@
48
48
  "@modern-js/runtime": "^2.49.2",
49
49
  "@modern-js/module-tools": "^2.35.0",
50
50
  "@modern-js/tsconfig": "^2.35.0",
51
- "@module-federation/manifest": "0.0.0-next-20240515104620"
51
+ "@module-federation/manifest": "0.0.0-next-20240515125630"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "modern build"