@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
package/migrations.json
CHANGED
@@ -229,6 +229,19 @@
|
|
229
229
|
"alwaysAddToPackageJson": false
|
230
230
|
}
|
231
231
|
}
|
232
|
+
},
|
233
|
+
"19.7.0": {
|
234
|
+
"version": "19.7.0-beta.0",
|
235
|
+
"packages": {
|
236
|
+
"@module-federation/enhanced": {
|
237
|
+
"version": "~0.6.0",
|
238
|
+
"alwaysAddToPackageJson": false
|
239
|
+
},
|
240
|
+
"@module-federation/node": {
|
241
|
+
"version": "~2.5.0",
|
242
|
+
"alwaysAddToPackageJson": false
|
243
|
+
}
|
244
|
+
}
|
232
245
|
}
|
233
246
|
}
|
234
247
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nx/react",
|
3
|
-
"version": "19.7.0-beta.
|
3
|
+
"version": "19.7.0-beta.5",
|
4
4
|
"private": false,
|
5
5
|
"description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
|
6
6
|
"repository": {
|
@@ -38,12 +38,12 @@
|
|
38
38
|
"file-loader": "^6.2.0",
|
39
39
|
"minimatch": "9.0.3",
|
40
40
|
"tslib": "^2.3.0",
|
41
|
-
"@module-federation/enhanced": "~0.
|
42
|
-
"@nx/devkit": "19.7.0-beta.
|
43
|
-
"@nx/js": "19.7.0-beta.
|
44
|
-
"@nx/eslint": "19.7.0-beta.
|
45
|
-
"@nx/web": "19.7.0-beta.
|
46
|
-
"@nrwl/react": "19.7.0-beta.
|
41
|
+
"@module-federation/enhanced": "~0.6.0",
|
42
|
+
"@nx/devkit": "19.7.0-beta.5",
|
43
|
+
"@nx/js": "19.7.0-beta.5",
|
44
|
+
"@nx/eslint": "19.7.0-beta.5",
|
45
|
+
"@nx/web": "19.7.0-beta.5",
|
46
|
+
"@nrwl/react": "19.7.0-beta.5"
|
47
47
|
},
|
48
48
|
"publishConfig": {
|
49
49
|
"access": "public"
|
package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js
CHANGED
@@ -28,8 +28,9 @@ function getBuildOptions(buildTarget, context) {
|
|
28
28
|
...buildOptions,
|
29
29
|
};
|
30
30
|
}
|
31
|
-
function startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, options) {
|
31
|
+
async function* startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, options) {
|
32
32
|
if (ssrStaticRemotesConfig.remotes.length === 0) {
|
33
|
+
yield { success: true };
|
33
34
|
return;
|
34
35
|
}
|
35
36
|
// The directories are usually generated with /browser and /server suffixes so we need to copy them to a common directory
|
@@ -55,7 +56,7 @@ function startSsrStaticRemotesFileServer(ssrStaticRemotesConfig, context, option
|
|
55
56
|
sslKey: options.sslKey,
|
56
57
|
cacheSeconds: -1,
|
57
58
|
}, context);
|
58
|
-
|
59
|
+
yield* staticRemotesIter;
|
59
60
|
}
|
60
61
|
async function startRemotes(remotes, context, options) {
|
61
62
|
const remoteIters = [];
|
@@ -176,18 +177,30 @@ async function* moduleFederationSsrDevServer(ssrDevServerOptions, context) {
|
|
176
177
|
pathToKey: options.sslKey,
|
177
178
|
}
|
178
179
|
: undefined);
|
179
|
-
|
180
|
+
const combined = (0, async_iterable_1.combineAsyncIterables)(staticRemotesIter, ...devRemoteIters);
|
181
|
+
let refs = 1 + (devRemoteIters?.length ?? 0);
|
182
|
+
for await (const result of combined) {
|
183
|
+
if (result.success === false)
|
184
|
+
throw new Error('Remotes failed to start');
|
185
|
+
if (result.success)
|
186
|
+
refs--;
|
187
|
+
if (refs === 0)
|
188
|
+
break;
|
189
|
+
}
|
190
|
+
return yield* (0, async_iterable_1.combineAsyncIterables)(iter, (0, async_iterable_1.createAsyncIterable)(async ({ next, done }) => {
|
191
|
+
const host = options.host ?? 'localhost';
|
192
|
+
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
180
193
|
if (!options.isInitialHost) {
|
194
|
+
next({ success: true, baseUrl });
|
181
195
|
done();
|
182
196
|
return;
|
183
197
|
}
|
184
198
|
if (remotes.remotePorts.length === 0) {
|
199
|
+
next({ success: true, baseUrl });
|
185
200
|
done();
|
186
201
|
return;
|
187
202
|
}
|
188
203
|
try {
|
189
|
-
const host = options.host ?? 'localhost';
|
190
|
-
const baseUrl = `http${options.ssl ? 's' : ''}://${host}:${options.port}`;
|
191
204
|
const portsToWaitFor = staticRemotesIter
|
192
205
|
? [options.staticRemotesPort, ...remotes.remotePorts]
|
193
206
|
: [...remotes.remotePorts];
|
@@ -153,7 +153,10 @@ async function applicationGeneratorInternal(host, schema) {
|
|
153
153
|
const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rspack', versions_1.nxRspackVersion);
|
154
154
|
const rspackTask = await configurationGenerator(host, {
|
155
155
|
project: options.projectName,
|
156
|
-
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(
|
156
|
+
main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
|
157
|
+
js: options.js,
|
158
|
+
useJsx: true,
|
159
|
+
}, `src/main.tsx`)),
|
157
160
|
tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
|
158
161
|
target: 'web',
|
159
162
|
newProject: true,
|
@@ -14,7 +14,10 @@ function addRouting(host, options) {
|
|
14
14
|
if (!tsModule) {
|
15
15
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
16
16
|
}
|
17
|
-
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(
|
17
|
+
const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)({
|
18
|
+
js: options.js,
|
19
|
+
useJsx: options.bundler === 'vite' || options.bundler === 'rspack',
|
20
|
+
}, `src/app/${options.fileName}.tsx`));
|
18
21
|
const appFileContent = host.read(appPath, 'utf-8');
|
19
22
|
const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
|
20
23
|
const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
|
@@ -126,7 +126,7 @@ async function createApplicationFiles(host, options) {
|
|
126
126
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, styleSolutionSpecificAppFiles), options.appProjectRoot, templateVariables);
|
127
127
|
if (options.js) {
|
128
128
|
(0, devkit_1.toJS)(host, {
|
129
|
-
useJsx: options.bundler === 'vite',
|
129
|
+
useJsx: options.bundler === 'vite' || options.bundler === 'rspack',
|
130
130
|
});
|
131
131
|
}
|
132
132
|
(0, create_ts_config_1.createTsConfig)(host, options.appProjectRoot, 'app', options, relativePathToRootTsConfig);
|
@@ -140,7 +140,10 @@ function createNxWebpackPluginOptions(options) {
|
|
140
140
|
: options.projectName),
|
141
141
|
index: './src/index.html',
|
142
142
|
baseHref: '/',
|
143
|
-
main: (0, maybe_js_1.maybeJs)(
|
143
|
+
main: (0, maybe_js_1.maybeJs)({
|
144
|
+
js: options.js,
|
145
|
+
useJsx: options.bundler === 'vite' || options.bundler === 'rspack',
|
146
|
+
}, `./src/main.tsx`),
|
144
147
|
tsConfig: './tsconfig.app.json',
|
145
148
|
assets: ['./src/favicon.ico', './src/assets'],
|
146
149
|
styles: options.styledModule || !options.hasStyles
|
@@ -29,6 +29,7 @@ async function federateModuleGenerator(tree, schema) {
|
|
29
29
|
unitTestRunner: schema.unitTestRunner,
|
30
30
|
host: schema.host,
|
31
31
|
projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
|
32
|
+
bundler: schema.bundler ?? 'rspack',
|
32
33
|
});
|
33
34
|
tasks.push(remoteGenerator);
|
34
35
|
const { projectName, projectRoot: remoteRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
|
@@ -46,7 +47,10 @@ async function federateModuleGenerator(tree, schema) {
|
|
46
47
|
remoteName = remote.name;
|
47
48
|
}
|
48
49
|
// add path to exposes property
|
49
|
-
|
50
|
+
const normalizedModulePath = schema.bundler === 'rspack'
|
51
|
+
? (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(projectRoot), schema.path)
|
52
|
+
: schema.path;
|
53
|
+
(0, utils_1.addPathToExposes)(tree, projectRoot, schema.name, normalizedModulePath);
|
50
54
|
// Add new path to tsconfig
|
51
55
|
const rootJSON = (0, devkit_1.readJson)(tree, (0, js_1.getRootTsConfigPathInTree)(tree));
|
52
56
|
if (!rootJSON?.compilerOptions?.paths[`${remoteName}/${schema.name}`]) {
|
@@ -76,6 +76,12 @@
|
|
76
76
|
"host": {
|
77
77
|
"type": "string",
|
78
78
|
"description": "The host / shell application for this remote."
|
79
|
+
},
|
80
|
+
"bundler": {
|
81
|
+
"description": "The bundler to use.",
|
82
|
+
"type": "string",
|
83
|
+
"enum": ["rspack", "webpack"],
|
84
|
+
"default": "rspack"
|
79
85
|
}
|
80
86
|
},
|
81
87
|
"required": ["name", "path", "remote"],
|
@@ -0,0 +1,33 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
<% if (!minimal) { %>
|
3
|
+
import NxWelcome from "./nx-welcome";
|
4
|
+
<% } %>
|
5
|
+
import { Link, Route, Routes } from 'react-router-dom';
|
6
|
+
|
7
|
+
<% if (remotes.length > 0) { %>
|
8
|
+
<% remotes.forEach(function(r) { %>
|
9
|
+
const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
|
10
|
+
<% }); %>
|
11
|
+
<% } %>
|
12
|
+
export function App() {
|
13
|
+
return (
|
14
|
+
<React.Suspense fallback={null}>
|
15
|
+
<ul>
|
16
|
+
<li><Link to="/">Home</Link></li>
|
17
|
+
<% remotes.forEach(function(r) { %>
|
18
|
+
<li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
|
19
|
+
<% }); %>
|
20
|
+
</ul>
|
21
|
+
<Routes>
|
22
|
+
<% if (!minimal) { %>
|
23
|
+
<Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
|
24
|
+
<% } %>
|
25
|
+
<% remotes.forEach(function(r) { %>
|
26
|
+
<Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
|
27
|
+
<% }); %>
|
28
|
+
</Routes>
|
29
|
+
</React.Suspense>
|
30
|
+
);
|
31
|
+
}
|
32
|
+
|
33
|
+
export default App;
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% if (dynamic) { %>
|
2
|
+
import { setRemoteDefinitions } from '@nx/react/mf';
|
3
|
+
|
4
|
+
fetch('/assets/module-federation.manifest.json')
|
5
|
+
.then((res) => res.json())
|
6
|
+
.then(definitions => setRemoteDefinitions(definitions))
|
7
|
+
.then(() => import('./bootstrap').catch(err => console.error(err)));
|
8
|
+
<% } else { %>
|
9
|
+
import('./bootstrap').catch(err => console.error(err));
|
10
|
+
<% } %>
|
@@ -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 for Module Federation
|
13
|
+
* The DTS Plugin can be enabled by setting dts: true
|
14
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
15
|
+
*/
|
16
|
+
module.exports = composePlugins(withNx(), withReact(), withModuleFederation(config, { dts: false }));
|
@@ -0,0 +1,36 @@
|
|
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 prodConfig = {
|
7
|
+
...baseConfig,
|
8
|
+
/*
|
9
|
+
* Remote overrides for production.
|
10
|
+
* Each entry is a pair of a unique name and the URL where it is deployed.
|
11
|
+
*
|
12
|
+
* e.g.
|
13
|
+
* remotes: [
|
14
|
+
* ['app1', 'http://app1.example.com'],
|
15
|
+
* ['app2', 'http://app2.example.com'],
|
16
|
+
* ]
|
17
|
+
*
|
18
|
+
* You can also use a full path to the remoteEntry.js file if desired.
|
19
|
+
*
|
20
|
+
* remotes: [
|
21
|
+
* ['app1', 'http://example.com/path/to/app1/remoteEntry.js'],
|
22
|
+
* ['app2', 'http://example.com/path/to/app2/remoteEntry.js'],
|
23
|
+
* ]
|
24
|
+
*/
|
25
|
+
remotes: [
|
26
|
+
<% remotes.forEach(function(r) {%>['<%= r.fileName %>', 'http://localhost:<%= r.port %>/'],<% }); %>
|
27
|
+
],
|
28
|
+
};
|
29
|
+
|
30
|
+
// Nx plugins for rspack to build config object from Nx options and context.
|
31
|
+
/**
|
32
|
+
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
33
|
+
* The DTS Plugin can be enabled by setting dts: true
|
34
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
35
|
+
*/
|
36
|
+
module.exports = composePlugins(withNx(), withReact(), withModuleFederation(prodConfig, { dts: false }));
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// @ts-check
|
2
|
+
|
3
|
+
/**
|
4
|
+
* @type {import('@nx/rspack/module-federation').ModuleFederationConfig}
|
5
|
+
**/
|
6
|
+
const moduleFederationConfig = {
|
7
|
+
name: '<%= projectName %>',
|
8
|
+
remotes: [
|
9
|
+
<% if (static) {
|
10
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
11
|
+
}
|
12
|
+
%>
|
13
|
+
],
|
14
|
+
};
|
15
|
+
|
16
|
+
module.exports = moduleFederationConfig;
|
package/src/generators/host/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.config');
|
5
|
+
|
6
|
+
const defaultConfig = {
|
7
|
+
...baseConfig
|
8
|
+
};
|
9
|
+
|
10
|
+
// Nx plugins for rspack to build config object from Nx options and context.
|
11
|
+
/**
|
12
|
+
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
13
|
+
* The DTS Plugin can be enabled by setting dts: true
|
14
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
15
|
+
*/
|
16
|
+
module.exports = composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ModuleFederationConfig } from '@nx/rspack/module-federation';
|
2
|
+
|
3
|
+
const config: ModuleFederationConfig = {
|
4
|
+
name: '<%= projectName %>',
|
5
|
+
remotes: [
|
6
|
+
<% if (static) {
|
7
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
8
|
+
}
|
9
|
+
%>
|
10
|
+
],
|
11
|
+
};
|
12
|
+
|
13
|
+
export default config;
|
package/src/generators/host/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.config';
|
5
|
+
|
6
|
+
const defaultConfig = {
|
7
|
+
...baseConfig
|
8
|
+
};
|
9
|
+
|
10
|
+
// Nx plugins for rspack to build config object from Nx options and context.
|
11
|
+
/**
|
12
|
+
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
13
|
+
* The DTS Plugin can be enabled by setting dts: true
|
14
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
15
|
+
*/
|
16
|
+
export default composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig, { dts: false }));
|
package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
import { ModuleFederationConfig } from '@nx/rspack/module-federation';
|
2
|
+
|
3
|
+
const config: ModuleFederationConfig = {
|
4
|
+
name: '<%= projectName %>',
|
5
|
+
/**
|
6
|
+
* To use a remote that does not exist in your current Nx Workspace
|
7
|
+
* You can use the tuple-syntax to define your remote
|
8
|
+
*
|
9
|
+
* remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
|
10
|
+
*
|
11
|
+
* You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
|
12
|
+
* following content:
|
13
|
+
*
|
14
|
+
* declare module 'my-external-remote';
|
15
|
+
*
|
16
|
+
*/
|
17
|
+
remotes: [
|
18
|
+
<% if (static) {
|
19
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
20
|
+
}
|
21
|
+
%>
|
22
|
+
],
|
23
|
+
};
|
24
|
+
|
25
|
+
export default config;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { composePlugins, withNx, withReact } from '@nx/rspack';
|
2
|
+
import { withModuleFederation, ModuleFederationConfig } from '@nx/rspack/module-federation';
|
3
|
+
|
4
|
+
import baseConfig from './module-federation.config';
|
5
|
+
|
6
|
+
const prodConfig: ModuleFederationConfig = {
|
7
|
+
...baseConfig,
|
8
|
+
/*
|
9
|
+
* Remote overrides for production.
|
10
|
+
* Each entry is a pair of a unique name and the URL where it is deployed.
|
11
|
+
*
|
12
|
+
* e.g.
|
13
|
+
* remotes: [
|
14
|
+
* ['app1', 'http://app1.example.com'],
|
15
|
+
* ['app2', 'http://app2.example.com'],
|
16
|
+
* ]
|
17
|
+
*
|
18
|
+
* You can also use a full path to the remoteEntry.js file if desired.
|
19
|
+
*
|
20
|
+
* remotes: [
|
21
|
+
* ['app1', 'http://example.com/path/to/app1/remoteEntry.js'],
|
22
|
+
* ['app2', 'http://example.com/path/to/app2/remoteEntry.js'],
|
23
|
+
* ]
|
24
|
+
*/
|
25
|
+
remotes: [
|
26
|
+
<% remotes.forEach(function(r) {%>['<%= r.fileName %>', 'http://localhost:<%= r.port %>/'],<% }); %>
|
27
|
+
],
|
28
|
+
};
|
29
|
+
|
30
|
+
// Nx plugins for rspack to build config object from Nx options and context.
|
31
|
+
/**
|
32
|
+
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
33
|
+
* The DTS Plugin can be enabled by setting dts: true
|
34
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
35
|
+
*/
|
36
|
+
export default composePlugins(withNx(), withReact(), withModuleFederation(prodConfig, { dts: false }));
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import {composePlugins, withNx, withReact} from '@nx/rspack';
|
2
|
+
import {withModuleFederation, ModuleFederationConfig} from '@nx/rspack/module-federation';
|
3
|
+
|
4
|
+
import baseConfig from './module-federation.config';
|
5
|
+
|
6
|
+
const config: ModuleFederationConfig = {
|
7
|
+
...baseConfig,
|
8
|
+
};
|
9
|
+
|
10
|
+
// Nx plugins for rspack to build config object from Nx options and context.
|
11
|
+
/**
|
12
|
+
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support for Module Federation
|
13
|
+
* The DTS Plugin can be enabled by setting dts: true
|
14
|
+
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
15
|
+
*/
|
16
|
+
export default composePlugins(withNx(), withReact(), withModuleFederation(config, { dts: false }));
|
package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module.exports = {
|
2
|
+
name: '<%= projectName %>',
|
3
|
+
/**
|
4
|
+
* To use a remote that does not exist in your current Nx Workspace
|
5
|
+
* You can use the tuple-syntax to define your remote
|
6
|
+
*
|
7
|
+
* remotes: [['my-external-remote', 'https://nx-angular-remote.netlify.app']]
|
8
|
+
*
|
9
|
+
* You _may_ need to add a `remotes.d.ts` file to your `src/` folder declaring the external remote for tsc, with the
|
10
|
+
* following content:
|
11
|
+
*
|
12
|
+
* declare module 'my-external-remote';
|
13
|
+
*
|
14
|
+
*/
|
15
|
+
remotes: [
|
16
|
+
<% if (static) {
|
17
|
+
remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
|
18
|
+
}
|
19
|
+
%>
|
20
|
+
],
|
21
|
+
};
|
@@ -0,0 +1,28 @@
|
|
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 indexPath = path.join(browserDist, 'index.html');
|
12
|
+
|
13
|
+
app.use(cors());
|
14
|
+
|
15
|
+
app.get(
|
16
|
+
'*.*',
|
17
|
+
express.static(browserDist, {
|
18
|
+
maxAge: '1y',
|
19
|
+
})
|
20
|
+
);
|
21
|
+
|
22
|
+
app.use('*', handleRequest(indexPath));
|
23
|
+
|
24
|
+
const server = app.listen(port, () => {
|
25
|
+
console.log(`Express server listening on http://localhost:${port}`);
|
26
|
+
});
|
27
|
+
|
28
|
+
server.on('error', console.error);
|
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.app.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../out-tsc/server",
|
5
|
+
"target": "es2019",
|
6
|
+
"types": [
|
7
|
+
"node",
|
8
|
+
"@nx/react/typings/cssmodule.d.ts",
|
9
|
+
"@nx/react/typings/image.d.ts"
|
10
|
+
]
|
11
|
+
},
|
12
|
+
"include": [
|
13
|
+
"src/remotes.d.ts",
|
14
|
+
"src/main.server.tsx",
|
15
|
+
"server.ts"
|
16
|
+
]
|
17
|
+
}
|
@@ -0,0 +1,28 @@
|
|
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 indexPath = path.join(browserDist, 'index.html');
|
12
|
+
|
13
|
+
app.use(cors());
|
14
|
+
|
15
|
+
app.get(
|
16
|
+
'*.*',
|
17
|
+
express.static(browserDist, {
|
18
|
+
maxAge: '1y',
|
19
|
+
})
|
20
|
+
);
|
21
|
+
|
22
|
+
app.use('*', handleRequest(indexPath));
|
23
|
+
|
24
|
+
const server = app.listen(port, () => {
|
25
|
+
console.log(`Express server listening on http://localhost:${port}`);
|
26
|
+
});
|
27
|
+
|
28
|
+
server.on('error', console.error);
|
package/src/generators/host/files/webpack-module-federation-ssr-ts/tsconfig.server.json__tmpl__
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
{
|
2
|
+
"extends": "./tsconfig.app.json",
|
3
|
+
"compilerOptions": {
|
4
|
+
"outDir": "../../out-tsc/server",
|
5
|
+
"target": "es2019",
|
6
|
+
"types": [
|
7
|
+
"node",
|
8
|
+
"@nx/react/typings/cssmodule.d.ts",
|
9
|
+
"@nx/react/typings/image.d.ts"
|
10
|
+
]
|
11
|
+
},
|
12
|
+
"include": [
|
13
|
+
"src/remotes.d.ts",
|
14
|
+
"src/main.server.tsx",
|
15
|
+
"server.ts"
|
16
|
+
]
|
17
|
+
}
|
@@ -32,6 +32,7 @@ async function hostGeneratorInternal(host, schema) {
|
|
32
32
|
dynamic: schema.dynamic ?? false,
|
33
33
|
// TODO(colum): remove when MF works with Crystal
|
34
34
|
addPlugin: false,
|
35
|
+
bundler: schema.bundler ?? 'rspack',
|
35
36
|
};
|
36
37
|
// Check to see if remotes are provided and also check if --dynamic is provided
|
37
38
|
// if both are check that the remotes are valid names else throw an error.
|
@@ -47,8 +48,6 @@ async function hostGeneratorInternal(host, schema) {
|
|
47
48
|
...options,
|
48
49
|
// The target use-case is loading remotes as child routes, thus always enable routing.
|
49
50
|
routing: true,
|
50
|
-
// Only webpack works with module federation for now.
|
51
|
-
bundler: 'webpack',
|
52
51
|
skipFormat: true,
|
53
52
|
});
|
54
53
|
tasks.push(initTask);
|
@@ -74,6 +73,7 @@ async function hostGeneratorInternal(host, schema) {
|
|
74
73
|
dynamic: options.dynamic,
|
75
74
|
host: options.name,
|
76
75
|
skipPackageJson: options.skipPackageJson,
|
76
|
+
bundler: options.bundler,
|
77
77
|
});
|
78
78
|
tasks.push(remoteTask);
|
79
79
|
remotePort++;
|
@@ -92,7 +92,14 @@ async function hostGeneratorInternal(host, schema) {
|
|
92
92
|
const setupSsrForHostTask = await (0, setup_ssr_for_host_1.setupSsrForHost)(host, options, options.projectName, remotesWithPorts);
|
93
93
|
tasks.push(setupSsrForHostTask);
|
94
94
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
95
|
-
|
95
|
+
if (options.bundler === 'rspack') {
|
96
|
+
projectConfig.targets.server.executor = '@nx/rspack:rspack';
|
97
|
+
projectConfig.targets.server.options.rspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
98
|
+
delete projectConfig.targets.server.options.webpackConfig;
|
99
|
+
}
|
100
|
+
else {
|
101
|
+
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.server.config.${options.typescriptConfiguration ? 'ts' : 'js'}`);
|
102
|
+
}
|
96
103
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
97
104
|
}
|
98
105
|
if (!options.setParserOptionsProject) {
|