Skip to content

Commit

Permalink
bugfix(react): fix react mfe with ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
xiongemi committed Oct 12, 2023
1 parent 6f2b20f commit dc211ef
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 7 deletions.
27 changes: 27 additions & 0 deletions e2e/react-core/src/react-module-federation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ describe('React Module Federation', () => {
}
}, 500_000);

it('should generate host and remote apps with ssr', async () => {
const shell = uniq('shell');
const remote1 = uniq('remote1');
const remote2 = uniq('remote2');
const remote3 = uniq('remote3');

await runCLIAsync(
`generate @nx/react:host ${shell} --ssr --remotes=${remote1},${remote2},${remote3} --style=css --no-interactive --projectNameAndRootFormat=derived`
);

expect(readPort(shell)).toEqual(4200);
expect(readPort(remote1)).toEqual(4201);
expect(readPort(remote2)).toEqual(4202);
expect(readPort(remote3)).toEqual(4203);

[shell, remote1, remote2, remote3].forEach((app) => {
checkFilesExist(
`apps/${app}/module-federation.config.ts`,
`apps/${app}/module-federation.server.config.ts`
);
['development', 'production'].forEach((configuration) => {
const cliOutput = runCLI(`run ${app}:build:${configuration}`);
expect(cliOutput).toContain('Successfully ran target');
});
});
}, 500_000);

it('should should support generating host and remote apps with the new name and root format', async () => {
const shell = uniq('shell');
const remote = uniq('remote');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export default async function* moduleFederationSsrDevServer(
const remoteServerOutput = join(
workspaceRoot,
remoteProject.targets.server.options.outputPath,
'main.js'
remoteProject.targets.server.options.outputFileName
);
const pm = getPackageManagerCommand();
execSync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"outDir": "../../out-tsc/server",
"target": "es2019",
"types": [
"node"
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"outDir": "../../out-tsc/server",
"target": "es2019",
"types": [
"node"
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
Expand Down
12 changes: 10 additions & 2 deletions packages/react/src/generators/host/host.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ describe('hostGenerator', () => {
compilerOptions: {
outDir: '../../out-tsc/server',
target: 'es2019',
types: ['node'],
types: [
'node',
'@nx/react/typings/cssmodule.d.ts',
'@nx/react/typings/image.d.ts',
],
},
extends: './tsconfig.app.json',
include: ['src/remotes.d.ts', 'src/main.server.tsx', 'server.ts'],
Expand Down Expand Up @@ -138,7 +142,11 @@ describe('hostGenerator', () => {
compilerOptions: {
outDir: '../../out-tsc/server',
target: 'es2019',
types: ['node'],
types: [
'node',
'@nx/react/typings/cssmodule.d.ts',
'@nx/react/typings/image.d.ts',
],
},
extends: './tsconfig.app.json',
include: ['src/remotes.d.ts', 'src/main.server.tsx', 'server.ts'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"outDir": "../../out-tsc/server",
"target": "es2019",
"types": [
"node"
"node",
"@nx/react/typings/cssmodule.d.ts",
"@nx/react/typings/image.d.ts"
]
},
"include": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function* ssrDevServerExecutor(
let nodeStarted = false;
const combined = combineAsyncIterables(runBrowser, runServer);

process.env['port'] = `${options.port}`;
process.env['PORT'] = `${options.port}`;

for await (const output of combined) {
if (!output.success) throw new Error('Could not build application');
Expand Down

0 comments on commit dc211ef

Please sign in to comment.