-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
270 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...rc/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// @ts-check | ||
|
||
/** | ||
* @type {import('@nrwl/devkit').ModuleFederationConfig} | ||
**/ | ||
const moduleFederationConfig = { | ||
name: '<%= projectName %>', | ||
remotes: [ | ||
<% remotes.forEach(function(r) {%> "<%= r.fileName %>", <% }); %> | ||
], | ||
}; | ||
|
||
module.exports = moduleFederationConfig; |
8 changes: 8 additions & 0 deletions
8
...es/react/src/generators/host/files/module-federation-ssr/webpack.server.config.js__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const { withModuleFederationForSSR } = require('@nrwl/react/module-federation'); | ||
const baseConfig = require("./module-federation.server.config"); | ||
|
||
const defaultConfig = { | ||
...baseConfig | ||
}; | ||
|
||
module.exports = withModuleFederationForSSR(defaultConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import type { Tree } from '@nrwl/devkit'; | ||
import { readJson } from '@nrwl/devkit'; | ||
import { createTreeWithEmptyWorkspace } from '@nrwl/devkit/testing'; | ||
import hostGenerator from './host'; | ||
import { Linter } from '@nrwl/linter'; | ||
|
||
describe('hostGenerator', () => { | ||
let tree: Tree; | ||
|
||
beforeEach(() => { | ||
tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); | ||
}); | ||
|
||
it('should generate host files and configs', async () => { | ||
await hostGenerator(tree, { | ||
name: 'test', | ||
style: 'css', | ||
linter: Linter.None, | ||
unitTestRunner: 'none', | ||
e2eTestRunner: 'none', | ||
}); | ||
|
||
expect(tree.exists('apps/test/tsconfig.json')); | ||
expect(tree.exists('apps/test/webpack.config.prod.js')); | ||
expect(tree.exists('apps/test/webpack.config.js')); | ||
expect(tree.exists('apps/test/src/bootstrap.tsx')); | ||
expect(tree.exists('apps/test/src/main.ts')); | ||
expect(tree.exists('apps/test/src/remotes.d.ts')); | ||
}); | ||
|
||
it('should generate host files and configs for SSR', async () => { | ||
await hostGenerator(tree, { | ||
name: 'test', | ||
ssr: true, | ||
style: 'css', | ||
linter: Linter.None, | ||
unitTestRunner: 'none', | ||
e2eTestRunner: 'none', | ||
}); | ||
|
||
expect(tree.exists('apps/test/tsconfig.json')); | ||
expect(tree.exists('apps/test/webpack.config.prod.js')); | ||
expect(tree.exists('apps/test/webpack.config.server.js')); | ||
expect(tree.exists('apps/test/webpack.config.js')); | ||
expect(tree.exists('apps/test/src/main.server.tsx')); | ||
expect(tree.exists('apps/test/src/bootstrap.tsx')); | ||
expect(tree.exists('apps/test/src/main.ts')); | ||
expect(tree.exists('apps/test/src/remotes.d.ts')); | ||
|
||
expect(readJson(tree, 'apps/test/tsconfig.server.json')).toEqual({ | ||
compilerOptions: { | ||
outDir: '../../out-tsc/server', | ||
target: 'es2019', | ||
types: ['node'], | ||
}, | ||
extends: './tsconfig.app.json', | ||
files: ['src/main.server.tsx', 'server.ts'], | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import type { GeneratorCallback, Tree } from '@nrwl/devkit'; | ||
import { | ||
addDependenciesToPackageJson, | ||
generateFiles, | ||
joinPathFragments, | ||
names, | ||
readProjectConfiguration, | ||
} from '@nrwl/devkit'; | ||
import type { Schema } from '../schema'; | ||
import { moduleFederationNodeVersion } from '../../../utils/versions'; | ||
import { runTasksInSerial } from '@nrwl/workspace/src/utilities/run-tasks-in-serial'; | ||
import { normalizeProjectName } from '@nrwl/react/src/generators/application/lib/normalize-options'; | ||
|
||
export async function addSsrFiles( | ||
tree: Tree, | ||
options: Schema, | ||
appName: string, | ||
defaultRemoteManifest: { name: string; port: number }[] | ||
) { | ||
const tasks: GeneratorCallback[] = []; | ||
const project = readProjectConfiguration(tree, appName); | ||
|
||
generateFiles( | ||
tree, | ||
joinPathFragments(__dirname, '../files/module-federation-ssr'), | ||
project.root, | ||
{ | ||
...options, | ||
remotes: defaultRemoteManifest.map(({ name, port }) => { | ||
const remote = normalizeProjectName({ ...options, name }); | ||
return { | ||
...names(remote), | ||
port, | ||
}; | ||
}), | ||
appName, | ||
tmpl: '', | ||
} | ||
); | ||
|
||
const installTask = addDependenciesToPackageJson( | ||
tree, | ||
{ | ||
'@module-federation/node': moduleFederationNodeVersion, | ||
}, | ||
{} | ||
); | ||
tasks.push(installTask); | ||
|
||
return runTasksInSerial(...tasks); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 11 additions & 7 deletions
18
packages/react/src/generators/setup-ssr/files/server.ts__tmpl__
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ | |
"node" | ||
] | ||
}, | ||
"include": [ | ||
"files": [ | ||
"src/main.server.tsx", | ||
"server.ts", | ||
"server.ts" | ||
] | ||
} |
Oops, something went wrong.