@nx/react 0.0.0-pr-30457-0ed97e4 → 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.
- package/package.json +6 -6
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +1 -3
- package/src/generators/application/application.js +1 -1
- package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +1 -0
- package/src/generators/application/lib/add-e2e.js +0 -4
- package/src/generators/application/lib/add-jest.js +2 -26
- package/src/generators/application/lib/create-application-files.d.ts +0 -61
- package/src/generators/application/lib/create-application-files.js +44 -49
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -37
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +32 -60
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
- package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +9 -37
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +14 -37
- package/src/generators/host/host.js +15 -15
- package/src/generators/host/lib/add-module-federation-files.js +12 -28
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
- package/src/generators/host/lib/setup-ssr-for-host.js +22 -46
- package/src/generators/library/library.js +12 -14
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +13 -40
- package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +0 -6
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +16 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +0 -6
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +16 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +13 -40
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
- package/src/generators/remote/lib/setup-ssr-for-remote.js +15 -37
- package/src/generators/remote/remote.js +21 -27
- package/src/rules/update-module-federation-project.d.ts +1 -2
- package/src/rules/update-module-federation-project.js +47 -28
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -66
- package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -49
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -66
- package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +0 -49
- package/src/generators/host/lib/normalize-host-name.d.ts +0 -2
- package/src/generators/host/lib/normalize-host-name.js +0 -12
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +0 -69
- package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +0 -45
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +0 -69
- 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
|
|
7
|
+
function updateModuleFederationProject(host, options) {
|
|
8
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
9
|
-
if (options.bundler
|
|
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
|
|
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
|
|
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
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
52
|
-
|
|
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,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];
|
package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__
DELETED
|
@@ -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,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];
|
package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__
DELETED
|
@@ -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
|
-
}
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__
DELETED
|
@@ -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];
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__
DELETED
|
@@ -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
|
-
}
|