-
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.
feat(react): switch default to typescript configuration for module fe…
…deration (#19031)
- Loading branch information
Showing
35 changed files
with
823 additions
and
43 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
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
128 changes: 128 additions & 0 deletions
128
packages/react/src/generators/host/__snapshots__/host.spec.ts.snap
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,128 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`hostGenerator should generate host files and configs 1`] = ` | ||
"const { composePlugins, withNx } = require('@nx/webpack'); | ||
const { withReact } = require('@nx/react'); | ||
const { withModuleFederation } = require('@nx/react/module-federation'); | ||
const baseConfig = require('./module-federation.config'); | ||
const config = { | ||
...baseConfig, | ||
}; | ||
// Nx plugins for webpack to build config object from Nx options and context. | ||
module.exports = composePlugins( | ||
withNx(), | ||
withReact(), | ||
withModuleFederation(config) | ||
); | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs 2`] = ` | ||
"module.exports = { | ||
name: 'test', | ||
remotes: [], | ||
}; | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs for SSR 1`] = ` | ||
"const { composePlugins, withNx } = require('@nx/webpack'); | ||
const { withReact } = require('@nx/react'); | ||
const { withModuleFederationForSSR } = require('@nx/react/module-federation'); | ||
const baseConfig = require('./module-federation.config'); | ||
const defaultConfig = { | ||
...baseConfig, | ||
}; | ||
// Nx plugins for webpack to build config object from Nx options and context. | ||
module.exports = composePlugins( | ||
withNx(), | ||
withReact({ ssr: true }), | ||
withModuleFederationForSSR(defaultConfig) | ||
); | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs for SSR 2`] = ` | ||
"// @ts-check | ||
/** | ||
* @type {import('@nx/webpack').ModuleFederationConfig} | ||
**/ | ||
const moduleFederationConfig = { | ||
name: 'test', | ||
remotes: [], | ||
}; | ||
module.exports = moduleFederationConfig; | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs for SSR when --typescriptConfiguration=true 1`] = ` | ||
"import { composePlugins, withNx } from '@nx/webpack'; | ||
import { withReact } from '@nx/react'; | ||
import { withModuleFederationForSSR } from '@nx/react/module-federation'; | ||
import baseConfig from './module-federation.config'; | ||
const defaultConfig = { | ||
...baseConfig, | ||
}; | ||
// Nx plugins for webpack to build config object from Nx options and context. | ||
export default composePlugins( | ||
withNx(), | ||
withReact({ ssr: true }), | ||
withModuleFederationForSSR(defaultConfig) | ||
); | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs for SSR when --typescriptConfiguration=true 2`] = ` | ||
"import { ModuleFederationConfig } from '@nx/webpack'; | ||
const config: ModuleFederationConfig = { | ||
name: 'test', | ||
remotes: [], | ||
}; | ||
export default config; | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs when --typescriptConfiguration=true 1`] = ` | ||
"import { composePlugins, withNx } from '@nx/webpack'; | ||
import { withReact } from '@nx/react'; | ||
import { withModuleFederation } from '@nx/react/module-federation'; | ||
import baseConfig from './module-federation.config'; | ||
const config = { | ||
...baseConfig, | ||
}; | ||
// Nx plugins for webpack to build config object from Nx options and context. | ||
export default composePlugins( | ||
withNx(), | ||
withReact(), | ||
withModuleFederation(config) | ||
); | ||
" | ||
`; | ||
|
||
exports[`hostGenerator should generate host files and configs when --typescriptConfiguration=true 2`] = ` | ||
"import { ModuleFederationConfig } from '@nx/webpack'; | ||
const config: ModuleFederationConfig = { | ||
name: 'test', | ||
remotes: [], | ||
}; | ||
export default config; | ||
" | ||
`; |
10 changes: 10 additions & 0 deletions
10
...generators/host/files/module-federation-ssr-ts/module-federation.server.config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ModuleFederationConfig } from '@nx/webpack'; | ||
|
||
const config: ModuleFederationConfig = { | ||
name: '<%= projectName %>', | ||
remotes: [ | ||
<% remotes.forEach(function(r) {%> "<%= r.fileName %>", <% }); %> | ||
], | ||
}; | ||
|
||
export default config; |
28 changes: 28 additions & 0 deletions
28
packages/react/src/generators/host/files/module-federation-ssr-ts/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as path from 'path'; | ||
import express from 'express'; | ||
import cors from 'cors'; | ||
|
||
import { handleRequest } from './src/main.server'; | ||
|
||
const port = process.env['PORT'] || 4200; | ||
const app = express(); | ||
|
||
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>'); | ||
const indexPath = path.join(browserDist, 'index.html'); | ||
|
||
app.use(cors()); | ||
|
||
app.get( | ||
'*.*', | ||
express.static(browserDist, { | ||
maxAge: '1y', | ||
}) | ||
); | ||
|
||
app.use('*', handleRequest(indexPath)); | ||
|
||
const server = app.listen(port, () => { | ||
console.log(`Express server listening on http://localhost:${port}`); | ||
}); | ||
|
||
server.on('error', console.error); |
15 changes: 15 additions & 0 deletions
15
...ges/react/src/generators/host/files/module-federation-ssr-ts/tsconfig.server.json__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,15 @@ | ||
{ | ||
"extends": "./tsconfig.app.json", | ||
"compilerOptions": { | ||
"outDir": "../../out-tsc/server", | ||
"target": "es2019", | ||
"types": [ | ||
"node" | ||
] | ||
}, | ||
"include": [ | ||
"src/remotes.d.ts", | ||
"src/main.server.tsx", | ||
"server.ts" | ||
] | ||
} |
12 changes: 12 additions & 0 deletions
12
...react/src/generators/host/files/module-federation-ssr-ts/webpack.server.config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {composePlugins, withNx} from '@nx/webpack'; | ||
import {withReact} from '@nx/react'; | ||
import {withModuleFederationForSSR} from '@nx/react/module-federation'; | ||
|
||
import baseConfig from './module-federation.config'; | ||
|
||
const defaultConfig = { | ||
...baseConfig | ||
}; | ||
|
||
// Nx plugins for webpack to build config object from Nx options and context. | ||
export default composePlugins(withNx(), withReact({ssr: true}), withModuleFederationForSSR(defaultConfig)); |
10 changes: 10 additions & 0 deletions
10
.../react/src/generators/host/files/module-federation-ts/module-federation.config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ModuleFederationConfig } from '@nx/webpack'; | ||
|
||
const config: ModuleFederationConfig = { | ||
name: '<%= projectName %>', | ||
remotes: [ | ||
<% remotes.forEach(function(r) {%> "<%= r.fileName %>", <% }); %> | ||
], | ||
}; | ||
|
||
export default config; |
1 change: 1 addition & 0 deletions
1
packages/react/src/generators/host/files/module-federation-ts/src/main.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import('./bootstrap'); |
4 changes: 4 additions & 0 deletions
4
packages/react/src/generators/host/files/module-federation-ts/src/remotes.d.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// Declare your remote Modules here | ||
// Example declare module 'about/Module'; | ||
|
||
<% remotes.forEach(function(r) { %>declare module '<%= r.fileName %>/Module';<% }); %> |
32 changes: 32 additions & 0 deletions
32
packages/react/src/generators/host/files/module-federation-ts/webpack.config.prod.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { composePlugins, withNx } from '@nx/webpack'; | ||
import { withReact } from '@nx/react'; | ||
import { withModuleFederation } from '@nx/react/module-federation'; | ||
|
||
import baseConfig from './module-federation.config'; | ||
|
||
const prodConfig = { | ||
...baseConfig, | ||
/* | ||
* Remote overrides for production. | ||
* Each entry is a pair of a unique name and the URL where it is deployed. | ||
* | ||
* e.g. | ||
* remotes: [ | ||
* ['app1', 'http://app1.example.com'], | ||
* ['app2', 'http://app2.example.com'], | ||
* ] | ||
* | ||
* You can also use a full path to the remoteEntry.js file if desired. | ||
* | ||
* remotes: [ | ||
* ['app1', 'http://example.com/path/to/app1/remoteEntry.js'], | ||
* ['app2', 'http://example.com/path/to/app2/remoteEntry.js'], | ||
* ] | ||
*/ | ||
remotes: [ | ||
<% remotes.forEach(function(r) {%>['<%= r.fileName %>', 'http://localhost:<%= r.port %>/'],<% }); %> | ||
], | ||
}; | ||
|
||
// Nx plugins for webpack to build config object from Nx options and context. | ||
export default composePlugins(withNx(), withReact(), withModuleFederation(prodConfig)); |
12 changes: 12 additions & 0 deletions
12
packages/react/src/generators/host/files/module-federation-ts/webpack.config.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {composePlugins, withNx} from '@nx/webpack'; | ||
import {withReact} from '@nx/react'; | ||
import {withModuleFederation} from '@nx/react/module-federation'; | ||
|
||
import baseConfig from './module-federation.config'; | ||
|
||
const config = { | ||
...baseConfig, | ||
}; | ||
|
||
// Nx plugins for webpack to build config object from Nx options and context. | ||
export default composePlugins(withNx(), withReact(), withModuleFederation(config)); |
Oops, something went wrong.
11fcb8f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nx-dev – ./
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx-dev-nrwl.vercel.app
nx.dev