Skip to content

Commit f045199

Browse files
authoredOct 4, 2023
feat(react): use JS webpack config files for module federation (#19452)
1 parent 854d8b8 commit f045199

File tree

5 files changed

+37
-41
lines changed

5 files changed

+37
-41
lines changed
 

‎docs/generated/packages/react/generators/host.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
"typescriptConfiguration": {
165165
"type": "boolean",
166166
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
167-
"default": true
167+
"default": false
168168
}
169169
},
170170
"required": ["name"],

‎docs/generated/packages/react/generators/remote.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
"typescriptConfiguration": {
163163
"type": "boolean",
164164
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
165-
"default": true
165+
"default": false
166166
}
167167
},
168168
"required": ["name"],

‎e2e/react-core/src/react-module-federation.test.ts

+33-37
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { stripIndents } from '@nx/devkit';
22
import {
33
checkFilesExist,
44
cleanupProject,
5+
killPorts,
56
killProcessAndPorts,
67
newProject,
78
readJson,
@@ -39,10 +40,10 @@ describe('React Module Federation', () => {
3940
`generate @nx/react:remote ${remote3} --style=css --host=${shell} --no-interactive`
4041
);
4142

42-
checkFilesExist(`apps/${shell}/module-federation.config.ts`);
43-
checkFilesExist(`apps/${remote1}/module-federation.config.ts`);
44-
checkFilesExist(`apps/${remote2}/module-federation.config.ts`);
45-
checkFilesExist(`apps/${remote3}/module-federation.config.ts`);
43+
checkFilesExist(`apps/${shell}/module-federation.config.js`);
44+
checkFilesExist(`apps/${remote1}/module-federation.config.js`);
45+
checkFilesExist(`apps/${remote2}/module-federation.config.js`);
46+
checkFilesExist(`apps/${remote3}/module-federation.config.js`);
4647

4748
await expect(runCLIAsync(`test ${shell}`)).resolves.toMatchObject({
4849
combinedOutput: expect.stringContaining('Test Suites: 1 passed, 1 total'),
@@ -54,15 +55,15 @@ describe('React Module Federation', () => {
5455
expect(readPort(remote3)).toEqual(4203);
5556

5657
updateFile(
57-
`apps/${shell}/webpack.config.ts`,
58+
`apps/${shell}/webpack.config.js`,
5859
stripIndents`
59-
import { composePlugins, withNx, ModuleFederationConfig } from '@nx/webpack';
60-
import { withReact } from '@nx/react';
61-
import { withModuleFederation } from '@nx/react/module-federation');
60+
const { composePlugins, withNx, ModuleFederationConfig } = require('@nx/webpack');
61+
const { withReact } = require('@nx/react');
62+
const { withModuleFederation } = require('@nx/react/module-federation');
6263
6364
const baseConfig = require('./module-federation.config');
6465
65-
const config: ModuleFederationConfig = {
66+
const config = {
6667
...baseConfig,
6768
remotes: [
6869
'${remote1}',
@@ -106,20 +107,15 @@ describe('React Module Federation', () => {
106107
});
107108
`
108109
);
109-
// TODO(caleb): cypress isn't able to find the element and then throws error with an address already in use error.
110-
// https://staging.nx.app/runs/ASAokpXhnE/task/e2e-react:e2e
111-
// if (runCypressTests()) {
112-
// const e2eResults = runCLI(`e2e ${shell}-e2e --no-watch --verbose`);
113-
// expect(e2eResults).toContain('All specs passed!');
114-
// expect(
115-
// await killPorts([
116-
// readPort(shell),
117-
// readPort(remote1),
118-
// readPort(remote2),
119-
// readPort(remote3),
120-
// ])
121-
// ).toBeTruthy();
122-
// }
110+
111+
if (runE2ETests()) {
112+
const e2eResults = runCLI(`e2e ${shell}-e2e --no-watch --verbose`);
113+
expect(e2eResults).toContain('All specs passed!');
114+
await killPorts(readPort(shell));
115+
await killPorts(readPort(remote1));
116+
await killPorts(readPort(remote2));
117+
await killPorts(readPort(remote3));
118+
}
123119
}, 500_000);
124120

125121
it('should should support generating host and remote apps with the new name and root format', async () => {
@@ -136,8 +132,8 @@ describe('React Module Federation', () => {
136132

137133
// check files are generated without the layout directory ("apps/") and
138134
// using the project name as the directory when no directory is provided
139-
checkFilesExist(`${shell}/module-federation.config.ts`);
140-
checkFilesExist(`${remote}/module-federation.config.ts`);
135+
checkFilesExist(`${shell}/module-federation.config.js`);
136+
checkFilesExist(`${remote}/module-federation.config.js`);
141137

142138
// check default generated host is built successfully
143139
const buildOutput = runCLI(`run ${shell}:build:development`);
@@ -304,45 +300,45 @@ describe('React Module Federation', () => {
304300

305301
// update host and remote to use library type var
306302
updateFile(
307-
`${shell}/module-federation.config.ts`,
303+
`${shell}/module-federation.config.js`,
308304
stripIndents`
309-
import { ModuleFederationConfig } from '@nx/webpack';
305+
const { ModuleFederationConfig } = require('@nx/webpack');
310306
311-
const config: ModuleFederationConfig = {
307+
const config = {
312308
name: '${shell}',
313309
library: { type: 'var', name: '${shell}' },
314310
remotes: ['${remote}'],
315311
};
316312
317-
export default config;
313+
module.exports = config;
318314
`
319315
);
320316

321317
updateFile(
322-
`${shell}/webpack.config.prod.ts`,
323-
`export { default } from './webpack.config';`
318+
`${shell}/webpack.config.prod.js`,
319+
`module.exports = require('./webpack.config');`
324320
);
325321

326322
updateFile(
327-
`${remote}/module-federation.config.ts`,
323+
`${remote}/module-federation.config.js`,
328324
stripIndents`
329-
import { ModuleFederationConfig } from '@nx/webpack';
325+
const { ModuleFederationConfig } = require('@nx/webpack');
330326
331-
const config: ModuleFederationConfig = {
327+
const config = {
332328
name: '${remote}',
333329
library: { type: 'var', name: '${remote}' },
334330
exposes: {
335331
'./Module': './src/remote-entry.ts',
336332
},
337333
};
338334
339-
export default config;
335+
module.exports = config;
340336
`
341337
);
342338

343339
updateFile(
344-
`${remote}/webpack.config.prod.ts`,
345-
`export { default } from './webpack.config';`
340+
`${remote}/webpack.config.prod.js`,
341+
`module.exports = require('./webpack.config');`
346342
);
347343

348344
// Update host e2e test to check that the remote works with library type var via navigation

‎packages/react/src/generators/host/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@
170170
"typescriptConfiguration": {
171171
"type": "boolean",
172172
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
173-
"default": true
173+
"default": false
174174
}
175175
},
176176
"required": ["name"],

‎packages/react/src/generators/remote/schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@
168168
"typescriptConfiguration": {
169169
"type": "boolean",
170170
"description": "Whether the module federation configuration and webpack configuration files should use TS.",
171-
"default": true
171+
"default": false
172172
}
173173
},
174174
"required": ["name"],

1 commit comments

Comments
 (1)

vercel[bot] commented on Oct 4, 2023

@vercel[bot]

Successfully deployed to the following URLs:

nx-dev – ./

nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx.dev
nx-dev-nrwl.vercel.app

Please sign in to comment.