@nx/react 19.7.0-beta.3 → 19.7.0-beta.5
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/migrations.json +13 -0
- package/package.json +7 -7
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +18 -5
- package/src/generators/application/application.js +4 -1
- package/src/generators/application/lib/add-routing.js +4 -1
- package/src/generators/application/lib/create-application-files.js +5 -2
- package/src/generators/federate-module/federate-module.js +5 -1
- package/src/generators/federate-module/schema.d.ts +1 -0
- package/src/generators/federate-module/schema.json +6 -0
- package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +33 -0
- package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +10 -0
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +16 -0
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +36 -0
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -0
- 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-ts/module-federation.server.config.ts__tmpl__ +13 -0
- 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-ts/module-federation.config.ts__tmpl__ +25 -0
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +36 -0
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +16 -0
- package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__ +21 -0
- package/src/generators/host/files/webpack-module-federation-ssr/server.ts__tmpl__ +28 -0
- package/src/generators/host/files/webpack-module-federation-ssr/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/host/files/webpack-module-federation-ssr-ts/server.ts__tmpl__ +28 -0
- package/src/generators/host/files/webpack-module-federation-ssr-ts/tsconfig.server.json__tmpl__ +17 -0
- package/src/generators/host/host.js +10 -3
- package/src/generators/host/lib/add-module-federation-files.js +23 -11
- package/src/generators/host/lib/setup-ssr-for-host.js +6 -3
- package/src/generators/host/schema.d.ts +1 -0
- package/src/generators/host/schema.json +8 -0
- package/src/generators/remote/files/rspack-common/src/main.jsx__tmpl__ +1 -0
- package/src/generators/remote/files/rspack-common/src/remote-entry.js__tmpl__ +1 -0
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +16 -0
- package/src/generators/remote/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +1 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
- 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-ts/module-federation.server.config.ts__tmpl__ +10 -0
- 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/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +13 -0
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +1 -0
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +16 -0
- package/src/generators/remote/files/rspack-module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/files/webpack-module-federation/module-federation.config.js__tmpl__ +9 -0
- package/src/generators/remote/files/webpack-module-federation-ssr/server.ts__tmpl__ +45 -0
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/server.ts__tmpl__ +45 -0
- package/src/generators/remote/files/webpack-module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js +2 -2
- package/src/generators/remote/lib/update-host-with-remote.js +4 -0
- package/src/generators/remote/remote.js +24 -11
- package/src/generators/remote/schema.d.ts +1 -0
- package/src/generators/remote/schema.json +8 -0
- package/src/generators/setup-ssr/schema.d.ts +1 -0
- package/src/generators/setup-ssr/schema.json +6 -0
- package/src/generators/setup-ssr/setup-ssr.js +11 -3
- package/src/module-federation/with-module-federation-ssr.js +7 -7
- package/src/module-federation/with-module-federation.js +1 -0
- package/src/rules/update-module-federation-project.d.ts +1 -0
- package/src/rules/update-module-federation-project.js +47 -15
- package/src/utils/add-mf-env-to-inputs.js +2 -1
- package/src/utils/maybe-js.d.ts +1 -0
- package/src/utils/maybe-js.js +1 -1
- package/src/utils/versions.d.ts +2 -2
- package/src/utils/versions.js +2 -2
- /package/src/generators/{remote/files/module-federation-ssr-ts → host/files/rspack-common}/tsconfig.lint.json__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation → rspack-module-federation}/module-federation.config.js__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr → rspack-module-federation-ssr}/server.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr → rspack-module-federation-ssr}/tsconfig.server.json__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr-ts → rspack-module-federation-ssr-ts}/server.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr-ts → rspack-module-federation-ssr-ts}/tsconfig.server.json__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation → webpack-module-federation}/webpack.config.js__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation → webpack-module-federation}/webpack.config.prod.js__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr → webpack-module-federation-ssr}/module-federation.server.config.js__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr → webpack-module-federation-ssr}/webpack.server.config.js__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr-ts → webpack-module-federation-ssr-ts}/module-federation.server.config.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ssr-ts → webpack-module-federation-ssr-ts}/webpack.server.config.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ts → webpack-module-federation-ts}/module-federation.config.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ts → webpack-module-federation-ts}/webpack.config.prod.ts__tmpl__ +0 -0
- /package/src/generators/host/files/{module-federation-ts → webpack-module-federation-ts}/webpack.config.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation → rspack-module-federation}/module-federation.config.js__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr → rspack-module-federation-ssr}/server.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr-ts → rspack-module-federation-ssr-ts}/server.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation → webpack-module-federation}/webpack.config.js__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation → webpack-module-federation}/webpack.config.prod.js__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr → webpack-module-federation-ssr}/module-federation.server.config.js__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr → webpack-module-federation-ssr}/webpack.server.config.js__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr-ts → webpack-module-federation-ssr-ts}/module-federation.server.config.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → webpack-module-federation-ssr-ts}/tsconfig.lint.json__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ssr-ts → webpack-module-federation-ssr-ts}/webpack.server.config.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → webpack-module-federation-ts}/module-federation.config.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → webpack-module-federation-ts}/webpack.config.prod.ts__tmpl__ +0 -0
- /package/src/generators/remote/files/{module-federation-ts → webpack-module-federation-ts}/webpack.config.ts__tmpl__ +0 -0
@@ -21,11 +21,15 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
21
21
|
// Module federation requires bootstrap code to be dynamically imported.
|
22
22
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
23
23
|
// new entry file.
|
24
|
-
host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
|
25
|
-
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/${options.js
|
24
|
+
host.rename((0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: options.bundler === 'rspack' }, 'src/main.tsx')), (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: options.bundler === 'rspack' }, 'src/bootstrap.tsx')));
|
25
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/${options.js
|
26
|
+
? options.bundler === 'rspack'
|
27
|
+
? 'rspack-common'
|
28
|
+
: 'common'
|
29
|
+
: 'common-ts'}`), options.appProjectRoot, templateVariables);
|
26
30
|
const pathToModuleFederationFiles = options.typescriptConfiguration
|
27
|
-
? 'module-federation-ts
|
28
|
-
: 'module-federation
|
31
|
+
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ts`
|
32
|
+
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation`;
|
29
33
|
// New entry file is created here.
|
30
34
|
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationFiles}`), options.appProjectRoot, templateVariables);
|
31
35
|
function deleteFileIfExists(host, filePath) {
|
@@ -33,17 +37,25 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
|
|
33
37
|
host.delete(filePath);
|
34
38
|
}
|
35
39
|
}
|
36
|
-
function
|
37
|
-
const
|
38
|
-
deleteFileIfExists(host,
|
40
|
+
function processBundlerConfigFile(options, host, fileName) {
|
41
|
+
const pathToBundlerConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, fileName);
|
42
|
+
deleteFileIfExists(host, pathToBundlerConfig);
|
39
43
|
}
|
40
44
|
if (options.typescriptConfiguration) {
|
41
|
-
|
42
|
-
|
45
|
+
if (options.bundler === 'rspack') {
|
46
|
+
processBundlerConfigFile(options, host, 'rspack.config.js');
|
47
|
+
processBundlerConfigFile(options, host, 'rspack.config.prod.js');
|
48
|
+
}
|
49
|
+
else {
|
50
|
+
processBundlerConfigFile(options, host, 'webpack.config.js');
|
51
|
+
processBundlerConfigFile(options, host, 'webpack.config.prod.js');
|
52
|
+
}
|
43
53
|
}
|
44
54
|
if (options.dynamic) {
|
45
|
-
|
46
|
-
|
55
|
+
processBundlerConfigFile(options, host, 'webpack.config.prod.js');
|
56
|
+
processBundlerConfigFile(options, host, 'webpack.config.prod.ts');
|
57
|
+
processBundlerConfigFile(options, host, 'rspack.config.prod.js');
|
58
|
+
processBundlerConfigFile(options, host, 'rspack.config.prod.ts');
|
47
59
|
if (!host.exists(pathToMFManifest)) {
|
48
60
|
host.write(pathToMFManifest, `{
|
49
61
|
${defaultRemoteManifest
|
@@ -6,11 +6,14 @@ const versions_1 = require("../../../utils/versions");
|
|
6
6
|
async function setupSsrForHost(tree, options, appName, defaultRemoteManifest) {
|
7
7
|
const tasks = [];
|
8
8
|
let project = (0, devkit_1.readProjectConfiguration)(tree, appName);
|
9
|
-
project.targets.serve.executor =
|
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';
|
10
13
|
(0, devkit_1.updateProjectConfiguration)(tree, appName, project);
|
11
14
|
const pathToModuleFederationSsrFiles = options.typescriptConfiguration
|
12
|
-
? 'module-federation-ssr-ts
|
13
|
-
: 'module-federation-ssr
|
15
|
+
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
|
16
|
+
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
|
14
17
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, {
|
15
18
|
...options,
|
16
19
|
static: !options?.dynamic,
|
@@ -183,6 +183,14 @@
|
|
183
183
|
"type": "boolean",
|
184
184
|
"default": false,
|
185
185
|
"x-priority": "internal"
|
186
|
+
},
|
187
|
+
"bundler": {
|
188
|
+
"description": "The bundler to use.",
|
189
|
+
"type": "string",
|
190
|
+
"enum": ["rspack", "webpack"],
|
191
|
+
"x-prompt": "Which bundler do you want to use to build the application?",
|
192
|
+
"default": "rspack",
|
193
|
+
"x-priority": "important"
|
186
194
|
}
|
187
195
|
},
|
188
196
|
"required": ["name"],
|
@@ -0,0 +1 @@
|
|
1
|
+
import('./bootstrap');
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './app/app';
|
@@ -0,0 +1,16 @@
|
|
1
|
+
const { composePlugins, withNx, withReact } = require('@nx/rspack');
|
2
|
+
const { withModuleFederation } = require('@nx/rspack/module-federation');
|
3
|
+
|
4
|
+
const baseConfig = require('./module-federation.config');
|
5
|
+
|
6
|
+
const config = {
|
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(), withModuleFederation(config, { dts: false }));
|
@@ -0,0 +1 @@
|
|
1
|
+
module.exports = require('./rspack.config');
|
package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
const {composePlugins, withNx, withReact} = require('@nx/rspack');
|
2
|
+
const {withModuleFederationForSSR} = require('@nx/rspack/module-federation');
|
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 }));
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
+
import {withModuleFederationForSSR} from '@nx/rspack/module-federation';
|
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 }));
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/tsconfig.lint.json__tmpl__
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../dist/out-tsc",
|
5
|
+
"types": [
|
6
|
+
"node",
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
8
|
+
"@nx/react/typings/image.d.ts"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
"include": [
|
12
|
+
"src/**/*.js",
|
13
|
+
"src/**/*.jsx",
|
14
|
+
"src/**/*.ts",
|
15
|
+
"src/**/*.tsx",
|
16
|
+
"rspack.config.ts",
|
17
|
+
"rspack.prod.config.ts"
|
18
|
+
]
|
19
|
+
}
|
package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import {ModuleFederationConfig} from '@nx/rspack/module-federation';
|
2
|
+
|
3
|
+
const config: ModuleFederationConfig = {
|
4
|
+
name: '<%= projectName %>',
|
5
|
+
<% if (dynamic) { %>
|
6
|
+
library: { type: 'var', name: '<%= projectName %>'},
|
7
|
+
<% } %>
|
8
|
+
exposes: {
|
9
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
10
|
+
},
|
11
|
+
};
|
12
|
+
|
13
|
+
export default config;
|
@@ -0,0 +1 @@
|
|
1
|
+
export default require('./rspack.config');
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
+
import {withModuleFederation} from '@nx/rspack/module-federation';
|
3
|
+
|
4
|
+
import baseConfig from './module-federation.config';
|
5
|
+
|
6
|
+
const config = {
|
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(), withModuleFederation(config, { dts: false }));
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../dist/out-tsc",
|
5
|
+
"types": [
|
6
|
+
"node",
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
8
|
+
"@nx/react/typings/image.d.ts"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
"include": [
|
12
|
+
"src/**/*.js",
|
13
|
+
"src/**/*.jsx",
|
14
|
+
"src/**/*.ts",
|
15
|
+
"src/**/*.tsx",
|
16
|
+
"rspack.config.ts",
|
17
|
+
"rspack.prod.config.ts"
|
18
|
+
]
|
19
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import * as path from 'path';
|
2
|
+
import express from 'express';
|
3
|
+
import cors from 'cors';
|
4
|
+
|
5
|
+
import { handleRequest } from './src/main.server';
|
6
|
+
|
7
|
+
const port = process.env['PORT'] || <%= port %>;
|
8
|
+
const app = express();
|
9
|
+
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
|
11
|
+
const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
|
12
|
+
const indexPath = path.join(browserDist, 'index.html');
|
13
|
+
|
14
|
+
app.use(cors());
|
15
|
+
|
16
|
+
// Client-side static bundles
|
17
|
+
app.get(
|
18
|
+
'*.*',
|
19
|
+
express.static(browserDist, {
|
20
|
+
maxAge: '1y',
|
21
|
+
})
|
22
|
+
);
|
23
|
+
|
24
|
+
// Static bundles for server-side module federation
|
25
|
+
app.use('/server',
|
26
|
+
express.static(serverDist, {
|
27
|
+
maxAge: '1y'
|
28
|
+
})
|
29
|
+
);
|
30
|
+
|
31
|
+
app.use('*', handleRequest(indexPath));
|
32
|
+
|
33
|
+
const server = app.listen(port, () => {
|
34
|
+
console.log(`Express server listening on http://localhost:${port}`);
|
35
|
+
|
36
|
+
/**
|
37
|
+
* DO NOT REMOVE IF USING @nx/react:module-federation-dev-ssr executor
|
38
|
+
* to serve your Host application with this Remote application.
|
39
|
+
* This message allows Nx to determine when the Remote is ready to be
|
40
|
+
* consumed by the Host.
|
41
|
+
*/
|
42
|
+
process.send?.('nx.server.ready');
|
43
|
+
});
|
44
|
+
|
45
|
+
server.on('error', console.error);
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import * as path from 'path';
|
2
|
+
import express from 'express';
|
3
|
+
import cors from 'cors';
|
4
|
+
|
5
|
+
import { handleRequest } from './src/main.server';
|
6
|
+
|
7
|
+
const port = process.env['PORT'] || <%= port %>;
|
8
|
+
const app = express();
|
9
|
+
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
|
11
|
+
const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
|
12
|
+
const indexPath = path.join(browserDist, 'index.html');
|
13
|
+
|
14
|
+
app.use(cors());
|
15
|
+
|
16
|
+
// Client-side static bundles
|
17
|
+
app.get(
|
18
|
+
'*.*',
|
19
|
+
express.static(browserDist, {
|
20
|
+
maxAge: '1y',
|
21
|
+
})
|
22
|
+
);
|
23
|
+
|
24
|
+
// Static bundles for server-side module federation
|
25
|
+
app.use('/server',
|
26
|
+
express.static(serverDist, {
|
27
|
+
maxAge: '1y'
|
28
|
+
})
|
29
|
+
);
|
30
|
+
|
31
|
+
app.use('*', handleRequest(indexPath));
|
32
|
+
|
33
|
+
const server = app.listen(port, () => {
|
34
|
+
console.log(`Express server listening on http://localhost:${port}`);
|
35
|
+
|
36
|
+
/**
|
37
|
+
* DO NOT REMOVE IF USING @nx/react:module-federation-dev-ssr executor
|
38
|
+
* to serve your Host application with this Remote application.
|
39
|
+
* This message allows Nx to determine when the Remote is ready to be
|
40
|
+
* consumed by the Host.
|
41
|
+
*/
|
42
|
+
process.send?.('nx.server.ready');
|
43
|
+
});
|
44
|
+
|
45
|
+
server.on('error', console.error);
|
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../dist/out-tsc",
|
5
|
+
"types": [
|
6
|
+
"node",
|
7
|
+
"@nx/react/typings/cssmodule.d.ts",
|
8
|
+
"@nx/react/typings/image.d.ts"
|
9
|
+
]
|
10
|
+
},
|
11
|
+
"include": [
|
12
|
+
"src/**/*.js",
|
13
|
+
"src/**/*.jsx",
|
14
|
+
"src/**/*.ts",
|
15
|
+
"src/**/*.tsx",
|
16
|
+
"webpack.config.ts",
|
17
|
+
"webpack.prod.config.ts"
|
18
|
+
]
|
19
|
+
}
|
@@ -7,8 +7,8 @@ async function setupSsrForRemote(tree, options, appName) {
|
|
7
7
|
const tasks = [];
|
8
8
|
const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
|
9
9
|
const pathToModuleFederationSsrFiles = options.typescriptConfiguration
|
10
|
-
? 'module-federation-ssr-ts
|
11
|
-
: 'module-federation-ssr
|
10
|
+
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr-ts`
|
11
|
+
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ssr`;
|
12
12
|
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, `../files/${pathToModuleFederationSsrFiles}`), project.root, {
|
13
13
|
...options,
|
14
14
|
port: Number(options?.devServerPort) || 4200,
|
@@ -40,11 +40,15 @@ function findAppComponentPath(host, sourceRoot) {
|
|
40
40
|
'app/app.tsx',
|
41
41
|
'app/App.tsx',
|
42
42
|
'app/app.js',
|
43
|
+
'app/app.jsx',
|
43
44
|
'app/App.js',
|
45
|
+
'app/App.jsx',
|
44
46
|
'app.tsx',
|
45
47
|
'App.tsx',
|
46
48
|
'app.js',
|
47
49
|
'App.js',
|
50
|
+
'app.jsx',
|
51
|
+
'App.jsx',
|
48
52
|
];
|
49
53
|
for (const loc of locations) {
|
50
54
|
if (host.exists((0, devkit_1.joinPathFragments)(sourceRoot, loc))) {
|
@@ -23,16 +23,22 @@ function addModuleFederationFiles(host, options) {
|
|
23
23
|
...options,
|
24
24
|
tmpl: '',
|
25
25
|
};
|
26
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js
|
26
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${options.js
|
27
|
+
? options.bundler === 'rspack'
|
28
|
+
? 'rspack-common'
|
29
|
+
: 'common'
|
30
|
+
: 'common-ts'}`), options.appProjectRoot, templateVariables);
|
27
31
|
const pathToModuleFederationFiles = options.typescriptConfiguration
|
28
|
-
? 'module-federation-ts
|
29
|
-
: 'module-federation
|
32
|
+
? `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation-ts`
|
33
|
+
: `${options.bundler === 'rspack' ? 'rspack-' : 'webpack-'}module-federation`;
|
30
34
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/${pathToModuleFederationFiles}`), options.appProjectRoot, templateVariables);
|
31
35
|
if (options.typescriptConfiguration) {
|
32
|
-
const
|
33
|
-
const pathToWebpackProdConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot,
|
34
|
-
|
35
|
-
|
36
|
+
const pathToBundlerConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, options.bundler === 'rspack' ? 'rspack.config.js' : 'webpack.config.js');
|
37
|
+
const pathToWebpackProdConfig = (0, devkit_1.joinPathFragments)(options.appProjectRoot, options.bundler === 'rspack'
|
38
|
+
? 'rspack.config.prod.js'
|
39
|
+
: 'webpack.config.prod.js');
|
40
|
+
if (host.exists(pathToBundlerConfig)) {
|
41
|
+
host.delete(pathToBundlerConfig);
|
36
42
|
}
|
37
43
|
if (host.exists(pathToWebpackProdConfig)) {
|
38
44
|
host.delete(pathToWebpackProdConfig);
|
@@ -57,6 +63,7 @@ async function remoteGeneratorInternal(host, schema) {
|
|
57
63
|
dynamic: schema.dynamic ?? false,
|
58
64
|
// TODO(colum): remove when MF works with Crystal
|
59
65
|
addPlugin: false,
|
66
|
+
bundler: schema.bundler ?? 'rspack',
|
60
67
|
};
|
61
68
|
if (options.dynamic) {
|
62
69
|
// Dynamic remotes generate with library { type: 'var' } by default.
|
@@ -68,8 +75,6 @@ async function remoteGeneratorInternal(host, schema) {
|
|
68
75
|
}
|
69
76
|
const initAppTask = await (0, application_1.default)(host, {
|
70
77
|
...options,
|
71
|
-
// Only webpack works with module federation for now.
|
72
|
-
bundler: 'webpack',
|
73
78
|
skipFormat: true,
|
74
79
|
});
|
75
80
|
tasks.push(initAppTask);
|
@@ -79,7 +84,7 @@ async function remoteGeneratorInternal(host, schema) {
|
|
79
84
|
// Module federation requires bootstrap code to be dynamically imported.
|
80
85
|
// Renaming original entry file so we can use `import(./bootstrap)` in
|
81
86
|
// new entry file.
|
82
|
-
host.rename((0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/main.tsx')), (0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, 'src/bootstrap.tsx')));
|
87
|
+
host.rename((0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: options.bundler === 'rspack' }, 'src/main.tsx')), (0, path_1.join)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: options.bundler === 'rspack' }, 'src/bootstrap.tsx')));
|
83
88
|
addModuleFederationFiles(host, options);
|
84
89
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
85
90
|
(0, setup_tspath_for_remote_1.setupTspathForRemote)(host, options);
|
@@ -88,12 +93,20 @@ async function remoteGeneratorInternal(host, schema) {
|
|
88
93
|
project: options.projectName,
|
89
94
|
serverPort: options.devServerPort,
|
90
95
|
skipFormat: true,
|
96
|
+
bundler: options.bundler,
|
91
97
|
});
|
92
98
|
tasks.push(setupSsrTask);
|
93
99
|
const setupSsrForRemoteTask = await (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
94
100
|
tasks.push(setupSsrForRemoteTask);
|
95
101
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
96
|
-
|
102
|
+
if (options.bundler === 'rspack') {
|
103
|
+
projectConfig.targets.server.executor = '@nx/rspack:rspack';
|
104
|
+
projectConfig.targets.server.options.rspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
105
|
+
delete projectConfig.targets.server.options.webpackConfig;
|
106
|
+
}
|
107
|
+
else {
|
108
|
+
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
109
|
+
}
|
97
110
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
98
111
|
}
|
99
112
|
if (!options.setParserOptionsProject) {
|
@@ -182,6 +182,14 @@
|
|
182
182
|
"type": "boolean",
|
183
183
|
"default": false,
|
184
184
|
"x-priority": "internal"
|
185
|
+
},
|
186
|
+
"bundler": {
|
187
|
+
"description": "The bundler to use.",
|
188
|
+
"type": "string",
|
189
|
+
"enum": ["rspack", "webpack"],
|
190
|
+
"x-prompt": "Which bundler do you want to use to build the application?",
|
191
|
+
"default": "rspack",
|
192
|
+
"x-priority": "important"
|
185
193
|
}
|
186
194
|
},
|
187
195
|
"required": ["name"],
|
@@ -41,6 +41,12 @@
|
|
41
41
|
"hidden": true,
|
42
42
|
"description": "Extra include entries in tsconfig.",
|
43
43
|
"default": []
|
44
|
+
},
|
45
|
+
"bundler": {
|
46
|
+
"description": "The bundler to use.",
|
47
|
+
"type": "string",
|
48
|
+
"enum": ["rspack", "webpack"],
|
49
|
+
"default": "webpack"
|
44
50
|
}
|
45
51
|
},
|
46
52
|
"required": ["project"],
|
@@ -69,7 +69,9 @@ async function setupSsrGenerator(tree, options) {
|
|
69
69
|
...projectConfig.targets,
|
70
70
|
server: {
|
71
71
|
dependsOn: ['build'],
|
72
|
-
executor: '
|
72
|
+
executor: options.bundler === 'rspack'
|
73
|
+
? '@nx/rspack:rspack'
|
74
|
+
: '@nx/webpack:webpack',
|
73
75
|
outputs: ['{options.outputPath}'],
|
74
76
|
defaultConfiguration: 'production',
|
75
77
|
options: {
|
@@ -81,7 +83,11 @@ async function setupSsrGenerator(tree, options) {
|
|
81
83
|
compiler: 'babel',
|
82
84
|
externalDependencies: 'all',
|
83
85
|
outputHashing: 'none',
|
84
|
-
|
86
|
+
...(options.bundler === 'rspack'
|
87
|
+
? { rspackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'rspack.config.js') }
|
88
|
+
: {
|
89
|
+
webpackConfig: (0, devkit_1.joinPathFragments)(projectRoot, 'webpack.config.js'),
|
90
|
+
}),
|
85
91
|
},
|
86
92
|
configurations: {
|
87
93
|
development: {
|
@@ -117,7 +123,9 @@ async function setupSsrGenerator(tree, options) {
|
|
117
123
|
},
|
118
124
|
},
|
119
125
|
serve: {
|
120
|
-
executor: '
|
126
|
+
executor: options.bundler === 'rspack'
|
127
|
+
? '@nx/rspack:ssr-dev-server'
|
128
|
+
: '@nx/webpack:ssr-dev-server',
|
121
129
|
defaultConfiguration: 'development',
|
122
130
|
options: {
|
123
131
|
browserTarget: `${options.project}:build:development`,
|
@@ -10,13 +10,13 @@ async function withModuleFederationForSSR(options, configOverride) {
|
|
10
10
|
isServer: true,
|
11
11
|
});
|
12
12
|
return (config) => {
|
13
|
-
config.target =
|
13
|
+
config.target = 'async-node';
|
14
14
|
config.output.uniqueName = options.name;
|
15
15
|
config.optimization = {
|
16
16
|
...(config.optimization ?? {}),
|
17
17
|
runtimeChunk: false,
|
18
18
|
};
|
19
|
-
config.plugins.push(new (require('@module-federation/
|
19
|
+
config.plugins.push(new (require('@module-federation/enhanced').ModuleFederationPlugin)({
|
20
20
|
name: options.name,
|
21
21
|
filename: 'remoteEntry.js',
|
22
22
|
exposes: options.exposes,
|
@@ -24,10 +24,6 @@ async function withModuleFederationForSSR(options, configOverride) {
|
|
24
24
|
shared: {
|
25
25
|
...sharedDependencies,
|
26
26
|
},
|
27
|
-
library: {
|
28
|
-
type: 'commonjs-module',
|
29
|
-
},
|
30
|
-
isServer: true,
|
31
27
|
/**
|
32
28
|
* Apply user-defined config overrides
|
33
29
|
*/
|
@@ -38,7 +34,11 @@ async function withModuleFederationForSSR(options, configOverride) {
|
|
38
34
|
...(configOverride?.runtimePlugins ?? []),
|
39
35
|
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
40
36
|
]
|
41
|
-
:
|
37
|
+
: [
|
38
|
+
...(configOverride?.runtimePlugins ?? []),
|
39
|
+
require.resolve('@module-federation/node/runtimePlugin'),
|
40
|
+
],
|
41
|
+
virtualRuntimeEntry: true,
|
42
42
|
}, {}), sharedLibraries.getReplacementPlugin());
|
43
43
|
// The env var is only set from the module-federation-dev-server
|
44
44
|
// Attach the runtime plugin
|
@@ -60,6 +60,7 @@ async function withModuleFederation(options, configOverride) {
|
|
60
60
|
require.resolve('@nx/webpack/src/utils/module-federation/plugins/runtime-library-control.plugin.js'),
|
61
61
|
]
|
62
62
|
: configOverride?.runtimePlugins,
|
63
|
+
virtualRuntimeEntry: true,
|
63
64
|
}), sharedLibraries.getReplacementPlugin());
|
64
65
|
// The env var is only set from the module-federation-dev-server
|
65
66
|
// Attach the runtime plugin
|