@nx/react 20.7.1 → 20.8.0-beta.0

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 (45) hide show
  1. package/package.json +6 -6
  2. package/src/generators/application/lib/add-e2e.js +4 -0
  3. package/src/generators/application/lib/create-application-files.d.ts +61 -0
  4. package/src/generators/application/lib/create-application-files.js +49 -44
  5. package/src/generators/component-test/component-test.js +1 -1
  6. package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
  7. package/src/generators/cypress-component-configuration/lib/add-files.js +7 -4
  8. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +37 -13
  9. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +60 -32
  10. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
  11. package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +66 -0
  12. package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
  13. package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +49 -0
  14. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -0
  15. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +66 -0
  16. package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
  17. package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +49 -0
  18. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +37 -9
  19. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +37 -14
  20. package/src/generators/host/host.js +15 -15
  21. package/src/generators/host/lib/add-module-federation-files.js +28 -12
  22. package/src/generators/host/lib/normalize-host-name.d.ts +2 -0
  23. package/src/generators/host/lib/normalize-host-name.js +12 -0
  24. package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
  25. package/src/generators/host/lib/setup-ssr-for-host.js +46 -22
  26. package/src/generators/library/library.js +14 -12
  27. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +40 -13
  28. package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
  29. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +69 -0
  30. package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
  31. package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +45 -0
  32. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -0
  33. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +69 -0
  34. package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
  35. package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +45 -0
  36. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +40 -13
  37. package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
  38. package/src/generators/remote/lib/setup-ssr-for-remote.js +37 -15
  39. package/src/generators/remote/remote.js +27 -21
  40. package/src/rules/update-module-federation-project.d.ts +2 -1
  41. package/src/rules/update-module-federation-project.js +28 -47
  42. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
  43. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
  44. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
  45. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
@@ -0,0 +1,69 @@
1
+ import { NxAppRspackPlugin } from '@nx/rspack/app-plugin';
2
+ import { NxReactRspackPlugin } from '@nx/rspack/react-plugin';
3
+ import { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } from '@nx/module-federation/rspack';
4
+ import { join } from 'path';
5
+
6
+ import browserMfConfig from './module-federation.config';
7
+ import serverMfConfig from './module-federation.server.config';
8
+
9
+ const browserRspackConfig = {
10
+ name: 'browser',
11
+ output: {
12
+ path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'browser'),
13
+ publicPath: 'auto'
14
+ },
15
+ devServer: {
16
+ port: <%= devServerPort %>,
17
+ headers: {
18
+ "Access-Control-Allow-Origin": "*"
19
+ },
20
+ historyApiFallback: {
21
+ index: '/index.html',
22
+ disableDotRule: true,
23
+ htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
24
+ },
25
+ devMiddleware: {
26
+ writeToDisk: (file: string) => !file.includes('.hot-update.'),
27
+ },
28
+ },
29
+ plugins: [
30
+ new NxAppRspackPlugin({
31
+ tsConfig: '<%= rspackPluginOptions.tsConfig %>',
32
+ main: '<%= rspackPluginOptions.main %>',
33
+ index: '<%= rspackPluginOptions.index %>',
34
+ baseHref: '<%= rspackPluginOptions.baseHref %>',
35
+ assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
36
+ styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
37
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
38
+ optimization: process.env['NODE_ENV'] === 'production',
39
+ }),
40
+ new NxReactRspackPlugin({
41
+ // Uncomment this line if you don't want to use SVGR
42
+ // See: https://react-svgr.com/
43
+ // svgr: false
44
+ }),
45
+ new NxModuleFederationPlugin({ config: browserMfConfig }, { dts: false }),
46
+ ],
47
+ };
48
+
49
+ const serverRspackConfig = {
50
+ name: 'server',
51
+ target: 'async-node',
52
+ output: {
53
+ path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
54
+ filename: 'server.js'
55
+ },
56
+ plugins: [
57
+ new NxAppRspackPlugin({
58
+ outputPath: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
59
+ outputFileName: 'server.js',
60
+ tsConfig: '<%= rspackPluginOptions.tsConfig %>',
61
+ main: '<%= rspackPluginOptions.mainServer %>',
62
+ baseHref: '<%= rspackPluginOptions.baseHref %>',
63
+ }),
64
+ new NxModuleFederationPlugin({ config: serverMfConfig, isServer: true }, { dts: false }),
65
+ new NxModuleFederationSSRDevServerPlugin({ config: serverMfConfig }),
66
+ ],
67
+ };
68
+
69
+ export default [browserRspackConfig, serverRspackConfig];
@@ -7,8 +7,8 @@ import { handleRequest } from './src/main.server';
7
7
  const port = process.env['PORT'] || <%= port %>;
8
8
  const app = express();
9
9
 
10
- const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
11
- const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
10
+ const browserDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'browser');
11
+ const serverDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'server');
12
12
  const indexPath = path.join(browserDist, 'index.html');
13
13
 
14
14
  app.use(cors());
@@ -0,0 +1,45 @@
1
+ import type { Request, Response } from 'express';
2
+ import * as fs from 'fs';
3
+ import * as ReactDOMServer from 'react-dom/server';
4
+ import isbot from 'isbot';
5
+
6
+ import App from './app/app';
7
+
8
+ let indexHtml: null | string = null;
9
+
10
+ export function handleRequest(indexPath: string) {
11
+ return function render(req: Request, res: Response) {
12
+ let didError = false;
13
+
14
+ if (!indexHtml) {
15
+ indexHtml = fs.readFileSync(indexPath).toString();
16
+ }
17
+
18
+ const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
19
+
20
+ // For bots (e.g. search engines), the content will not be streamed but render all at once.
21
+ // For users, content should be streamed to the user as they are ready.
22
+ const callbackName = isbot(req.headers['user-agent'])
23
+ ? 'onAllReady'
24
+ : 'onShellReady';
25
+
26
+ const stream = ReactDOMServer.renderToPipeableStream(<App />, {
27
+ [callbackName]() {
28
+ res.statusCode = didError ? 500 : 200;
29
+ res.setHeader('Content-type', 'text/html; charset=utf-8');
30
+ res.write(`${htmlStart}<div id="root">`);
31
+ stream.pipe(res);
32
+ res.write(`</div>${htmlEnd}`);
33
+ },
34
+ onShellError(error) {
35
+ console.error(error);
36
+ res.statusCode = 500;
37
+ res.send('<!doctype html><h1>Server Error</h1>');
38
+ },
39
+ onError(error) {
40
+ didError = true;
41
+ console.error(error);
42
+ },
43
+ });
44
+ };
45
+ }
@@ -1,16 +1,43 @@
1
- import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederation} from '@nx/module-federation/rspack';
1
+ import { NxAppRspackPlugin } from '@nx/rspack/app-plugin';
2
+ import { NxReactRspackPlugin } from '@nx/rspack/react-plugin';
3
+ import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack';
4
+ import { join } from 'path';
3
5
 
4
- import baseConfig from './module-federation.config';
6
+ import config from './module-federation.config';
5
7
 
6
- const config = {
7
- ...baseConfig,
8
+ export default {
9
+ output: {
10
+ path: join(__dirname, '<%= rspackPluginOptions.outputPath %>'),
11
+ publicPath: 'auto'
12
+ },
13
+ devServer: {
14
+ port: <%= devServerPort %>,
15
+ headers: {
16
+ "Access-Control-Allow-Origin": "*"
17
+ },
18
+ historyApiFallback: {
19
+ index: '/index.html',
20
+ disableDotRule: true,
21
+ htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
22
+ },
23
+ },
24
+ plugins: [
25
+ new NxAppRspackPlugin({
26
+ tsConfig: '<%= rspackPluginOptions.tsConfig %>',
27
+ main: '<%= rspackPluginOptions.main %>',
28
+ index: '<%= rspackPluginOptions.index %>',
29
+ baseHref: '<%= rspackPluginOptions.baseHref %>',
30
+ assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
31
+ styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
32
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
33
+ optimization: process.env['NODE_ENV'] === 'production',
34
+ }),
35
+ new NxReactRspackPlugin({
36
+ // Uncomment this line if you don't want to use SVGR
37
+ // See: https://react-svgr.com/
38
+ // svgr: false
39
+ }),
40
+ new NxModuleFederationPlugin({ config }, { dts: false }),
41
+ new NxModuleFederationDevServerPlugin({ config }),
42
+ ],
8
43
  };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- export default composePlugins(withNx(), withReact(), withModuleFederation(config, { dts: false }));
@@ -1,4 +1,4 @@
1
- import type { GeneratorCallback, Tree } from '@nx/devkit';
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema } from '../../application/schema';
3
3
  import type { Schema } from '../schema';
4
4
  export declare function setupSsrForRemote(tree: Tree, options: NormalizedSchema<Schema>, appName: string): Promise<GeneratorCallback>;
@@ -2,39 +2,61 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupSsrForRemote = setupSsrForRemote;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const devkit_2 = require("@nx/devkit");
5
6
  const versions_1 = require("../../../utils/versions");
7
+ const create_application_files_1 = require("../../application/lib/create-application-files");
6
8
  async function setupSsrForRemote(tree, options, appName) {
7
9
  const tasks = [];
8
- const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
10
+ const project = (0, devkit_2.readProjectConfiguration)(tree, appName);
9
11
  const pathToModuleFederationSsrFiles = options.typescriptConfiguration
10
12
  ? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
11
13
  : `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
12
- (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, {
13
- ...options,
14
- port: Number(options?.devServerPort) || 4200,
15
- appName,
16
- tmpl: '',
17
- browserBuildOutputPath: project.targets.build.options.outputPath,
18
- serverBuildOutputPath: project.targets.server.options.outputPath,
19
- });
14
+ const templateVariables = options.bundler === 'rspack'
15
+ ? {
16
+ ...(0, create_application_files_1.getDefaultTemplateVariables)(tree, options),
17
+ rspackPluginOptions: {
18
+ ...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
19
+ mainServer: `./server.ts`,
20
+ },
21
+ port: Number(options?.devServerPort) || 4200,
22
+ appName,
23
+ }
24
+ : {
25
+ ...options,
26
+ port: Number(options?.devServerPort) || 4200,
27
+ appName,
28
+ tmpl: '',
29
+ browserBuildOutputPath: project.targets.build?.options?.outputPath,
30
+ serverBuildOutputPath: project.targets.server?.options?.outputPath,
31
+ };
32
+ (0, devkit_2.generateFiles)(tree, (0, devkit_2.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, templateVariables);
20
33
  // For hosts to use when running remotes in static mode.
21
- const originalOutputPath = project.targets.build?.options?.outputPath;
34
+ const originalOutputPath = project.targets.build?.options?.outputPath ??
35
+ options.isUsingTsSolutionConfig
36
+ ? 'dist'
37
+ : (0, devkit_2.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.appProjectRoot), 'dist', options.appProjectRoot != '.'
38
+ ? options.appProjectRoot
39
+ : options.projectName);
22
40
  const serverOptions = project.targets.server?.options;
23
41
  const serverOutputPath = serverOptions?.outputPath ??
24
- (0, devkit_1.joinPathFragments)(originalOutputPath, 'server');
42
+ (0, devkit_2.joinPathFragments)(originalOutputPath, 'server');
25
43
  const serverOutputName = serverOptions?.outputFileName ?? 'main.js';
26
44
  project.targets['serve-static'] = {
27
45
  dependsOn: ['build', 'server'],
28
46
  executor: 'nx:run-commands',
29
47
  defaultConfiguration: 'development',
30
48
  options: {
31
- command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(serverOutputPath, serverOutputName)}`,
49
+ command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_2.joinPathFragments)(serverOutputPath, serverOutputName)}`,
32
50
  },
33
51
  };
34
- (0, devkit_1.updateProjectConfiguration)(tree, appName, project);
35
- const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
52
+ (0, devkit_2.updateProjectConfiguration)(tree, appName, project);
53
+ const installTask = (0, devkit_2.addDependenciesToPackageJson)(tree, {
36
54
  '@module-federation/node': versions_1.moduleFederationNodeVersion,
55
+ cors: versions_1.corsVersion,
56
+ isbot: versions_1.isbotVersion,
57
+ express: versions_1.expressVersion,
58
+ '@types/express': versions_1.typesExpressVersion,
37
59
  }, {});
38
60
  tasks.push(installTask);
39
- return (0, devkit_1.runTasksInSerial)(...tasks);
61
+ return (0, devkit_2.runTasksInSerial)(...tasks);
40
62
  }
@@ -17,12 +17,21 @@ const maybe_js_1 = require("../../utils/maybe-js");
17
17
  const js_1 = require("@nx/js");
18
18
  const versions_1 = require("../../utils/versions");
19
19
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
20
+ const create_application_files_1 = require("../application/lib/create-application-files");
20
21
  function addModuleFederationFiles(host, options) {
21
- const templateVariables = {
22
- ...(0, devkit_1.names)(options.projectName),
23
- ...options,
24
- tmpl: '',
25
- };
22
+ const templateVariables = options.bundler === 'rspack'
23
+ ? {
24
+ ...(0, create_application_files_1.getDefaultTemplateVariables)(host, options),
25
+ rspackPluginOptions: {
26
+ ...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
27
+ mainServer: `./server.ts`,
28
+ },
29
+ }
30
+ : {
31
+ ...(0, devkit_1.names)(options.projectName),
32
+ ...options,
33
+ tmpl: '',
34
+ };
26
35
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js
27
36
  ? options.bundler === 'rspack'
28
37
  ? 'rspack-common'
@@ -58,8 +67,8 @@ async function remoteGenerator(host, schema) {
58
67
  ? false
59
68
  : schema.typescriptConfiguration ?? true,
60
69
  dynamic: schema.dynamic ?? false,
61
- // TODO(colum): remove when MF works with Crystal
62
- addPlugin: false,
70
+ // TODO(colum): remove when Webpack MF works with Crystal
71
+ addPlugin: !schema.bundler || schema.bundler === 'rspack' ? true : false,
63
72
  bundler: schema.bundler ?? 'rspack',
64
73
  };
65
74
  if (options.dynamic) {
@@ -97,25 +106,22 @@ async function remoteGenerator(host, schema) {
97
106
  (0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
98
107
  (0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
99
108
  if (options.ssr) {
100
- const setupSsrTask = await (0, setup_ssr_1.default)(host, {
101
- project: options.projectName,
102
- serverPort: options.devServerPort,
103
- skipFormat: true,
104
- bundler: options.bundler,
105
- });
106
- tasks.push(setupSsrTask);
109
+ if (options.bundler !== 'rspack') {
110
+ const setupSsrTask = await (0, setup_ssr_1.default)(host, {
111
+ project: options.projectName,
112
+ serverPort: options.devServerPort,
113
+ skipFormat: true,
114
+ bundler: options.bundler,
115
+ });
116
+ tasks.push(setupSsrTask);
117
+ }
107
118
  const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
108
119
  tasks.push(setupSsrForRemoteTask);
109
120
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
110
- if (options.bundler === 'rspack') {
111
- projectConfig.targets.server.executor = '@nx/rspack:rspack';
112
- projectConfig.targets.server.options.rspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
113
- delete projectConfig.targets.server.options.webpackConfig;
114
- }
115
- else {
121
+ if (options.bundler !== 'rspack') {
116
122
  projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
123
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
117
124
  }
118
- (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
119
125
  }
120
126
  if (!options.setParserOptionsProject) {
121
127
  host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
@@ -7,4 +7,5 @@ export declare function updateModuleFederationProject(host: Tree, options: {
7
7
  typescriptConfiguration?: boolean;
8
8
  dynamic?: boolean;
9
9
  bundler?: 'rspack' | 'webpack';
10
- }): void;
10
+ ssr?: boolean;
11
+ }, isHost?: boolean): void;
@@ -4,23 +4,9 @@ exports.updateModuleFederationProject = updateModuleFederationProject;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const maybe_js_1 = require("../utils/maybe-js");
6
6
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
- function updateModuleFederationProject(host, options) {
7
+ function updateModuleFederationProject(host, options, isHost = false) {
8
8
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
9
- if (options.bundler === 'rspack') {
10
- projectConfig.targets.build.executor = '@nx/rspack:rspack';
11
- projectConfig.targets.build.options = {
12
- ...(projectConfig.targets.build.options ?? {}),
13
- main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
14
- rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
15
- target: 'web',
16
- };
17
- projectConfig.targets.build.configurations ??= {};
18
- projectConfig.targets.build.configurations.production = {
19
- ...(projectConfig.targets.build.configurations?.production ?? {}),
20
- rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
21
- };
22
- }
23
- else {
9
+ if (options.bundler !== 'rspack') {
24
10
  projectConfig.targets.build.options = {
25
11
  ...(projectConfig.targets.build.options ?? {}),
26
12
  main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
@@ -34,15 +20,7 @@ function updateModuleFederationProject(host, options) {
34
20
  }
35
21
  // If host should be configured to use dynamic federation
36
22
  if (options.dynamic) {
37
- if (options.bundler === 'rspack') {
38
- const pathToProdRspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
39
- if (host.exists(pathToProdRspackConfig)) {
40
- host.delete(pathToProdRspackConfig);
41
- }
42
- delete projectConfig.targets.build.configurations.production
43
- ?.rspackConfig;
44
- }
45
- else {
23
+ if (options.bundler !== 'rspack') {
46
24
  const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
47
25
  if (host.exists(pathToProdWebpackConfig)) {
48
26
  host.delete(pathToProdWebpackConfig);
@@ -51,36 +29,39 @@ function updateModuleFederationProject(host, options) {
51
29
  ?.webpackConfig;
52
30
  }
53
31
  }
54
- if (options.bundler === 'rspack') {
55
- projectConfig.targets.serve.executor =
56
- '@nx/rspack:module-federation-dev-server';
57
- }
58
- else {
32
+ if (options.bundler !== 'rspack') {
59
33
  projectConfig.targets.serve.executor =
60
34
  '@nx/react:module-federation-dev-server';
61
35
  }
62
- projectConfig.targets.serve.options.port = options.devServerPort;
36
+ projectConfig.targets.serve ??= {};
37
+ projectConfig.targets.serve.options ??= {};
38
+ projectConfig.targets.serve.options.port =
39
+ options.bundler === 'rspack' && options.ssr && isHost
40
+ ? 4000
41
+ : options.devServerPort;
63
42
  // `serve-static` for remotes that don't need to be in development mode
64
- const serveStaticExecutor = options.bundler === 'rspack'
65
- ? '@nx/rspack:module-federation-static-server'
66
- : '@nx/react:module-federation-static-server';
67
- projectConfig.targets['serve-static'] = {
68
- executor: serveStaticExecutor,
69
- defaultConfiguration: 'production',
70
- options: {
71
- serveTarget: `${options.projectName}:serve`,
72
- },
73
- configurations: {
74
- development: {
75
- serveTarget: `${options.projectName}:serve:development`,
43
+ if (options.bundler !== 'rspack') {
44
+ const serveStaticExecutor = '@nx/react:module-federation-static-server';
45
+ projectConfig.targets['serve-static'] = {
46
+ executor: serveStaticExecutor,
47
+ defaultConfiguration: 'production',
48
+ options: {
49
+ serveTarget: `${options.projectName}:serve`,
76
50
  },
77
- production: {
78
- serveTarget: `${options.projectName}:serve:production`,
51
+ configurations: {
52
+ development: {
53
+ serveTarget: `${options.projectName}:serve:development`,
54
+ },
55
+ production: {
56
+ serveTarget: `${options.projectName}:serve:production`,
57
+ },
79
58
  },
80
- },
81
- };
59
+ };
60
+ }
82
61
  // Typechecks must be performed first before build and serve to generate remote d.ts files.
83
62
  if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
63
+ projectConfig.targets.build ??= {};
64
+ projectConfig.targets.serve ??= {};
84
65
  projectConfig.targets.build.dependsOn = ['^build', 'typecheck'];
85
66
  projectConfig.targets.serve.dependsOn = ['typecheck'];
86
67
  }
@@ -1,16 +0,0 @@
1
- const {composePlugins, withNx, withReact} = require('@nx/rspack');
2
- const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
3
-
4
- const baseConfig = require('./module-federation.config');
5
-
6
- const defaultConfig = {
7
- ...baseConfig
8
- };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- module.exports = composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));
@@ -1,16 +0,0 @@
1
- import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
3
-
4
- import baseConfig from './module-federation.config';
5
-
6
- const defaultConfig = {
7
- ...baseConfig
8
- };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- export default composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));
@@ -1,16 +0,0 @@
1
- const {composePlugins, withNx, withReact} = require('@nx/rspack');
2
- const {withModuleFederationForSSR} = require('@nx/module-federation/rspack');
3
-
4
- const baseConfig = require("./module-federation.server.config");
5
-
6
- const defaultConfig = {
7
- ...baseConfig,
8
- };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- module.exports = composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));
@@ -1,16 +0,0 @@
1
- import {composePlugins, withNx, withReact} from '@nx/rspack';
2
- import {withModuleFederationForSSR} from '@nx/module-federation/rspack';
3
-
4
- import baseConfig from "./module-federation.server.config";
5
-
6
- const defaultConfig = {
7
- ...baseConfig,
8
- };
9
-
10
- // Nx plugins for rspack to build config object from Nx options and context.
11
- /**
12
- * DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support Module Federation
13
- * The DTS Plugin can be enabled by setting dts: true
14
- * Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
15
- */
16
- export default composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));