@nx/react 19.7.0-beta.4 → 19.7.0-beta.6
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/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/utils.js +1 -1
- package/src/module-federation/with-module-federation.js +2 -11
- package/src/rules/update-module-federation-project.d.ts +1 -0
- package/src/rules/update-module-federation-project.js +47 -15
- package/src/utils/maybe-js.d.ts +1 -0
- package/src/utils/maybe-js.js +1 -1
- /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
@@ -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`,
|
@@ -69,7 +69,7 @@ async function getModuleFederationConfig(mfConfig, options = { isServer: false }
|
|
69
69
|
let mappedRemotes = {};
|
70
70
|
if (mfConfig.remotes && mfConfig.remotes.length > 0) {
|
71
71
|
const isLibraryTypeVar = mfConfig.library?.type === 'var';
|
72
|
-
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction,
|
72
|
+
mappedRemotes = mapRemotesFunction(mfConfig.remotes, 'js', determineRemoteUrlFunction, true);
|
73
73
|
}
|
74
74
|
return { sharedLibraries, sharedDependencies, mappedRemotes };
|
75
75
|
}
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.withModuleFederation = withModuleFederation;
|
4
4
|
const utils_1 = require("./utils");
|
5
5
|
const webpack_1 = require("@module-federation/enhanced/webpack");
|
6
|
-
const isVarOrWindow = (libType) => libType === 'var' || libType === 'window';
|
7
6
|
/**
|
8
7
|
* @param {ModuleFederationConfig} options
|
9
8
|
* @return {Promise<AsyncNxComposableWebpackPlugin>}
|
@@ -13,13 +12,10 @@ async function withModuleFederation(options, configOverride) {
|
|
13
12
|
return (config) => config;
|
14
13
|
}
|
15
14
|
const { sharedDependencies, sharedLibraries, mappedRemotes } = await (0, utils_1.getModuleFederationConfig)(options);
|
16
|
-
const isGlobal = isVarOrWindow(options.library?.type);
|
17
15
|
return (config, ctx) => {
|
18
16
|
config.output.uniqueName = options.name;
|
19
17
|
config.output.publicPath = 'auto';
|
20
|
-
|
21
|
-
config.output.scriptType = 'text/javascript';
|
22
|
-
}
|
18
|
+
config.output.scriptType = 'text/javascript';
|
23
19
|
config.optimization = {
|
24
20
|
...(config.optimization ?? {}),
|
25
21
|
runtimeChunk: false,
|
@@ -29,13 +25,8 @@ async function withModuleFederation(options, configOverride) {
|
|
29
25
|
!options.exposes) {
|
30
26
|
config.optimization.runtimeChunk = 'single';
|
31
27
|
}
|
32
|
-
config.experiments = {
|
33
|
-
...config.experiments,
|
34
|
-
outputModule: !isGlobal,
|
35
|
-
};
|
36
28
|
config.plugins.push(new webpack_1.ModuleFederationPlugin({
|
37
29
|
name: options.name,
|
38
|
-
library: options.library ?? { type: 'module' },
|
39
30
|
filename: 'remoteEntry.js',
|
40
31
|
exposes: options.exposes,
|
41
32
|
remotes: mappedRemotes,
|
@@ -48,7 +39,7 @@ async function withModuleFederation(options, configOverride) {
|
|
48
39
|
* { appX: 'appX@http://localhost:3001/remoteEntry.js' }
|
49
40
|
* { appY: 'appY@http://localhost:3002/remoteEntry.js' }
|
50
41
|
*/
|
51
|
-
|
42
|
+
remoteType: 'script',
|
52
43
|
/**
|
53
44
|
* Apply user-defined config overrides
|
54
45
|
*/
|
@@ -6,25 +6,57 @@ const versions_1 = require("../utils/versions");
|
|
6
6
|
const maybe_js_1 = require("../utils/maybe-js");
|
7
7
|
function updateModuleFederationProject(host, options) {
|
8
8
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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.production = {
|
18
|
+
...projectConfig.targets.build.configurations.production,
|
19
|
+
rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
20
|
+
};
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
projectConfig.targets.build.options = {
|
24
|
+
...projectConfig.targets.build.options,
|
25
|
+
main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
|
26
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
27
|
+
};
|
28
|
+
projectConfig.targets.build.configurations.production = {
|
29
|
+
...projectConfig.targets.build.configurations.production,
|
30
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
31
|
+
};
|
32
|
+
}
|
18
33
|
// If host should be configured to use dynamic federation
|
19
34
|
if (options.dynamic) {
|
20
|
-
|
21
|
-
|
22
|
-
host.
|
35
|
+
if (options.bundler === 'rspack') {
|
36
|
+
const pathToProdRspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
37
|
+
if (host.exists(pathToProdRspackConfig)) {
|
38
|
+
host.delete(pathToProdRspackConfig);
|
39
|
+
}
|
40
|
+
delete projectConfig.targets.build.configurations.production
|
41
|
+
?.rspackConfig;
|
23
42
|
}
|
24
|
-
|
43
|
+
else {
|
44
|
+
const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
45
|
+
if (host.exists(pathToProdWebpackConfig)) {
|
46
|
+
host.delete(pathToProdWebpackConfig);
|
47
|
+
}
|
48
|
+
delete projectConfig.targets.build.configurations.production
|
49
|
+
?.webpackConfig;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
if (options.bundler === 'rspack') {
|
53
|
+
projectConfig.targets.serve.executor =
|
54
|
+
'@nx/rspack:module-federation-dev-server';
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
projectConfig.targets.serve.executor =
|
58
|
+
'@nx/react:module-federation-dev-server';
|
25
59
|
}
|
26
|
-
projectConfig.targets.serve.executor =
|
27
|
-
'@nx/react:module-federation-dev-server';
|
28
60
|
projectConfig.targets.serve.options.port = options.devServerPort;
|
29
61
|
// `serve-static` for remotes that don't need to be in development mode
|
30
62
|
projectConfig.targets['serve-static'] = {
|
package/src/utils/maybe-js.d.ts
CHANGED
package/src/utils/maybe-js.js
CHANGED
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.maybeJs = maybeJs;
|
4
4
|
function maybeJs(options, path) {
|
5
5
|
return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
|
6
|
-
? path.replace(/\.tsx?$/, '.js')
|
6
|
+
? path.replace(/\.tsx?$/, options.useJsx ? '.jsx' : '.js')
|
7
7
|
: path;
|
8
8
|
}
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|