@nx/react 0.0.0-pr-29464-73fdcbb → 0.0.0-pr-30565-cfe2164

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 (52) 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 +20 -21
  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/application/lib/normalize-options.js +1 -4
  10. package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -37
  11. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +32 -60
  12. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
  13. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
  14. package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
  15. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
  16. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -0
  17. package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
  18. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +9 -37
  19. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +14 -37
  20. package/src/generators/host/host.js +15 -15
  21. package/src/generators/host/lib/add-module-federation-files.js +12 -28
  22. package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
  23. package/src/generators/host/lib/setup-ssr-for-host.js +22 -46
  24. package/src/generators/library/library.js +1 -1
  25. package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -40
  26. package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
  27. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
  28. package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
  29. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
  30. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -0
  31. package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
  32. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +13 -40
  33. package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
  34. package/src/generators/remote/lib/setup-ssr-for-remote.js +15 -37
  35. package/src/generators/remote/remote.js +21 -27
  36. package/src/rules/update-module-federation-project.d.ts +1 -2
  37. package/src/rules/update-module-federation-project.js +47 -28
  38. package/src/utils/assertion.d.ts +0 -2
  39. package/src/utils/assertion.js +0 -6
  40. package/src/utils/ct-utils.d.ts +1 -1
  41. package/src/utils/format-file.d.ts +1 -0
  42. package/src/utils/format-file.js +11 -0
  43. package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -66
  44. package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -49
  45. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -66
  46. package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +0 -49
  47. package/src/generators/host/lib/normalize-host-name.d.ts +0 -2
  48. package/src/generators/host/lib/normalize-host-name.js +0 -12
  49. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -69
  50. package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -45
  51. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -69
  52. package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +0 -45
@@ -4,9 +4,23 @@ 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, isHost = false) {
7
+ function updateModuleFederationProject(host, options) {
8
8
  const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
9
- if (options.bundler !== 'rspack') {
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 {
10
24
  projectConfig.targets.build.options = {
11
25
  ...(projectConfig.targets.build.options ?? {}),
12
26
  main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
@@ -20,7 +34,15 @@ function updateModuleFederationProject(host, options, isHost = false) {
20
34
  }
21
35
  // If host should be configured to use dynamic federation
22
36
  if (options.dynamic) {
23
- if (options.bundler !== 'rspack') {
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 {
24
46
  const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
25
47
  if (host.exists(pathToProdWebpackConfig)) {
26
48
  host.delete(pathToProdWebpackConfig);
@@ -29,39 +51,36 @@ function updateModuleFederationProject(host, options, isHost = false) {
29
51
  ?.webpackConfig;
30
52
  }
31
53
  }
32
- if (options.bundler !== 'rspack') {
54
+ if (options.bundler === 'rspack') {
55
+ projectConfig.targets.serve.executor =
56
+ '@nx/rspack:module-federation-dev-server';
57
+ }
58
+ else {
33
59
  projectConfig.targets.serve.executor =
34
60
  '@nx/react:module-federation-dev-server';
35
61
  }
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;
62
+ projectConfig.targets.serve.options.port = options.devServerPort;
42
63
  // `serve-static` for remotes that don't need to be in development mode
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`,
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`,
50
76
  },
51
- configurations: {
52
- development: {
53
- serveTarget: `${options.projectName}:serve:development`,
54
- },
55
- production: {
56
- serveTarget: `${options.projectName}:serve:production`,
57
- },
77
+ production: {
78
+ serveTarget: `${options.projectName}:serve:production`,
58
79
  },
59
- };
60
- }
80
+ },
81
+ };
61
82
  // Typechecks must be performed first before build and serve to generate remote d.ts files.
62
83
  if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
63
- projectConfig.targets.build ??= {};
64
- projectConfig.targets.serve ??= {};
65
84
  projectConfig.targets.build.dependsOn = ['^build', 'typecheck'];
66
85
  projectConfig.targets.serve.dependsOn = ['typecheck'];
67
86
  }
@@ -1,3 +1 @@
1
- import { type Schema } from '../generators/application/schema';
2
1
  export declare function assertValidStyle(style: string): void;
3
- export declare function assertValidReactRouter(reactRouter: boolean, bundler: Schema['bundler']): void;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.assertValidStyle = assertValidStyle;
4
- exports.assertValidReactRouter = assertValidReactRouter;
5
4
  const VALID_STYLES = [
6
5
  'css',
7
6
  'scss',
@@ -17,8 +16,3 @@ function assertValidStyle(style) {
17
16
  throw new Error(`Unsupported style option found: ${style}. Valid values are: "${VALID_STYLES.join('", "')}"`);
18
17
  }
19
18
  }
20
- function assertValidReactRouter(reactRouter, bundler) {
21
- if (reactRouter && bundler !== 'vite') {
22
- throw new Error(`Unsupported bundler found: ${bundler}. React Router is only supported with 'vite'.`);
23
- }
24
- }
@@ -10,5 +10,5 @@ export declare function getBundlerFromTarget(found: FoundTarget, tree: Tree): Pr
10
10
  export declare function getActualBundler(tree: Tree, options: {
11
11
  buildTarget?: string;
12
12
  bundler?: 'vite' | 'webpack';
13
- }, found: FoundTarget): Promise<"webpack" | "vite">;
13
+ }, found: FoundTarget): Promise<"vite" | "webpack">;
14
14
  export declare function isComponent(tree: Tree, filePath: string): boolean;
@@ -0,0 +1 @@
1
+ export declare function formatFile(content: any, ...values: any[]): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatFile = formatFile;
4
+ const prettier_1 = require("prettier");
5
+ const devkit_1 = require("@nx/devkit");
6
+ function formatFile(content, ...values) {
7
+ return (0, prettier_1.format)((0, devkit_1.stripIndents)(content, values), {
8
+ singleQuote: true,
9
+ parser: 'typescript',
10
+ });
11
+ }
@@ -1,66 +0,0 @@
1
- const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
2
- const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
3
- const { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } = require('@nx/module-federation/rspack');
4
- const { join } = require('path');
5
-
6
- const browserMfConfig = require('./module-federation.config');
7
- const serverMfConfig = require('./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
- historyApiFallback: {
18
- index: '/index.html',
19
- disableDotRule: true,
20
- htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
21
- },
22
- devMiddleware: {
23
- writeToDisk: (file: string) => !file.includes('.hot-update.'),
24
- },
25
- },
26
- plugins: [
27
- new NxAppRspackPlugin({
28
- tsConfig: '<%= rspackPluginOptions.tsConfig %>',
29
- main: '<%= rspackPluginOptions.main %>',
30
- index: '<%= rspackPluginOptions.index %>',
31
- baseHref: '<%= rspackPluginOptions.baseHref %>',
32
- assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
33
- styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
34
- outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
35
- optimization: process.env['NODE_ENV'] === 'production',
36
- }),
37
- new NxReactRspackPlugin({
38
- // Uncomment this line if you don't want to use SVGR
39
- // See: https://react-svgr.com/
40
- // svgr: false
41
- }),
42
- new NxModuleFederationPlugin({ config: browserMfConfig }, { dts: false }),
43
- ],
44
- };
45
-
46
- const serverRspackConfig = {
47
- name: 'server',
48
- target: 'async-node',
49
- output: {
50
- path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
51
- filename: 'server.js'
52
- },
53
- plugins: [
54
- new NxAppRspackPlugin({
55
- outputPath: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
56
- outputFileName: 'server.js',
57
- tsConfig: '<%= rspackPluginOptions.tsConfig %>',
58
- main: '<%= rspackPluginOptions.mainServer %>',
59
- baseHref: '<%= rspackPluginOptions.baseHref %>',
60
- }),
61
- new NxModuleFederationPlugin({ config: serverMfConfig, isServer: true }, { dts: false }),
62
- new NxModuleFederationSSRDevServerPlugin({ config: serverMfConfig }),
63
- ],
64
- };
65
-
66
- module.exports = [browserRspackConfig, serverRspackConfig];
@@ -1,49 +0,0 @@
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
- import { StaticRouter } from 'react-router-dom/server';
9
-
10
-
11
- let indexHtml: null | string = null;
12
-
13
- export function handleRequest(indexPath: string) {
14
- return function render(req: Request, res: Response) {
15
- let didError = false;
16
-
17
- if (!indexHtml) {
18
- indexHtml = fs.readFileSync(indexPath).toString();
19
- }
20
-
21
- const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
22
-
23
- // For bots (e.g. search engines), the content will not be streamed but render all at once.
24
- // For users, content should be streamed to the user as they are ready.
25
- const callbackName = isbot(req.headers['user-agent']) ? 'onAllReady' : 'onShellReady';
26
-
27
- const stream = ReactDOMServer.renderToPipeableStream(
28
- <StaticRouter location={req.originalUrl}><App /></StaticRouter>,
29
- {
30
- [callbackName]() {
31
- res.statusCode = didError ? 500 : 200;
32
- res.setHeader('Content-type', 'text/html; charset=utf-8');
33
- res.write(`${htmlStart}<div id="root">`);
34
- stream.pipe(res);
35
- res.write(`</div>${htmlEnd}`);
36
- },
37
- onShellError(error) {
38
- console.error(error);
39
- res.statusCode = 500;
40
- res.send('<!doctype html><h1>Server Error</h1>');
41
- },
42
- onError(error) {
43
- didError = true;
44
- console.error(error);
45
- }
46
- }
47
- );
48
- }
49
- }
@@ -1,66 +0,0 @@
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
- historyApiFallback: {
18
- index: '/index.html',
19
- disableDotRule: true,
20
- htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
21
- },
22
- devMiddleware: {
23
- writeToDisk: (file: string) => !file.includes('.hot-update.'),
24
- },
25
- },
26
- plugins: [
27
- new NxAppRspackPlugin({
28
- tsConfig: '<%= rspackPluginOptions.tsConfig %>',
29
- main: '<%= rspackPluginOptions.main %>',
30
- index: '<%= rspackPluginOptions.index %>',
31
- baseHref: '<%= rspackPluginOptions.baseHref %>',
32
- assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
33
- styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
34
- outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
35
- optimization: process.env['NODE_ENV'] === 'production',
36
- }),
37
- new NxReactRspackPlugin({
38
- // Uncomment this line if you don't want to use SVGR
39
- // See: https://react-svgr.com/
40
- // svgr: false
41
- }),
42
- new NxModuleFederationPlugin({ config: browserMfConfig }, { dts: false }),
43
- ],
44
- };
45
-
46
- const serverRspackConfig = {
47
- name: 'server',
48
- target: 'async-node',
49
- output: {
50
- path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
51
- filename: 'server.js'
52
- },
53
- plugins: [
54
- new NxAppRspackPlugin({
55
- outputPath: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
56
- outputFileName: 'server.js',
57
- tsConfig: '<%= rspackPluginOptions.tsConfig %>',
58
- main: '<%= rspackPluginOptions.mainServer %>',
59
- baseHref: '<%= rspackPluginOptions.baseHref %>',
60
- }),
61
- new NxModuleFederationPlugin({ config: serverMfConfig, isServer: true }, { dts: false }),
62
- new NxModuleFederationSSRDevServerPlugin({ config: serverMfConfig }),
63
- ],
64
- };
65
-
66
- export default [browserRspackConfig, serverRspackConfig];
@@ -1,49 +0,0 @@
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
- import { StaticRouter } from 'react-router-dom/server';
9
-
10
-
11
- let indexHtml: null | string = null;
12
-
13
- export function handleRequest(indexPath: string) {
14
- return function render(req: Request, res: Response) {
15
- let didError = false;
16
-
17
- if (!indexHtml) {
18
- indexHtml = fs.readFileSync(indexPath).toString();
19
- }
20
-
21
- const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
22
-
23
- // For bots (e.g. search engines), the content will not be streamed but render all at once.
24
- // For users, content should be streamed to the user as they are ready.
25
- const callbackName = isbot(req.headers['user-agent']) ? 'onAllReady' : 'onShellReady';
26
-
27
- const stream = ReactDOMServer.renderToPipeableStream(
28
- <StaticRouter location={req.originalUrl}><App /></StaticRouter>,
29
- {
30
- [callbackName]() {
31
- res.statusCode = didError ? 500 : 200;
32
- res.setHeader('Content-type', 'text/html; charset=utf-8');
33
- res.write(`${htmlStart}<div id="root">`);
34
- stream.pipe(res);
35
- res.write(`</div>${htmlEnd}`);
36
- },
37
- onShellError(error) {
38
- console.error(error);
39
- res.statusCode = 500;
40
- res.send('<!doctype html><h1>Server Error</h1>');
41
- },
42
- onError(error) {
43
- didError = true;
44
- console.error(error);
45
- }
46
- }
47
- );
48
- }
49
- }
@@ -1,2 +0,0 @@
1
- import { Tree } from '@nx/devkit';
2
- export declare function normalizeHostName(tree: Tree, directory: string, name?: string): Promise<string>;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeHostName = normalizeHostName;
4
- const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
- async function normalizeHostName(tree, directory, name) {
6
- const { projectName } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
7
- name,
8
- directory,
9
- projectType: 'application',
10
- });
11
- return projectName;
12
- }
@@ -1,69 +0,0 @@
1
- const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
2
- const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
3
- const { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } = require('@nx/module-federation/rspack');
4
- const { join } = require('path');
5
-
6
- const browserMfConfig = require('./module-federation.config');
7
- const serverMfConfig = require('./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
- module.exports = [browserRspackConfig, serverRspackConfig];
@@ -1,45 +0,0 @@
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,69 +0,0 @@
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];
@@ -1,45 +0,0 @@
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
- }