@nx/react 20.2.0-canary.20241122-a1efb63 → 20.2.0-canary.20241123-128778e

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 (43) hide show
  1. package/migrations.json +6 -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 -18
  6. package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
  7. package/src/generators/application/lib/add-e2e.js +2 -0
  8. package/src/generators/application/lib/add-project.js +66 -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/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +1 -1
  23. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  24. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  25. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  26. package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
  27. package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  28. package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  29. package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  30. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
  31. package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +35 -0
  32. package/src/rules/update-module-federation-project.js +6 -4
  33. package/src/utils/build-static.remotes.d.ts +1 -1
  34. package/src/utils/has-rspack-plugin.d.ts +2 -0
  35. package/src/utils/has-rspack-plugin.js +10 -0
  36. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.d.ts +0 -2
  37. package/src/generators/application/lib/add-project-root-to-rspack-plugin-excludes.js +0 -31
  38. package/src/module-federation/utils.d.ts +0 -12
  39. package/src/module-federation/utils.js +0 -75
  40. package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
  41. package/src/module-federation/with-module-federation-ssr.js +0 -50
  42. package/src/module-federation/with-module-federation.d.ts +0 -7
  43. 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": {
@@ -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": "20.2.0-canary.20241122-a1efb63",
3
+ "version": "20.2.0-canary.20241123-128778e",
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.7.6",
42
- "@nx/devkit": "20.2.0-canary.20241122-a1efb63",
43
- "@nx/js": "20.2.0-canary.20241122-a1efb63",
44
- "@nx/eslint": "20.2.0-canary.20241122-a1efb63",
45
- "@nx/web": "20.2.0-canary.20241122-a1efb63",
46
- "@nx/module-federation": "20.2.0-canary.20241122-a1efb63",
41
+ "@nx/devkit": "20.2.0-canary.20241123-128778e",
42
+ "@nx/js": "20.2.0-canary.20241123-128778e",
43
+ "@nx/eslint": "20.2.0-canary.20241123-128778e",
44
+ "@nx/web": "20.2.0-canary.20241123-128778e",
45
+ "@nx/module-federation": "20.2.0-canary.20241123-128778e",
47
46
  "express": "^4.19.2",
48
47
  "http-proxy-middleware": "^3.0.3"
49
48
  },
@@ -15,7 +15,6 @@ const devkit_1 = require("@nx/devkit");
15
15
  const init_1 = require("../init/init");
16
16
  const eslint_1 = require("@nx/eslint");
17
17
  const versions_1 = require("../../utils/versions");
18
- const maybe_js_1 = require("../../utils/maybe-js");
19
18
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
20
19
  const create_ts_config_1 = require("../../utils/create-ts-config");
21
20
  const add_swc_dependencies_1 = require("@nx/js/src/utils/swc/add-swc-dependencies");
@@ -28,7 +27,6 @@ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-projec
28
27
  const setup_tailwind_1 = require("../setup-tailwind/setup-tailwind");
29
28
  const flat_config_1 = require("@nx/eslint/src/utils/flat-config");
30
29
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
31
- const add_project_root_to_rspack_plugin_excludes_1 = require("./lib/add-project-root-to-rspack-plugin-excludes");
32
30
  async function addLinting(host, options) {
33
31
  const tasks = [];
34
32
  if (options.linter === eslint_1.Linter.EsLint) {
@@ -116,6 +114,15 @@ async function applicationGeneratorInternal(host, schema) {
116
114
  tasks.push(ensureDependencies(host, { uiFramework: 'react' }));
117
115
  }
118
116
  }
117
+ else if (options.bundler === 'rspack') {
118
+ const { rspackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
119
+ const rspackInitTask = await rspackInitGenerator(host, {
120
+ ...options,
121
+ addPlugin: false,
122
+ skipFormat: true,
123
+ });
124
+ tasks.push(rspackInitTask);
125
+ }
119
126
  if (!options.rootProject) {
120
127
  (0, create_ts_config_1.extractTsConfigBase)(host);
121
128
  }
@@ -163,22 +170,6 @@ async function applicationGeneratorInternal(host, schema) {
163
170
  plugins: ['react()'],
164
171
  }, false);
165
172
  }
166
- else if (options.bundler === 'rspack') {
167
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
168
- const rspackTask = await configurationGenerator(host, {
169
- project: options.projectName,
170
- main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
171
- js: options.js,
172
- useJsx: true,
173
- }, `src/main.tsx`)),
174
- tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
175
- target: 'web',
176
- newProject: true,
177
- framework: 'react',
178
- });
179
- tasks.push(rspackTask);
180
- (0, add_project_root_to_rspack_plugin_excludes_1.addProjectRootToRspackPluginExcludesIfExists)(host, options.appProjectRoot);
181
- }
182
173
  if (options.bundler !== 'vite' && options.unitTestRunner === 'vitest') {
183
174
  const { createOrEditViteConfig, vitestGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
184
175
  const vitestTask = await vitestGenerator(host, {
@@ -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}`,
@@ -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
  function addProject(host, options) {
8
9
  const project = {
9
10
  root: options.appProjectRoot,
@@ -20,10 +21,75 @@ function addProject(host, options) {
20
21
  };
21
22
  }
22
23
  }
24
+ else if (options.bundler === 'rspack' &&
25
+ (!(0, has_rspack_plugin_1.hasRspackPlugin)(host) || !options.addPlugin)) {
26
+ project.targets = {
27
+ build: createRspackBuildTarget(options),
28
+ serve: createRspackServeTarget(options),
29
+ };
30
+ }
23
31
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
24
32
  ...project,
25
33
  });
26
34
  }
35
+ function createRspackBuildTarget(options) {
36
+ return {
37
+ executor: '@nx/rspack:rspack',
38
+ outputs: ['{options.outputPath}'],
39
+ defaultConfiguration: 'production',
40
+ options: {
41
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot),
42
+ index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
43
+ baseHref: '/',
44
+ main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
45
+ tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
46
+ assets: [
47
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
48
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/assets'),
49
+ ],
50
+ rspackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'rspack.config.js'),
51
+ styles: options.styledModule || !options.hasStyles
52
+ ? []
53
+ : [
54
+ (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
55
+ ],
56
+ scripts: [],
57
+ configurations: {
58
+ development: {
59
+ mode: 'development',
60
+ },
61
+ production: {
62
+ mode: 'production',
63
+ optimization: true,
64
+ sourceMap: false,
65
+ outputHashing: 'all',
66
+ namedChunks: false,
67
+ extractLicenses: true,
68
+ vendorChunk: false,
69
+ },
70
+ },
71
+ },
72
+ };
73
+ }
74
+ function createRspackServeTarget(options) {
75
+ return {
76
+ executor: '@nx/rspack:dev-server',
77
+ defaultConfiguration: 'development',
78
+ options: {
79
+ buildTarget: `${options.projectName}:build`,
80
+ hmr: true,
81
+ },
82
+ configurations: {
83
+ development: {
84
+ buildTarget: `${options.projectName}:build:development`,
85
+ },
86
+ production: {
87
+ buildTarget: `${options.projectName}:build:production`,
88
+ hmr: false,
89
+ },
90
+ },
91
+ };
92
+ }
27
93
  function createBuildTarget(options) {
28
94
  return {
29
95
  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
  async function createApplicationFiles(host, options) {
14
15
  let styleSolutionSpecificAppFiles;
15
16
  if (options.styledModule && options.style !== 'styled-jsx') {
@@ -114,7 +115,12 @@ async function createApplicationFiles(host, options) {
114
115
  }
115
116
  }
116
117
  else if (options.bundler === 'rspack') {
117
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot, templateVariables);
118
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-rspack'), options.appProjectRoot, {
119
+ ...templateVariables,
120
+ rspackPluginOptions: (0, has_rspack_plugin_1.hasRspackPlugin)(host)
121
+ ? createNxRspackPluginOptions(options)
122
+ : null,
123
+ });
118
124
  }
119
125
  if (options.unitTestRunner === 'none' ||
120
126
  (options.unitTestRunner === 'vitest' && options.inSourceTests == true)) {
@@ -156,3 +162,24 @@ function createNxWebpackPluginOptions(options) {
156
162
  ],
157
163
  };
158
164
  }
165
+ function createNxRspackPluginOptions(options) {
166
+ return {
167
+ target: 'web',
168
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
169
+ ? options.appProjectRoot
170
+ : options.projectName),
171
+ index: './src/index.html',
172
+ baseHref: '/',
173
+ main: (0, maybe_js_1.maybeJs)({
174
+ js: options.js,
175
+ useJsx: true,
176
+ }, `./src/main.tsx`),
177
+ tsConfig: './tsconfig.app.json',
178
+ assets: ['./src/favicon.ico', './src/assets'],
179
+ styles: options.styledModule || !options.hasStyles
180
+ ? []
181
+ : [
182
+ `./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
183
+ ],
184
+ };
185
+ }
@@ -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';
@@ -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
+ }
@@ -8,24 +8,26 @@ function updateModuleFederationProject(host, options) {
8
8
  if (options.bundler === 'rspack') {
9
9
  projectConfig.targets.build.executor = '@nx/rspack:rspack';
10
10
  projectConfig.targets.build.options = {
11
- ...projectConfig.targets.build.options,
11
+ ...(projectConfig.targets.build.options ?? {}),
12
12
  main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
13
13
  rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
14
14
  target: 'web',
15
15
  };
16
+ projectConfig.targets.build.configurations ??= {};
16
17
  projectConfig.targets.build.configurations.production = {
17
- ...projectConfig.targets.build.configurations.production,
18
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
18
19
  rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
19
20
  };
20
21
  }
21
22
  else {
22
23
  projectConfig.targets.build.options = {
23
- ...projectConfig.targets.build.options,
24
+ ...(projectConfig.targets.build.options ?? {}),
24
25
  main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
25
26
  webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
26
27
  };
28
+ projectConfig.targets.build.configurations ??= {};
27
29
  projectConfig.targets.build.configurations.production = {
28
- ...projectConfig.targets.build.configurations.production,
30
+ ...(projectConfig.targets.build.configurations?.production ?? {}),
29
31
  webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
30
32
  };
31
33
  }
@@ -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
+ }
@@ -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
- }