@nx/react 0.0.0-pr-30418-d6cd6b6 → 0.0.0-pr-30516-4c8bfff

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/package.json +6 -6
  2. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +1 -3
  3. package/src/generators/application/application.js +1 -1
  4. package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +1 -0
  5. package/src/generators/application/lib/add-e2e.js +0 -4
  6. package/src/generators/application/lib/add-jest.js +2 -26
  7. package/src/generators/application/lib/create-application-files.d.ts +0 -61
  8. package/src/generators/application/lib/create-application-files.js +44 -49
  9. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -37
  10. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +32 -60
  11. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
  12. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
  13. package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
  14. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
  15. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -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-ts/rspack.config.prod.ts__tmpl__ +9 -37
  18. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +14 -37
  19. package/src/generators/host/host.js +15 -15
  20. package/src/generators/host/lib/add-module-federation-files.js +12 -28
  21. package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
  22. package/src/generators/host/lib/setup-ssr-for-host.js +22 -46
  23. package/src/generators/library/library.js +12 -14
  24. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -40
  25. package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
  26. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
  27. package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
  28. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
  29. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -0
  30. package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
  31. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +13 -40
  32. package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
  33. package/src/generators/remote/lib/setup-ssr-for-remote.js +15 -37
  34. package/src/generators/remote/remote.js +21 -27
  35. package/src/rules/update-module-federation-project.d.ts +1 -2
  36. package/src/rules/update-module-federation-project.js +47 -28
  37. package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -66
  38. package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -49
  39. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -66
  40. package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +0 -49
  41. package/src/generators/host/lib/normalize-host-name.d.ts +0 -2
  42. package/src/generators/host/lib/normalize-host-name.js +0 -12
  43. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -69
  44. package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -45
  45. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -69
  46. package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +0 -45
@@ -16,14 +16,11 @@ const js_1 = require("@nx/js");
16
16
  const versions_1 = require("../../utils/versions");
17
17
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
18
18
  const update_module_federation_tsconfig_1 = require("./lib/update-module-federation-tsconfig");
19
- const normalize_host_name_1 = require("./lib/normalize-host-name");
20
19
  async function hostGenerator(host, schema) {
21
20
  const tasks = [];
22
- const name = await (0, normalize_host_name_1.normalizeHostName)(host, schema.directory, schema.name);
23
21
  const options = {
24
22
  ...(await (0, normalize_options_1.normalizeOptions)(host, {
25
23
  ...schema,
26
- name,
27
24
  useProjectJson: true,
28
25
  })),
29
26
  js: schema.js ?? false,
@@ -31,8 +28,8 @@ async function hostGenerator(host, schema) {
31
28
  ? false
32
29
  : schema.typescriptConfiguration ?? true,
33
30
  dynamic: schema.dynamic ?? false,
34
- // TODO(colum): remove when Webpack MF works with Crystal
35
- addPlugin: !schema.bundler || schema.bundler === 'rspack' ? true : false,
31
+ // TODO(colum): remove when MF works with Crystal
32
+ addPlugin: false,
36
33
  bundler: schema.bundler ?? 'rspack',
37
34
  };
38
35
  // Check to see if remotes are provided and also check if --dynamic is provided
@@ -84,22 +81,25 @@ async function hostGenerator(host, schema) {
84
81
  }
85
82
  }
86
83
  (0, add_module_federation_files_1.addModuleFederationFiles)(host, options, remotesWithPorts);
87
- (0, update_module_federation_project_1.updateModuleFederationProject)(host, options, true);
84
+ (0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
88
85
  (0, update_module_federation_e2e_project_1.updateModuleFederationE2eProject)(host, options);
89
86
  (0, update_module_federation_tsconfig_1.updateModuleFederationTsconfig)(host, options);
90
87
  if (options.ssr) {
91
- if (options.bundler !== 'rspack') {
92
- const setupSsrTask = await (0, setup_ssr_1.default)(host, {
93
- project: options.projectName,
94
- serverPort: options.devServerPort,
95
- skipFormat: true,
96
- });
97
- tasks.push(setupSsrTask);
98
- }
88
+ const setupSsrTask = await (0, setup_ssr_1.default)(host, {
89
+ project: options.projectName,
90
+ serverPort: options.devServerPort,
91
+ skipFormat: true,
92
+ });
93
+ tasks.push(setupSsrTask);
99
94
  const setupSsrForHostTask = await (0, setup_ssr_for_host_1.setupSsrForHost)(host, options, options.projectName, remotesWithPorts);
100
95
  tasks.push(setupSsrForHostTask);
101
96
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
102
- if (options.bundler !== 'rspack') {
97
+ if (options.bundler === 'rspack') {
98
+ projectConfig.targets.server.executor = '@nx/rspack:rspack';
99
+ projectConfig.targets.server.options.rspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
100
+ delete projectConfig.targets.server.options.webpackConfig;
101
+ }
102
+ else {
103
103
  projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
104
104
  }
105
105
  (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
@@ -3,35 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addModuleFederationFiles = addModuleFederationFiles;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const maybe_js_1 = require("../../../utils/maybe-js");
6
- const create_application_files_1 = require("../../application/lib/create-application-files");
7
6
  function addModuleFederationFiles(host, options, defaultRemoteManifest) {
8
- const templateVariables = options.bundler === 'rspack'
9
- ? {
10
- ...(0, create_application_files_1.getDefaultTemplateVariables)(host, options),
11
- rspackPluginOptions: {
12
- ...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
13
- mainServer: `./server.ts`,
14
- },
15
- static: !options?.dynamic,
16
- remotes: defaultRemoteManifest.map(({ name, port }) => {
17
- return {
18
- ...(0, devkit_1.names)(name),
19
- port,
20
- };
21
- }),
22
- }
23
- : {
24
- ...(0, devkit_1.names)(options.projectName),
25
- ...options,
26
- static: !options?.dynamic,
27
- tmpl: '',
28
- remotes: defaultRemoteManifest.map(({ name, port }) => {
29
- return {
30
- ...(0, devkit_1.names)(name),
31
- port,
32
- };
33
- }),
34
- };
7
+ const templateVariables = {
8
+ ...(0, devkit_1.names)(options.projectName),
9
+ ...options,
10
+ static: !options?.dynamic,
11
+ tmpl: '',
12
+ remotes: defaultRemoteManifest.map(({ name, port }) => {
13
+ return {
14
+ ...(0, devkit_1.names)(name),
15
+ port,
16
+ };
17
+ }),
18
+ };
35
19
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
36
20
  const pathToMFManifest = (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
37
21
  // Module federation requires bootstrap code to be dynamically imported.
@@ -1,6 +1,6 @@
1
- import { GeneratorCallback, Tree } from '@nx/devkit';
2
- import type { NormalizedSchema } from '../schema';
3
- export declare function setupSsrForHost(tree: Tree, options: NormalizedSchema, appName: string, defaultRemoteManifest: {
1
+ import type { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import type { Schema } from '../schema';
3
+ export declare function setupSsrForHost(tree: Tree, options: Schema, appName: string, defaultRemoteManifest: {
4
4
  name: string;
5
5
  port: number;
6
6
  }[]): Promise<GeneratorCallback>;
@@ -2,59 +2,35 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.setupSsrForHost = setupSsrForHost;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const devkit_2 = require("@nx/devkit");
6
5
  const versions_1 = require("../../../utils/versions");
7
- const create_application_files_1 = require("../../application/lib/create-application-files");
8
6
  async function setupSsrForHost(tree, options, appName, defaultRemoteManifest) {
9
7
  const tasks = [];
10
- let project = (0, devkit_2.readProjectConfiguration)(tree, appName);
11
- if (options.bundler !== 'rspack') {
12
- project.targets.serve.executor =
13
- '@nx/react:module-federation-ssr-dev-server';
14
- (0, devkit_2.updateProjectConfiguration)(tree, appName, project);
15
- }
8
+ let project = (0, devkit_1.readProjectConfiguration)(tree, appName);
9
+ project.targets.serve.executor =
10
+ options.bundler === 'rspack'
11
+ ? '@nx/rspack:module-federation-ssr-dev-server'
12
+ : '@nx/react:module-federation-ssr-dev-server';
13
+ (0, devkit_1.updateProjectConfiguration)(tree, appName, project);
16
14
  const pathToModuleFederationSsrFiles = options.typescriptConfiguration
17
15
  ? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
18
16
  : `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
19
- const templateVariables = options.bundler === 'rspack'
20
- ? {
21
- ...(0, create_application_files_1.getDefaultTemplateVariables)(tree, options),
22
- rspackPluginOptions: {
23
- ...(0, create_application_files_1.createNxRspackPluginOptions)(options, (0, devkit_1.offsetFromRoot)(options.appProjectRoot), false),
24
- mainServer: `./server.ts`,
25
- },
26
- port: Number(options?.devServerPort) || 4200,
27
- appName,
28
- static: !options?.dynamic,
29
- remotes: defaultRemoteManifest.map(({ name, port }) => {
30
- return {
31
- ...(0, devkit_2.names)(name),
32
- port,
33
- };
34
- }),
35
- }
36
- : {
37
- ...options,
38
- static: !options?.dynamic,
39
- port: Number(options?.devServerPort) || 4200,
40
- appName,
41
- tmpl: '',
42
- browserBuildOutputPath: project.targets.build?.options?.outputPath,
43
- remotes: defaultRemoteManifest.map(({ name, port }) => {
44
- return {
45
- ...(0, devkit_2.names)(name),
46
- port,
47
- };
48
- }),
49
- };
50
- (0, devkit_2.generateFiles)(tree, (0, devkit_2.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, templateVariables);
51
- const installTask = (0, devkit_2.addDependenciesToPackageJson)(tree, {
17
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, {
18
+ ...options,
19
+ static: !options?.dynamic,
20
+ port: Number(options?.devServerPort) || 4200,
21
+ remotes: defaultRemoteManifest.map(({ name, port }) => {
22
+ return {
23
+ ...(0, devkit_1.names)(name),
24
+ port,
25
+ };
26
+ }),
27
+ appName,
28
+ tmpl: '',
29
+ browserBuildOutputPath: project.targets.build.options.outputPath,
30
+ });
31
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
52
32
  '@module-federation/node': versions_1.moduleFederationNodeVersion,
53
- cors: versions_1.corsVersion,
54
- isbot: versions_1.isbotVersion,
55
- express: versions_1.expressVersion,
56
- '@types/express': versions_1.typesExpressVersion,
57
33
  }, {});
58
34
  tasks.push(installTask);
59
- return (0, devkit_2.runTasksInSerial)(...tasks);
35
+ return (0, devkit_1.runTasksInSerial)(...tasks);
60
36
  }
@@ -2,29 +2,28 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.libraryGenerator = libraryGenerator;
4
4
  exports.libraryGeneratorInternal = libraryGeneratorInternal;
5
+ const path_1 = require("path");
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
7
8
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
8
9
  const js_1 = require("@nx/js");
9
- const path_1 = require("path");
10
- const add_release_config_1 = require("@nx/js/src/generators/library/utils/add-release-config");
11
- const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
12
- const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
13
- const use_legacy_versioning_1 = require("nx/src/command-line/release/config/use-legacy-versioning");
14
- const create_ts_config_1 = require("../../utils/create-ts-config");
15
- const jest_utils_1 = require("../../utils/jest-utils");
16
- const maybe_js_1 = require("../../utils/maybe-js");
17
10
  const versions_1 = require("../../utils/versions");
11
+ const maybe_js_1 = require("../../utils/maybe-js");
18
12
  const component_1 = require("../component/component");
19
13
  const init_1 = require("../init/init");
20
- const add_linting_1 = require("./lib/add-linting");
14
+ const jest_utils_1 = require("../../utils/jest-utils");
15
+ const normalize_options_1 = require("./lib/normalize-options");
21
16
  const add_rollup_build_target_1 = require("./lib/add-rollup-build-target");
17
+ const add_linting_1 = require("./lib/add-linting");
18
+ const update_app_routes_1 = require("./lib/update-app-routes");
22
19
  const create_files_1 = require("./lib/create-files");
23
- const determine_entry_fields_1 = require("./lib/determine-entry-fields");
20
+ const create_ts_config_1 = require("../../utils/create-ts-config");
24
21
  const install_common_dependencies_1 = require("./lib/install-common-dependencies");
25
- const normalize_options_1 = require("./lib/normalize-options");
26
22
  const set_defaults_1 = require("./lib/set-defaults");
27
- const update_app_routes_1 = require("./lib/update-app-routes");
23
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
24
+ const determine_entry_fields_1 = require("./lib/determine-entry-fields");
25
+ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
26
+ const add_release_config_1 = require("@nx/js/src/generators/library/utils/add-release-config");
28
27
  async function libraryGenerator(host, schema) {
29
28
  return await libraryGeneratorInternal(host, {
30
29
  addPlugin: false,
@@ -197,8 +196,7 @@ async function libraryGeneratorInternal(host, schema) {
197
196
  await (0, add_release_config_1.addReleaseConfigForTsSolution)(host, options.name, projectConfiguration);
198
197
  }
199
198
  else {
200
- const nxJson = (0, devkit_1.readNxJson)(host);
201
- await (0, add_release_config_1.addReleaseConfigForNonTsSolution)((0, use_legacy_versioning_1.shouldUseLegacyVersioning)(nxJson.release), host, options.name, projectConfiguration);
199
+ await (0, add_release_config_1.addReleaseConfigForNonTsSolution)(host, options.name, projectConfiguration);
202
200
  }
203
201
  (0, devkit_1.updateProjectConfiguration)(host, options.name, projectConfiguration);
204
202
  tasks.push(await (0, add_release_config_1.releaseTasks)(host));
@@ -1,43 +1,16 @@
1
- const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
2
- const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
3
- const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');
4
- const { join } = require('path');
1
+ const { composePlugins, withNx, withReact } = require('@nx/rspack');
2
+ const { withModuleFederation } = require('@nx/module-federation/rspack');
5
3
 
6
- const config = require('./module-federation.config');
4
+ const baseConfig = require('./module-federation.config');
7
5
 
8
- module.exports = {
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
- ],
6
+ const config = {
7
+ ...baseConfig,
43
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(), withModuleFederation(config, { dts: false }));
@@ -6,10 +6,4 @@ module.exports = {
6
6
  exposes: {
7
7
  './Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
8
8
  },
9
- shared: (libraryName, libraryConfig) => {
10
- return {
11
- ...libraryConfig,
12
- eager: true
13
- }
14
- },
15
9
  };
@@ -0,0 +1,16 @@
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 }));
@@ -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(), '<%= rspackPluginOptions.outputPath %>', 'browser');
11
- const serverDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'server');
10
+ const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
11
+ const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
12
12
  const indexPath = path.join(browserDist, 'index.html');
13
13
 
14
14
  app.use(cors());
@@ -5,12 +5,6 @@ const config: ModuleFederationConfig = {
5
5
  exposes: {
6
6
  './Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
7
7
  },
8
- shared: (libraryName, libraryConfig) => {
9
- return {
10
- ...libraryConfig,
11
- eager: true
12
- }
13
- },
14
8
  };
15
9
 
16
10
  /**
@@ -0,0 +1,16 @@
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 }));
@@ -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(), '<%= rspackPluginOptions.outputPath %>', 'browser');
11
- const serverDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'server');
10
+ const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
11
+ const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
12
12
  const indexPath = path.join(browserDist, 'index.html');
13
13
 
14
14
  app.use(cors());
@@ -1,43 +1,16 @@
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';
1
+ import {composePlugins, withNx, withReact} from '@nx/rspack';
2
+ import {withModuleFederation} from '@nx/module-federation/rspack';
5
3
 
6
- import config from './module-federation.config';
4
+ import baseConfig from './module-federation.config';
7
5
 
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
- ],
6
+ const config = {
7
+ ...baseConfig,
43
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(), withModuleFederation(config, { dts: false }));
@@ -1,4 +1,4 @@
1
- import { GeneratorCallback, Tree } from '@nx/devkit';
1
+ import type { 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,61 +2,39 @@
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");
6
5
  const versions_1 = require("../../../utils/versions");
7
- const create_application_files_1 = require("../../application/lib/create-application-files");
8
6
  async function setupSsrForRemote(tree, options, appName) {
9
7
  const tasks = [];
10
- const project = (0, devkit_2.readProjectConfiguration)(tree, appName);
8
+ const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
11
9
  const pathToModuleFederationSsrFiles = options.typescriptConfiguration
12
10
  ? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
13
11
  : `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
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);
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
+ });
33
20
  // For hosts to use when running remotes in static mode.
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);
21
+ const originalOutputPath = project.targets.build?.options?.outputPath;
40
22
  const serverOptions = project.targets.server?.options;
41
23
  const serverOutputPath = serverOptions?.outputPath ??
42
- (0, devkit_2.joinPathFragments)(originalOutputPath, 'server');
24
+ (0, devkit_1.joinPathFragments)(originalOutputPath, 'server');
43
25
  const serverOutputName = serverOptions?.outputFileName ?? 'main.js';
44
26
  project.targets['serve-static'] = {
45
27
  dependsOn: ['build', 'server'],
46
28
  executor: 'nx:run-commands',
47
29
  defaultConfiguration: 'development',
48
30
  options: {
49
- command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_2.joinPathFragments)(serverOutputPath, serverOutputName)}`,
31
+ command: `PORT=${options.devServerPort ?? 4200} node ${(0, devkit_1.joinPathFragments)(serverOutputPath, serverOutputName)}`,
50
32
  },
51
33
  };
52
- (0, devkit_2.updateProjectConfiguration)(tree, appName, project);
53
- const installTask = (0, devkit_2.addDependenciesToPackageJson)(tree, {
34
+ (0, devkit_1.updateProjectConfiguration)(tree, appName, project);
35
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
54
36
  '@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,
59
37
  }, {});
60
38
  tasks.push(installTask);
61
- return (0, devkit_2.runTasksInSerial)(...tasks);
39
+ return (0, devkit_1.runTasksInSerial)(...tasks);
62
40
  }
@@ -17,21 +17,12 @@ 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");
21
20
  function addModuleFederationFiles(host, options) {
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
- };
21
+ const templateVariables = {
22
+ ...(0, devkit_1.names)(options.projectName),
23
+ ...options,
24
+ tmpl: '',
25
+ };
35
26
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js
36
27
  ? options.bundler === 'rspack'
37
28
  ? 'rspack-common'
@@ -67,8 +58,8 @@ async function remoteGenerator(host, schema) {
67
58
  ? false
68
59
  : schema.typescriptConfiguration ?? true,
69
60
  dynamic: schema.dynamic ?? false,
70
- // TODO(colum): remove when Webpack MF works with Crystal
71
- addPlugin: !schema.bundler || schema.bundler === 'rspack' ? true : false,
61
+ // TODO(colum): remove when MF works with Crystal
62
+ addPlugin: false,
72
63
  bundler: schema.bundler ?? 'rspack',
73
64
  };
74
65
  if (options.dynamic) {
@@ -106,22 +97,25 @@ async function remoteGenerator(host, schema) {
106
97
  (0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
107
98
  (0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
108
99
  if (options.ssr) {
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
- }
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);
118
107
  const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
119
108
  tasks.push(setupSsrForRemoteTask);
120
109
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
121
- if (options.bundler !== 'rspack') {
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 {
122
116
  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);
124
117
  }
118
+ (0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
125
119
  }
126
120
  if (!options.setParserOptionsProject) {
127
121
  host.delete((0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.lint.json'));
@@ -7,5 +7,4 @@ export declare function updateModuleFederationProject(host: Tree, options: {
7
7
  typescriptConfiguration?: boolean;
8
8
  dynamic?: boolean;
9
9
  bundler?: 'rspack' | 'webpack';
10
- ssr?: boolean;
11
- }, isHost?: boolean): void;
10
+ }): void;