@nx/react 0.0.0-pr-28808-8717441 → 0.0.0-pr-28808-eac89e6

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.
Files changed (46) hide show
  1. package/migrations.json +27 -0
  2. package/module-federation.d.ts +6 -4
  3. package/module-federation.js +16 -7
  4. package/package.json +6 -7
  5. package/src/generators/application/application.js +9 -2
  6. package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
  7. package/src/generators/application/lib/add-e2e.js +5 -1
  8. package/src/generators/application/lib/add-project.js +67 -0
  9. package/src/generators/application/lib/create-application-files.js +28 -1
  10. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
  11. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +1 -1
  12. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  13. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  14. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +1 -1
  15. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  16. package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  17. package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +1 -1
  18. package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  19. package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  20. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +1 -1
  21. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  22. package/src/generators/library/library.js +1 -0
  23. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
  24. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  25. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  26. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  27. package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  28. package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  29. package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  30. package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  31. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  32. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  33. package/src/rules/update-module-federation-project.js +6 -4
  34. package/src/utils/build-static.remotes.d.ts +1 -1
  35. package/src/utils/has-rspack-plugin.d.ts +2 -0
  36. package/src/utils/has-rspack-plugin.js +10 -0
  37. package/src/utils/versions.d.ts +2 -2
  38. package/src/utils/versions.js +2 -2
  39. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.d.ts +0 -2
  40. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.js +0 -31
  41. package/src/module-federation/utils.d.ts +0 -12
  42. package/src/module-federation/utils.js +0 -75
  43. package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
  44. package/src/module-federation/with-module-federation-ssr.js +0 -50
  45. package/src/module-federation/with-module-federation.d.ts +0 -7
  46. package/src/module-federation/with-module-federation.js +0 -63
package/migrations.json CHANGED
@@ -35,6 +35,12 @@
35
35
  "version": "20.2.0-beta.2",
36
36
  "description": "Update the ModuleFederationConfig import use @nx/module-federation.",
37
37
  "factory": "./src/migrations/update-20-2-0/migrate-mf-imports-to-new-package"
38
+ },
39
+ "update-20-2-0-update-with-module-federation-import": {
40
+ "cli": "nx",
41
+ "version": "20.2.0-beta.2",
42
+ "description": "Update the withModuleFederation import use @nx/module-federation/webpack.",
43
+ "factory": "./src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package"
38
44
  }
39
45
  },
40
46
  "packageJsonUpdates": {
@@ -158,6 +164,27 @@
158
164
  "alwaysAddToPackageJson": false
159
165
  }
160
166
  }
167
+ },
168
+ "20.2.0": {
169
+ "version": "20.2.0-beta.3",
170
+ "packages": {
171
+ "@module-federation/enhanced": {
172
+ "version": "0.7.6",
173
+ "alwaysAddToPackageJson": false
174
+ },
175
+ "@module-federation/runtime": {
176
+ "version": "0.7.6",
177
+ "alwaysAddToPackageJson": false
178
+ },
179
+ "@module-federation/sdk": {
180
+ "version": "0.7.6",
181
+ "alwaysAddToPackageJson": false
182
+ },
183
+ "@module-federation/node": {
184
+ "version": "2.6.11",
185
+ "alwaysAddToPackageJson": false
186
+ }
187
+ }
161
188
  }
162
189
  }
163
190
  }
@@ -1,4 +1,6 @@
1
- import { withModuleFederation } from './src/module-federation/with-module-federation';
2
- import { withModuleFederationForSSR } from './src/module-federation/with-module-federation-ssr';
3
- export { withModuleFederation };
4
- export { withModuleFederationForSSR };
1
+ import { withModuleFederation } from '@nx/module-federation/webpack';
2
+ import { withModuleFederationForSSR } from '@nx/module-federation/webpack';
3
+ /**
4
+ * @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22.
5
+ */
6
+ export { withModuleFederation, withModuleFederationForSSR };
@@ -1,12 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.withModuleFederationForSSR = exports.withModuleFederation = void 0;
4
- const with_module_federation_1 = require("./src/module-federation/with-module-federation");
5
- Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return with_module_federation_1.withModuleFederation; } });
6
- const with_module_federation_ssr_1 = require("./src/module-federation/with-module-federation-ssr");
7
- Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return with_module_federation_ssr_1.withModuleFederationForSSR; } });
4
+ const webpack_1 = require("@nx/module-federation/webpack");
5
+ Object.defineProperty(exports, "withModuleFederation", { enumerable: true, get: function () { return webpack_1.withModuleFederation; } });
6
+ const webpack_2 = require("@nx/module-federation/webpack");
7
+ Object.defineProperty(exports, "withModuleFederationForSSR", { enumerable: true, get: function () { return webpack_2.withModuleFederationForSSR; } });
8
8
  // Support for older generated code: `const withModuleFederation = require('@nx/react/module-federation')`
9
- module.exports = with_module_federation_1.withModuleFederation;
9
+ /**
10
+ * @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22.
11
+ */
12
+ module.exports = webpack_1.withModuleFederation;
10
13
  // Allow newer generated code to work: `const { withModuleFederation } = require(...)`;
11
- module.exports.withModuleFederation = with_module_federation_1.withModuleFederation;
12
- module.exports.withModuleFederationForSSR = with_module_federation_ssr_1.withModuleFederationForSSR;
14
+ /**
15
+ * @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22.
16
+ */
17
+ module.exports.withModuleFederation = webpack_1.withModuleFederation;
18
+ /**
19
+ * @deprecated Use `@nx/module-federation/webpack` instead. This will be removed in Nx v22.
20
+ */
21
+ module.exports.withModuleFederationForSSR = webpack_2.withModuleFederationForSSR;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "0.0.0-pr-28808-8717441",
3
+ "version": "0.0.0-pr-28808-eac89e6",
4
4
  "private": false,
5
5
  "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -38,12 +38,11 @@
38
38
  "minimatch": "9.0.3",
39
39
  "picocolors": "^1.1.0",
40
40
  "tslib": "^2.3.0",
41
- "@module-federation/enhanced": "0.6.9",
42
- "@nx/devkit": "0.0.0-pr-28808-8717441",
43
- "@nx/js": "0.0.0-pr-28808-8717441",
44
- "@nx/eslint": "0.0.0-pr-28808-8717441",
45
- "@nx/web": "0.0.0-pr-28808-8717441",
46
- "@nx/module-federation": "0.0.0-pr-28808-8717441",
41
+ "@nx/devkit": "0.0.0-pr-28808-eac89e6",
42
+ "@nx/js": "0.0.0-pr-28808-eac89e6",
43
+ "@nx/eslint": "0.0.0-pr-28808-eac89e6",
44
+ "@nx/web": "0.0.0-pr-28808-eac89e6",
45
+ "@nx/module-federation": "0.0.0-pr-28808-eac89e6",
47
46
  "express": "^4.19.2",
48
47
  "http-proxy-middleware": "^3.0.3"
49
48
  },
@@ -27,7 +27,6 @@ const js_1 = require("@nx/js");
27
27
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
28
28
  const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
29
29
  const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
30
- const add_project_root_to_rspack_plugin_excludes_1 = require("./lib/add-project-root-to-rspack-plugin-excludes");
31
30
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
32
31
  async function addLinting(host, options) {
33
32
  const tasks = [];
@@ -117,6 +116,15 @@ async function applicationGeneratorInternal(host, schema) {
117
116
  tasks.push(ensureDependencies(host, { uiFramework: 'react' }));
118
117
  }
119
118
  }
119
+ else if (options.bundler === 'rspack') {
120
+ const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxVersion);
121
+ const rspackInitTask = await rspackInitGenerator(host, {
122
+ ...options,
123
+ addPlugin: false,
124
+ skipFormat: true,
125
+ });
126
+ tasks.push(rspackInitTask);
127
+ }
120
128
  if (!options.rootProject) {
121
129
  (0, create_ts_config_1.extractTsConfigBase)(host);
122
130
  }
@@ -179,7 +187,6 @@ async function applicationGeneratorInternal(host, schema) {
179
187
  framework: 'react',
180
188
  });
181
189
  tasks.push(rspackTask);
182
- (0, add_project_root_to_rspack_plugin_excludes_1.addProjectRootToRspackPluginExcludesIfExists)(host, options.appProjectRoot);
183
190
  }
184
191
  if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
185
192
  const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
@@ -0,0 +1,53 @@
1
+ <%_ if (rspackPluginOptions) { _%>
2
+ const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
3
+ const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
4
+ const { join } = require('path');
5
+
6
+ module.exports = {
7
+ output: {
8
+ path: join(__dirname, '<%= offsetFromRoot %><%= rspackPluginOptions.outputPath %>'),
9
+ },
10
+ devServer: {
11
+ port: 4200,
12
+ historyApiFallback: {
13
+ index: '/index.html',
14
+ disableDotRule: true,
15
+ htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
16
+ },
17
+ },
18
+ plugins: [
19
+ new NxAppRspackPlugin({
20
+ tsConfig: '<%= rspackPluginOptions.tsConfig %>',
21
+ main: '<%= rspackPluginOptions.main %>',
22
+ index: '<%= rspackPluginOptions.index %>',
23
+ baseHref: '<%= rspackPluginOptions.baseHref %>',
24
+ assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
25
+ styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
26
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
27
+ optimization: process.env['NODE_ENV'] === 'production',
28
+ }),
29
+ new NxReactRspackPlugin({
30
+ // Uncomment this line if you don't want to use SVGR
31
+ // See: https://react-svgr.com/
32
+ // svgr: false
33
+ }),
34
+ ],
35
+ };
36
+ <%_ } else { _%>
37
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
38
+
39
+ // Nx plugins for rspack.
40
+ module.exports = composePlugins(
41
+ withNx(),
42
+ withReact({
43
+ // Uncomment this line if you don't want to use SVGR
44
+ // See: https://react-svgr.com/
45
+ // svgr: false
46
+ }),
47
+ (config) => {
48
+ // Update the rspack config as needed here.
49
+ // e.g. `config.plugins.push(new MyPlugin())`
50
+ return config;
51
+ }
52
+ );
53
+ <%_ } _%>
@@ -6,10 +6,12 @@ const web_1 = require("@nx/web");
6
6
  const versions_1 = require("../../../utils/versions");
7
7
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
8
8
  const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
9
+ const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
9
10
  const find_plugin_for_config_file_1 = require("@nx/devkit/src/utils/find-plugin-for-config-file");
10
11
  const target_defaults_utils_1 = require("@nx/devkit/src/generators/target-defaults-utils");
11
12
  async function addE2e(tree, options) {
12
13
  const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
14
+ (options.bundler === 'rspack' && (0, has_rspack_plugin_1.hasRspackPlugin)(tree)) ||
13
15
  (options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
14
16
  let e2eWebServerInfo = {
15
17
  e2eWebServerAddress: `http://localhost:${options.devServerPort ?? 4200}`,
@@ -43,6 +45,7 @@ async function addE2e(tree, options) {
43
45
  private: true,
44
46
  nx: {
45
47
  projectType: 'application',
48
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
46
49
  implicitDependencies: [options.projectName],
47
50
  },
48
51
  });
@@ -107,7 +110,8 @@ async function addE2e(tree, options) {
107
110
  version: '0.0.1',
108
111
  private: true,
109
112
  nx: {
110
- name: options.e2eProjectName,
113
+ projectType: 'application',
114
+ sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
111
115
  implicitDependencies: [options.projectName],
112
116
  },
113
117
  });
@@ -4,6 +4,7 @@ exports.addProject = addProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
6
6
  const maybe_js_1 = require("../../../utils/maybe-js");
7
+ const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
7
8
  const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
8
9
  function addProject(host, options) {
9
10
  const project = {
@@ -21,6 +22,13 @@ function addProject(host, options) {
21
22
  };
22
23
  }
23
24
  }
25
+ else if (options.bundler === 'rspack' &&
26
+ (!(0, has_rspack_plugin_1.hasRspackPlugin)(host) || !options.addPlugin)) {
27
+ project.targets = {
28
+ build: createRspackBuildTarget(options),
29
+ serve: createRspackServeTarget(options),
30
+ };
31
+ }
24
32
  if (options.isUsingTsSolutionConfig) {
25
33
  (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
26
34
  name: (0, get_import_path_1.getImportPath)(host, options.name),
@@ -29,6 +37,7 @@ function addProject(host, options) {
29
37
  nx: {
30
38
  name: options.name,
31
39
  projectType: 'application',
40
+ sourceRoot: `${options.appProjectRoot}/src`,
32
41
  tags: options.parsedTags?.length ? options.parsedTags : undefined,
33
42
  },
34
43
  });
@@ -39,6 +48,64 @@ function addProject(host, options) {
39
48
  });
40
49
  }
41
50
  }
51
+ function createRspackBuildTarget(options) {
52
+ return {
53
+ executor: '@nx/rspack:rspack',
54
+ outputs: ['{options.outputPath}'],
55
+ defaultConfiguration: 'production',
56
+ options: {
57
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
58
+ index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
59
+ baseHref: '/',
60
+ main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
61
+ tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
62
+ assets: [
63
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
64
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/assets'),
65
+ ],
66
+ rspackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'),
67
+ styles: options.styledModule || !options.hasStyles
68
+ ? []
69
+ : [
70
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
71
+ ],
72
+ scripts: [],
73
+ configurations: {
74
+ development: {
75
+ mode: 'development',
76
+ },
77
+ production: {
78
+ mode: 'production',
79
+ optimization: true,
80
+ sourceMap: false,
81
+ outputHashing: 'all',
82
+ namedChunks: false,
83
+ extractLicenses: true,
84
+ vendorChunk: false,
85
+ },
86
+ },
87
+ },
88
+ };
89
+ }
90
+ function createRspackServeTarget(options) {
91
+ return {
92
+ executor: '@nx/rspack:dev-server',
93
+ defaultConfiguration: 'development',
94
+ options: {
95
+ buildTarget: `${options.projectName}:build`,
96
+ hmr: true,
97
+ },
98
+ configurations: {
99
+ development: {
100
+ buildTarget: `${options.projectName}:build:development`,
101
+ },
102
+ production: {
103
+ buildTarget: `${options.projectName}:build:production`,
104
+ hmr: false,
105
+ },
106
+ },
107
+ };
108
+ }
42
109
  function createBuildTarget(options) {
43
110
  return {
44
111
  executor: '@nx/webpack:webpack',
@@ -10,6 +10,7 @@ const maybe_js_1 = require("../../../utils/maybe-js");
10
10
  const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
11
11
  const get_app_tests_1 = require("./get-app-tests");
12
12
  const onboarding_1 = require("nx/src/nx-cloud/utilities/onboarding");
13
+ const has_rspack_plugin_1 = require("../../../utils/has-rspack-plugin");
13
14
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
14
15
  async function createApplicationFiles(host, options) {
15
16
  let styleSolutionSpecificAppFiles;
@@ -116,7 +117,12 @@ async function createApplicationFiles(host, options) {
116
117
  }
117
118
  }
118
119
  else if (options.bundler === 'rspack') {
119
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot, templateVariables);
120
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot, {
121
+ ...templateVariables,
122
+ rspackPluginOptions: (0, has_rspack_plugin_1.hasRspackPlugin)(host)
123
+ ? createNxRspackPluginOptions(options)
124
+ : null,
125
+ });
120
126
  }
121
127
  if (options.unitTestRunner === 'none' ||
122
128
  (options.unitTestRunner === 'vitest' && options.inSourceTests == true)) {
@@ -158,3 +164,24 @@ function createNxWebpackPluginOptions(options) {
158
164
  ],
159
165
  };
160
166
  }
167
+ function createNxRspackPluginOptions(options) {
168
+ return {
169
+ target: 'web',
170
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
171
+ ? options.appProjectRoot
172
+ : options.projectName),
173
+ index: './src/index.html',
174
+ baseHref: '/',
175
+ main: (0, maybe_js_1.maybeJs)({
176
+ js: options.js,
177
+ useJsx: true,
178
+ }, `./src/main.tsx`),
179
+ tsConfig: './tsconfig.app.json',
180
+ assets: ['./src/favicon.ico', './src/assets'],
181
+ styles: options.styledModule || !options.hasStyles
182
+ ? []
183
+ : [
184
+ `./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
185
+ ],
186
+ };
187
+ }
@@ -1,5 +1,5 @@
1
1
  const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
- const { withModuleFederation } = require('@nx/rspack/module-federation');
2
+ const { withModuleFederation } = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require('./module-federation.config');
5
5
 
@@ -1,5 +1,5 @@
1
1
  const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
- const { withModuleFederation } = require('@nx/rspack/module-federation');
2
+ const { withModuleFederation } = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require('./module-federation.config');
5
5
 
@@ -1,5 +1,5 @@
1
1
  const {composePlugins, withNx, withReact} = require('@nx/rspack');
2
- const {withModuleFederationForSSR} = require('@nx/rspack/module-federation');
2
+ const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require('./module-federation.config');
5
5
 
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederationForSSR} from '@nx/rspack/module-federation';
2
+ import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
3
3
 
4
4
  import baseConfig from './module-federation.config';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { composePlugins, withNx, withReact } from '@nx/rspack';
2
- import { withModuleFederation } from '@nx/rspack/module-federation';
2
+ import { withModuleFederation } from '@nx/module-federation/rspack';
3
3
  import { ModuleFederationConfig } from '@nx/module-federation';
4
4
 
5
5
  import baseConfig from './module-federation.config';
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import { withModuleFederation } from '@nx/rspack/module-federation';
2
+ import { withModuleFederation } from '@nx/module-federation/rspack';
3
3
  import { ModuleFederationConfig } from '@nx/module-federation';
4
4
 
5
5
  import baseConfig from './module-federation.config';
@@ -1,6 +1,6 @@
1
1
  const { composePlugins, withNx } = require('@nx/webpack');
2
2
  const { withReact } = require('@nx/react');
3
- const { withModuleFederation } = require('@nx/react/module-federation');
3
+ const { withModuleFederation } = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require('./module-federation.config');
6
6
 
@@ -1,6 +1,6 @@
1
1
  const { composePlugins, withNx } = require('@nx/webpack');
2
2
  const { withReact } = require('@nx/react');
3
- const { withModuleFederation } = require('@nx/react/module-federation');
3
+ const { withModuleFederation } = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require('./module-federation.config');
6
6
 
@@ -1,6 +1,6 @@
1
1
  const {composePlugins, withNx} = require('@nx/webpack');
2
2
  const {withReact} = require('@nx/react');
3
- const {withModuleFederationForSSR} = require('@nx/react/module-federation');
3
+ const {withModuleFederationForSSR} = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require('./module-federation.config');
6
6
 
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederationForSSR} from '@nx/react/module-federation';
3
+ import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
4
4
 
5
5
  import baseConfig from './module-federation.config';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { composePlugins, withNx } from '@nx/webpack';
2
2
  import { withReact } from '@nx/react';
3
- import { withModuleFederation } from '@nx/react/module-federation';
3
+ import { withModuleFederation } from '@nx/module-federation/webpack';
4
4
  import { ModuleFederationConfig } from '@nx/module-federation';
5
5
 
6
6
  import baseConfig from './module-federation.config';
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederation} from '@nx/react/module-federation';
3
+ import {withModuleFederation} from '@nx/module-federation/webpack';
4
4
  import { ModuleFederationConfig } from '@nx/module-federation';
5
5
 
6
6
  import baseConfig from './module-federation.config';
@@ -52,6 +52,7 @@ async function libraryGeneratorInternal(host, schema) {
52
52
  nx: {
53
53
  name: options.importPath === options.name ? undefined : options.name,
54
54
  projectType: 'library',
55
+ sourceRoot: `${options.projectRoot}/src`,
55
56
  tags: options.parsedTags?.length ? options.parsedTags : undefined,
56
57
  },
57
58
  });
@@ -1,5 +1,5 @@
1
1
  const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
- const { withModuleFederation } = require('@nx/rspack/module-federation');
2
+ const { withModuleFederation } = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require('./module-federation.config');
5
5
 
@@ -1,5 +1,5 @@
1
1
  const {composePlugins, withNx, withReact} = require('@nx/rspack');
2
- const {withModuleFederationForSSR} = require('@nx/rspack/module-federation');
2
+ const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
3
3
 
4
4
  const baseConfig = require("./module-federation.server.config");
5
5
 
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederationForSSR} from '@nx/rspack/module-federation';
2
+ import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
3
3
 
4
4
  import baseConfig from "./module-federation.server.config";
5
5
 
@@ -1,5 +1,5 @@
1
1
  import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederation} from '@nx/rspack/module-federation';
2
+ import {withModuleFederation} from '@nx/module-federation/rspack';
3
3
 
4
4
  import baseConfig from './module-federation.config';
5
5
 
@@ -1,6 +1,6 @@
1
1
  const { composePlugins, withNx } = require('@nx/webpack');
2
2
  const { withReact } = require('@nx/react');
3
- const { withModuleFederation } = require('@nx/react/module-federation');
3
+ const { withModuleFederation } = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require('./module-federation.config');
6
6
 
@@ -1,6 +1,6 @@
1
1
  const {composePlugins, withNx} = require('@nx/webpack');
2
2
  const {withReact} = require('@nx/react');
3
- const {withModuleFederationForSSR} = require('@nx/react/module-federation');
3
+ const {withModuleFederationForSSR} = require('@nx/module-federation/webpack');
4
4
 
5
5
  const baseConfig = require("./module-federation.server.config");
6
6
 
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederationForSSR} from '@nx/react/module-federation';
3
+ import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
4
4
 
5
5
  import baseConfig from "./module-federation.server.config";
6
6
 
@@ -1,6 +1,6 @@
1
1
  import {composePlugins, withNx} from '@nx/webpack';
2
2
  import {withReact} from '@nx/react';
3
- import {withModuleFederation} from '@nx/react/module-federation';
3
+ import {withModuleFederation} from '@nx/module-federation/webpack';
4
4
 
5
5
  import baseConfig from './module-federation.config';
6
6
 
@@ -0,0 +1,2 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function migrateWithMfImport(tree: Tree): Promise<void>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = migrateWithMfImport;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const executor_options_utils_1 = require("@nx/devkit/src/generators/executor-options-utils");
6
+ const tsquery_1 = require("@phenomnomnominal/tsquery");
7
+ const NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR = 'ImportDeclaration > StringLiteral[value=@nx/react/module-federation], VariableStatement CallExpression:has(Identifier[name=require]) > StringLiteral[value=@nx/react/module-federation]';
8
+ const NEW_IMPORT_PATH = `'@nx/module-federation/webpack'`;
9
+ async function migrateWithMfImport(tree) {
10
+ const projects = new Set();
11
+ (0, executor_options_utils_1.forEachExecutorOptions)(tree, '@nx/react:module-federation-dev-server', (options, project, target) => {
12
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, project);
13
+ projects.add(projectConfig.root);
14
+ });
15
+ for (const projectRoot of projects) {
16
+ (0, devkit_1.visitNotIgnoredFiles)(tree, projectRoot, (filePath) => {
17
+ if (!filePath.endsWith('.ts') && !filePath.endsWith('.js')) {
18
+ return;
19
+ }
20
+ let contents = tree.read(filePath, 'utf-8');
21
+ if (!contents.includes('@nx/react/module-federation')) {
22
+ return;
23
+ }
24
+ const ast = tsquery_1.tsquery.ast(contents);
25
+ const importNodes = (0, tsquery_1.tsquery)(ast, NX_RSPACK_MODULE_FEDERATION_IMPORT_SELECTOR);
26
+ if (importNodes.length === 0) {
27
+ return;
28
+ }
29
+ const importPathNode = importNodes[0];
30
+ contents = `${contents.slice(0, importPathNode.getStart())}${NEW_IMPORT_PATH}${contents.slice(importPathNode.getEnd())}`;
31
+ tree.write(filePath, contents);
32
+ });
33
+ }
34
+ await (0, devkit_1.formatFiles)(tree);
35
+ }
@@ -9,24 +9,26 @@ function updateModuleFederationProject(host, options) {
9
9
  if (options.bundler === 'rspack') {
10
10
  projectConfig.targets.build.executor = '@nx/rspack:rspack';
11
11
  projectConfig.targets.build.options = {
12
- ...projectConfig.targets.build.options,
12
+ ...(projectConfig.targets.build.options ?? {}),
13
13
  main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
14
14
  rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
15
15
  target: 'web',
16
16
  };
17
+ projectConfig.targets.build.configurations ??= {};
17
18
  projectConfig.targets.build.configurations.production = {
18
- ...projectConfig.targets.build.configurations.production,
19
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
19
20
  rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
20
21
  };
21
22
  }
22
23
  else {
23
24
  projectConfig.targets.build.options = {
24
- ...projectConfig.targets.build.options,
25
+ ...(projectConfig.targets.build.options ?? {}),
25
26
  main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
26
27
  webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
27
28
  };
29
+ projectConfig.targets.build.configurations ??= {};
28
30
  projectConfig.targets.build.configurations.production = {
29
- ...projectConfig.targets.build.configurations.production,
31
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
30
32
  webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
31
33
  };
32
34
  }
@@ -1,4 +1,4 @@
1
- import type { StaticRemotesConfig } from '@nx/webpack/src/utils/module-federation/parse-static-remotes-config';
1
+ import { StaticRemotesConfig } from '@nx/module-federation/src/utils';
2
2
  import { ExecutorContext } from '@nx/devkit';
3
3
  import { ModuleFederationDevServerOptions } from '../executors/module-federation-dev-server/schema';
4
4
  export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
@@ -0,0 +1,2 @@
1
+ import { Tree } from '@nx/devkit';
2
+ export declare function hasRspackPlugin(tree: Tree): boolean;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasRspackPlugin = hasRspackPlugin;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function hasRspackPlugin(tree) {
6
+ const nxJson = (0, devkit_1.readNxJson)(tree);
7
+ return !!nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/rspack/plugin'
9
+ : p.plugin === '@nx/rspack/plugin');
10
+ }
@@ -35,8 +35,8 @@ export declare const typesExpressVersion = "4.17.17";
35
35
  export declare const isbotVersion = "^3.6.5";
36
36
  export declare const corsVersion = "~2.8.5";
37
37
  export declare const typesCorsVersion = "~2.8.12";
38
- export declare const moduleFederationNodeVersion = "~2.5.0";
39
- export declare const moduleFederationEnhancedVersion = "0.6.9";
38
+ export declare const moduleFederationNodeVersion = "~2.6.11";
39
+ export declare const moduleFederationEnhancedVersion = "0.7.6";
40
40
  export declare const lessVersion = "3.12.2";
41
41
  export declare const sassVersion = "^1.55.0";
42
42
  export declare const rollupPluginUrlVersion = "^8.0.2";
@@ -40,8 +40,8 @@ exports.typesExpressVersion = '4.17.17';
40
40
  exports.isbotVersion = '^3.6.5';
41
41
  exports.corsVersion = '~2.8.5';
42
42
  exports.typesCorsVersion = '~2.8.12';
43
- exports.moduleFederationNodeVersion = '~2.5.0';
44
- exports.moduleFederationEnhancedVersion = '0.6.9';
43
+ exports.moduleFederationNodeVersion = '~2.6.11';
44
+ exports.moduleFederationEnhancedVersion = '0.7.6';
45
45
  // style preprocessors
46
46
  exports.lessVersion = '3.12.2';
47
47
  exports.sassVersion = '^1.55.0';
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function addProjectRootToRspackPluginExcludesIfExists(tree: Tree, projectRoot: string): void;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addProjectRootToRspackPluginExcludesIfExists = addProjectRootToRspackPluginExcludesIfExists;
4
- const devkit_1 = require("@nx/devkit");
5
- const devkit_2 = require("@nx/devkit");
6
- function addProjectRootToRspackPluginExcludesIfExists(tree, projectRoot) {
7
- const excludeProjectGlob = (0, devkit_1.joinPathFragments)(projectRoot, '/**');
8
- const nxJson = (0, devkit_2.readNxJson)(tree);
9
- if (!nxJson.plugins?.length) {
10
- return;
11
- }
12
- for (let i = 0; i < nxJson.plugins.length; i++) {
13
- let plugin = nxJson.plugins[i];
14
- const isRspackPlugin = typeof plugin === 'string'
15
- ? plugin === '@nx/rspack/plugin'
16
- : plugin.plugin === '@nx/rspack/plugin';
17
- if (isRspackPlugin) {
18
- if (typeof plugin === 'string') {
19
- plugin = {
20
- plugin: plugin,
21
- exclude: [excludeProjectGlob],
22
- };
23
- }
24
- else {
25
- plugin.exclude = [...(plugin.exclude ?? []), excludeProjectGlob];
26
- }
27
- nxJson.plugins[i] = plugin;
28
- }
29
- }
30
- (0, devkit_1.updateNxJson)(tree, nxJson);
31
- }
@@ -1,12 +0,0 @@
1
- import { ModuleFederationConfig } from '@nx/module-federation';
2
- export declare function getFunctionDeterminateRemoteUrl(isServer?: boolean): (remote: string) => string;
3
- export declare function getModuleFederationConfig(mfConfig: ModuleFederationConfig, options?: {
4
- isServer: boolean;
5
- determineRemoteUrl?: (remote: string) => string;
6
- }): Promise<{
7
- sharedLibraries: import("@nx/module-federation").SharedWorkspaceLibraryConfig;
8
- sharedDependencies: {
9
- [x: string]: import("@nx/module-federation").SharedLibraryConfig;
10
- };
11
- mappedRemotes: {};
12
- }>;
@@ -1,75 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFunctionDeterminateRemoteUrl = getFunctionDeterminateRemoteUrl;
4
- exports.getModuleFederationConfig = getModuleFederationConfig;
5
- const module_federation_1 = require("@nx/module-federation");
6
- const devkit_1 = require("@nx/devkit");
7
- const project_graph_1 = require("nx/src/project-graph/project-graph");
8
- function getFunctionDeterminateRemoteUrl(isServer = false) {
9
- const target = 'serve';
10
- const remoteEntry = isServer ? 'server/remoteEntry.js' : 'remoteEntry.js';
11
- return function (remote) {
12
- const mappedStaticRemotesFromEnv = process.env
13
- .NX_MF_DEV_SERVER_STATIC_REMOTES
14
- ? JSON.parse(process.env.NX_MF_DEV_SERVER_STATIC_REMOTES)
15
- : undefined;
16
- if (mappedStaticRemotesFromEnv && mappedStaticRemotesFromEnv[remote]) {
17
- return `${mappedStaticRemotesFromEnv[remote]}/${remoteEntry}`;
18
- }
19
- let remoteConfiguration = null;
20
- try {
21
- remoteConfiguration = (0, project_graph_1.readCachedProjectConfiguration)(remote);
22
- }
23
- catch (e) {
24
- throw new Error(`Cannot find remote: "${remote}". Check that the remote name is correct in your module federation config file.\n`);
25
- }
26
- const serveTarget = remoteConfiguration?.targets?.[target];
27
- if (!serveTarget) {
28
- throw new Error(`Cannot automatically determine URL of remote (${remote}). Looked for property "host" in the project's "${serveTarget}" target.\n
29
- You can also use the tuple syntax in your webpack config to configure your remotes. e.g. \`remotes: [['remote1', 'http://localhost:4201']]\``);
30
- }
31
- const host = serveTarget.options?.host ??
32
- `http${serveTarget.options.ssl ? 's' : ''}://localhost`;
33
- const port = serveTarget.options?.port ?? 4201;
34
- return `${host.endsWith('/') ? host.slice(0, -1) : host}:${port}/${remoteEntry}`;
35
- };
36
- }
37
- async function getModuleFederationConfig(mfConfig, options = { isServer: false }) {
38
- let projectGraph;
39
- try {
40
- projectGraph = (0, devkit_1.readCachedProjectGraph)();
41
- }
42
- catch (e) {
43
- projectGraph = await (0, devkit_1.createProjectGraphAsync)();
44
- }
45
- const project = projectGraph.nodes[mfConfig.name]?.data;
46
- if (!project) {
47
- throw Error(`Cannot find project "${mfConfig.name}". Check that the name is correct in module-federation.config.js`);
48
- }
49
- const dependencies = (0, module_federation_1.getDependentPackagesForProject)(projectGraph, mfConfig.name);
50
- if (mfConfig.shared) {
51
- dependencies.workspaceLibraries = dependencies.workspaceLibraries.filter((lib) => mfConfig.shared(lib.importKey, {}) !== false);
52
- dependencies.npmPackages = dependencies.npmPackages.filter((pkg) => mfConfig.shared(pkg, {}) !== false);
53
- }
54
- const sharedLibraries = (0, module_federation_1.shareWorkspaceLibraries)(dependencies.workspaceLibraries);
55
- const npmPackages = (0, module_federation_1.sharePackages)(dependencies.npmPackages);
56
- const sharedDependencies = {
57
- ...sharedLibraries.getLibraries(project.root),
58
- ...npmPackages,
59
- };
60
- (0, module_federation_1.applySharedFunction)(sharedDependencies, mfConfig.shared);
61
- (0, module_federation_1.applyAdditionalShared)(sharedDependencies, mfConfig.additionalShared, projectGraph);
62
- // Choose the correct mapRemotes function based on the server state.
63
- const mapRemotesFunction = options.isServer ? module_federation_1.mapRemotesForSSR : module_federation_1.mapRemotes;
64
- // Determine the URL function, either from provided options or by using a default.
65
- const determineRemoteUrlFunction = options.determineRemoteUrl
66
- ? options.determineRemoteUrl
67
- : getFunctionDeterminateRemoteUrl(options.isServer);
68
- // Map the remotes if they exist, otherwise default to an empty object.
69
- let mappedRemotes = {};
70
- if (mfConfig.remotes && mfConfig.remotes.length > 0) {
71
- const isLibraryTypeVar = mfConfig.library?.type === 'var';
72
- mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction, true);
73
- }
74
- return { sharedLibraries, sharedDependencies, mappedRemotes };
75
- }
@@ -1,2 +0,0 @@
1
- import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
2
- export declare function withModuleFederationForSSR(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<(config: any) => any>;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withModuleFederationForSSR = withModuleFederationForSSR;
4
- const utils_1 = require("./utils");
5
- async function withModuleFederationForSSR(options, configOverride) {
6
- if (global.NX_GRAPH_CREATION) {
7
- return (config) => config;
8
- }
9
- const { sharedLibraries, sharedDependencies, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options, {
10
- isServer: true,
11
- });
12
- return (config) => {
13
- config.target = 'async-node';
14
- config.output.uniqueName = options.name;
15
- config.optimization = {
16
- ...(config.optimization ?? {}),
17
- runtimeChunk: false,
18
- };
19
- config.plugins.push(new (require('@module-federation/enhanced').ModuleFederationPlugin)({
20
- name: options.name.replace(/-/g, '_'),
21
- filename: 'remoteEntry.js',
22
- exposes: options.exposes,
23
- remotes: mappedRemotes,
24
- shared: {
25
- ...sharedDependencies,
26
- },
27
- /**
28
- * Apply user-defined config overrides
29
- */
30
- ...(configOverride ? configOverride : {}),
31
- runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
32
- !options.disableNxRuntimeLibraryControlPlugin
33
- ? [
34
- ...(configOverride?.runtimePlugins ?? []),
35
- require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
36
- ]
37
- : [
38
- ...(configOverride?.runtimePlugins ?? []),
39
- require.resolve('@module-federation/node/runtimePlugin'),
40
- ],
41
- virtualRuntimeEntry: true,
42
- }, {}), sharedLibraries.getReplacementPlugin());
43
- // The env var is only set from the module-federation-dev-server
44
- // Attach the runtime plugin
45
- config.plugins.push(new (require('webpack').DefinePlugin)({
46
- 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
47
- }));
48
- return config;
49
- };
50
- }
@@ -1,7 +0,0 @@
1
- import { ModuleFederationConfig, NxModuleFederationConfigOverride } from '@nx/module-federation';
2
- import type { AsyncNxComposableWebpackPlugin } from '@nx/webpack';
3
- /**
4
- * @param {ModuleFederationConfig} options
5
- * @return {Promise<AsyncNxComposableWebpackPlugin>}
6
- */
7
- export declare function withModuleFederation(options: ModuleFederationConfig, configOverride?: NxModuleFederationConfigOverride): Promise<AsyncNxComposableWebpackPlugin>;
@@ -1,63 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.withModuleFederation = withModuleFederation;
4
- const utils_1 = require("./utils");
5
- const webpack_1 = require("@module-federation/enhanced/webpack");
6
- /**
7
- * @param {ModuleFederationConfig} options
8
- * @return {Promise<AsyncNxComposableWebpackPlugin>}
9
- */
10
- async function withModuleFederation(options, configOverride) {
11
- if (global.NX_GRAPH_CREATION) {
12
- return (config) => config;
13
- }
14
- const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
15
- return (config, ctx) => {
16
- config.output.uniqueName = options.name;
17
- config.output.publicPath = 'auto';
18
- config.output.scriptType = 'text/javascript';
19
- config.optimization = {
20
- ...(config.optimization ?? {}),
21
- runtimeChunk: false,
22
- };
23
- if (config.mode === 'development' &&
24
- Object.keys(mappedRemotes).length > 1 &&
25
- !options.exposes) {
26
- config.optimization.runtimeChunk = 'single';
27
- }
28
- config.plugins.push(new webpack_1.ModuleFederationPlugin({
29
- name: options.name.replace(/-/g, '_'),
30
- filename: 'remoteEntry.js',
31
- exposes: options.exposes,
32
- remotes: mappedRemotes,
33
- shared: {
34
- ...sharedDependencies,
35
- },
36
- /**
37
- * remoteType: 'script' is required for the remote to be loaded as a script tag.
38
- * remotes will need to be defined as:
39
- * { appX: 'appX@http://localhost:3001/remoteEntry.js' }
40
- * { appY: 'appY@http://localhost:3002/remoteEntry.js' }
41
- */
42
- remoteType: 'script',
43
- /**
44
- * Apply user-defined config overrides
45
- */
46
- ...(configOverride ? configOverride : {}),
47
- runtimePlugins: process.env.NX_MF_DEV_REMOTES &&
48
- !options.disableNxRuntimeLibraryControlPlugin
49
- ? [
50
- ...(configOverride?.runtimePlugins ?? []),
51
- require.resolve('@nx/module-federation/src/utils/plugins/runtime-library-control.plugin.js'),
52
- ]
53
- : configOverride?.runtimePlugins,
54
- virtualRuntimeEntry: true,
55
- }), sharedLibraries.getReplacementPlugin());
56
- // The env var is only set from the module-federation-dev-server
57
- // Attach the runtime plugin
58
- config.plugins.push(new (require('webpack').DefinePlugin)({
59
- 'process.env.NX_MF_DEV_REMOTES': process.env.NX_MF_DEV_REMOTES,
60
- }));
61
- return config;
62
- };
63
- }