@nx/react 19.7.0-canary.20240906-a3c2db8 → 19.7.0
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/executors.json +5 -0
- package/package.json +8 -6
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -14
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +2 -60
- package/src/executors/module-federation-dev-server/schema.d.ts +17 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +12 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +240 -0
- package/src/executors/module-federation-static-server/schema.d.ts +3 -0
- package/src/executors/module-federation-static-server/schema.json +14 -0
- 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 +3 -2
- package/src/rules/update-module-federation-project.js +54 -23
- package/src/utils/build-static.remotes.d.ts +4 -0
- package/src/utils/build-static.remotes.js +65 -0
- 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,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
|
*/
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { Tree } from '@nx/devkit';
|
2
2
|
export declare function updateModuleFederationProject(host: Tree, options: {
|
3
3
|
js?: boolean;
|
4
4
|
projectName: string;
|
@@ -6,4 +6,5 @@ export declare function updateModuleFederationProject(host: Tree, options: {
|
|
6
6
|
devServerPort?: number;
|
7
7
|
typescriptConfiguration?: boolean;
|
8
8
|
dynamic?: boolean;
|
9
|
-
|
9
|
+
bundler?: 'rspack' | 'webpack';
|
10
|
+
}): void;
|
@@ -2,48 +2,79 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.updateModuleFederationProject = updateModuleFederationProject;
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
5
|
-
const versions_1 = require("../utils/versions");
|
6
5
|
const maybe_js_1 = require("../utils/maybe-js");
|
7
6
|
function updateModuleFederationProject(host, options) {
|
8
7
|
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
if (options.bundler === 'rspack') {
|
9
|
+
projectConfig.targets.build.executor = '@nx/rspack:rspack';
|
10
|
+
projectConfig.targets.build.options = {
|
11
|
+
...projectConfig.targets.build.options,
|
12
|
+
main: (0, maybe_js_1.maybeJs)({ js: options.js, useJsx: true }, `${options.appProjectRoot}/src/main.ts`),
|
13
|
+
rspackConfig: `${options.appProjectRoot}/rspack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
14
|
+
target: 'web',
|
15
|
+
};
|
16
|
+
projectConfig.targets.build.configurations.production = {
|
17
|
+
...projectConfig.targets.build.configurations.production,
|
18
|
+
rspackConfig: `${options.appProjectRoot}/rspack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
19
|
+
};
|
20
|
+
}
|
21
|
+
else {
|
22
|
+
projectConfig.targets.build.options = {
|
23
|
+
...projectConfig.targets.build.options,
|
24
|
+
main: (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/src/main.ts`),
|
25
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
26
|
+
};
|
27
|
+
projectConfig.targets.build.configurations.production = {
|
28
|
+
...projectConfig.targets.build.configurations.production,
|
29
|
+
webpackConfig: `${options.appProjectRoot}/webpack.config.prod.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`,
|
30
|
+
};
|
31
|
+
}
|
18
32
|
// If host should be configured to use dynamic federation
|
19
33
|
if (options.dynamic) {
|
20
|
-
|
21
|
-
|
22
|
-
host.
|
34
|
+
if (options.bundler === 'rspack') {
|
35
|
+
const pathToProdRspackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `rspack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
36
|
+
if (host.exists(pathToProdRspackConfig)) {
|
37
|
+
host.delete(pathToProdRspackConfig);
|
38
|
+
}
|
39
|
+
delete projectConfig.targets.build.configurations.production
|
40
|
+
?.rspackConfig;
|
23
41
|
}
|
24
|
-
|
42
|
+
else {
|
43
|
+
const pathToProdWebpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, `webpack.prod.config.${options.typescriptConfiguration && !options.js ? 'ts' : 'js'}`);
|
44
|
+
if (host.exists(pathToProdWebpackConfig)) {
|
45
|
+
host.delete(pathToProdWebpackConfig);
|
46
|
+
}
|
47
|
+
delete projectConfig.targets.build.configurations.production
|
48
|
+
?.webpackConfig;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
if (options.bundler === 'rspack') {
|
52
|
+
projectConfig.targets.serve.executor =
|
53
|
+
'@nx/rspack:module-federation-dev-server';
|
54
|
+
}
|
55
|
+
else {
|
56
|
+
projectConfig.targets.serve.executor =
|
57
|
+
'@nx/react:module-federation-dev-server';
|
25
58
|
}
|
26
|
-
projectConfig.targets.serve.executor =
|
27
|
-
'@nx/react:module-federation-dev-server';
|
28
59
|
projectConfig.targets.serve.options.port = options.devServerPort;
|
29
60
|
// `serve-static` for remotes that don't need to be in development mode
|
61
|
+
const serveStaticExecutor = options.bundler === 'rspack'
|
62
|
+
? '@nx/rspack:module-federation-static-server'
|
63
|
+
: '@nx/react:module-federation-static-server';
|
30
64
|
projectConfig.targets['serve-static'] = {
|
31
|
-
executor:
|
65
|
+
executor: serveStaticExecutor,
|
32
66
|
defaultConfiguration: 'production',
|
33
67
|
options: {
|
34
|
-
|
35
|
-
watch: false,
|
36
|
-
port: options.devServerPort,
|
68
|
+
serveTarget: `${options.projectName}:serve`,
|
37
69
|
},
|
38
70
|
configurations: {
|
39
71
|
development: {
|
40
|
-
|
72
|
+
serveTarget: `${options.projectName}:serve:development`,
|
41
73
|
},
|
42
74
|
production: {
|
43
|
-
|
75
|
+
serveTarget: `${options.projectName}:serve:production`,
|
44
76
|
},
|
45
77
|
},
|
46
78
|
};
|
47
79
|
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
48
|
-
return (0, devkit_1.addDependenciesToPackageJson)(host, {}, { '@nx/web': versions_1.nxVersion });
|
49
80
|
}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { StaticRemotesConfig } from '@nx/webpack/src/utils/module-federation/parse-static-remotes-config';
|
2
|
+
import { ExecutorContext } from '@nx/devkit';
|
3
|
+
import { ModuleFederationDevServerOptions } from '../executors/module-federation-dev-server/schema';
|
4
|
+
export declare function buildStaticRemotes(staticRemotesConfig: StaticRemotesConfig, nxBin: any, context: ExecutorContext, options: ModuleFederationDevServerOptions): Promise<Record<string, string>>;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.buildStaticRemotes = buildStaticRemotes;
|
4
|
+
const logger_1 = require("nx/src/utils/logger");
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
6
|
+
const path_1 = require("path");
|
7
|
+
const cache_directory_1 = require("nx/src/utils/cache-directory");
|
8
|
+
const fs_1 = require("fs");
|
9
|
+
async function buildStaticRemotes(staticRemotesConfig, nxBin, context, options) {
|
10
|
+
if (!staticRemotesConfig.remotes.length) {
|
11
|
+
return;
|
12
|
+
}
|
13
|
+
logger_1.logger.info(`NX Building ${staticRemotesConfig.remotes.length} static remotes...`);
|
14
|
+
const mappedLocationOfRemotes = {};
|
15
|
+
for (const app of staticRemotesConfig.remotes) {
|
16
|
+
mappedLocationOfRemotes[app] = `http${options.ssl ? 's' : ''}://${options.host}:${options.staticRemotesPort}/${staticRemotesConfig.config[app].urlSegment}`;
|
17
|
+
}
|
18
|
+
await new Promise((res, rej) => {
|
19
|
+
const staticProcess = (0, node_child_process_1.fork)(nxBin, [
|
20
|
+
'run-many',
|
21
|
+
`--target=build`,
|
22
|
+
`--projects=${staticRemotesConfig.remotes.join(',')}`,
|
23
|
+
...(context.configurationName
|
24
|
+
? [`--configuration=${context.configurationName}`]
|
25
|
+
: []),
|
26
|
+
...(options.parallel ? [`--parallel=${options.parallel}`] : []),
|
27
|
+
], {
|
28
|
+
cwd: context.root,
|
29
|
+
stdio: ['ignore', 'pipe', 'pipe', 'ipc'],
|
30
|
+
});
|
31
|
+
// File to debug build failures e.g. 2024-01-01T00_00_0_0Z-build.log'
|
32
|
+
const remoteBuildLogFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, `${new Date().toISOString().replace(/[:\.]/g, '_')}-build.log`);
|
33
|
+
const stdoutStream = (0, fs_1.createWriteStream)(remoteBuildLogFile);
|
34
|
+
staticProcess.stdout.on('data', (data) => {
|
35
|
+
const ANSII_CODE_REGEX = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g;
|
36
|
+
const stdoutString = data.toString().replace(ANSII_CODE_REGEX, '');
|
37
|
+
stdoutStream.write(stdoutString);
|
38
|
+
// in addition to writing into the stdout stream, also show error directly in console
|
39
|
+
// so the error is easily discoverable. 'ERROR in' is the key word to search in webpack output.
|
40
|
+
if (stdoutString.includes('ERROR in')) {
|
41
|
+
logger_1.logger.log(stdoutString);
|
42
|
+
}
|
43
|
+
if (stdoutString.includes('Successfully ran target build')) {
|
44
|
+
staticProcess.stdout.removeAllListeners('data');
|
45
|
+
logger_1.logger.info(`NX Built ${staticRemotesConfig.remotes.length} static remotes`);
|
46
|
+
res();
|
47
|
+
}
|
48
|
+
});
|
49
|
+
staticProcess.stderr.on('data', (data) => logger_1.logger.info(data.toString()));
|
50
|
+
staticProcess.once('exit', (code) => {
|
51
|
+
stdoutStream.end();
|
52
|
+
staticProcess.stdout.removeAllListeners('data');
|
53
|
+
staticProcess.stderr.removeAllListeners('data');
|
54
|
+
if (code !== 0) {
|
55
|
+
rej(`Remote failed to start. A complete log can be found in: ${remoteBuildLogFile}`);
|
56
|
+
}
|
57
|
+
else {
|
58
|
+
res();
|
59
|
+
}
|
60
|
+
});
|
61
|
+
process.on('SIGTERM', () => staticProcess.kill('SIGTERM'));
|
62
|
+
process.on('exit', () => staticProcess.kill('SIGTERM'));
|
63
|
+
});
|
64
|
+
return mappedLocationOfRemotes;
|
65
|
+
}
|
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
|
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
|