@nx/react 20.0.7 → 20.1.0-beta.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.
Files changed (68) hide show
  1. package/mf/dynamic-federation.d.ts +64 -0
  2. package/mf/dynamic-federation.js +64 -0
  3. package/package.json +6 -6
  4. package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  5. package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +27 -6
  6. package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +1 -1
  7. package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  8. package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +31 -6
  9. package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +1 -1
  10. package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
  11. package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +22 -2
  12. package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +1 -1
  13. package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +3 -3
  14. package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +26 -16
  15. package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +29 -20
  16. package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +26 -16
  17. package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +31 -22
  18. package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +30 -21
  19. package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +30 -18
  20. package/src/generators/application/lib/create-application-files.js +2 -0
  21. package/src/generators/application/lib/get-app-tests.js +8 -9
  22. package/src/generators/component/files/__fileName__.tsx__tmpl__ +55 -56
  23. package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +5 -5
  24. package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +3 -4
  25. package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +28 -21
  26. package/src/generators/host/files/common/src/main.js__tmpl__ +12 -9
  27. package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +28 -28
  28. package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +12 -9
  29. package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +22 -13
  30. package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +12 -9
  31. package/src/generators/host/files/rspack-module-federation/module-federation.config.js__tmpl__ +4 -4
  32. package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +3 -1
  33. package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -4
  34. package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  35. package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -6
  36. package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  37. package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +18 -18
  38. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +23 -21
  39. package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  40. package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__ +4 -4
  41. package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +23 -21
  42. package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -6
  43. package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  44. package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +6 -6
  45. package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  46. package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +18 -18
  47. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +23 -21
  48. package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  49. package/src/generators/host/host.js +3 -1
  50. package/src/generators/host/lib/add-module-federation-files.js +1 -1
  51. package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +1 -1
  52. package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +1 -1
  53. package/src/generators/remote/files/rspack-module-federation/module-federation.config.js__tmpl__ +7 -7
  54. package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +4 -4
  55. package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +1 -1
  56. package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +4 -4
  57. package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +1 -1
  58. package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +7 -7
  59. package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
  60. package/src/generators/remote/files/webpack-module-federation/module-federation.config.js__tmpl__ +7 -7
  61. package/src/generators/remote/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +4 -4
  62. package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +1 -1
  63. package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +4 -4
  64. package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
  65. package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +7 -7
  66. package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
  67. package/src/utils/versions.d.ts +1 -1
  68. package/src/utils/versions.js +1 -1
@@ -1,39 +1,48 @@
1
- <% if (classComponent) { %>
1
+ <%_ if (classComponent) { _%>
2
2
  import { Component } from 'react';
3
- <% } %>
3
+ <%_ } _%>
4
4
  import styled from '<%= styledModule %>';
5
- <% if (!minimal) { %>
5
+ <%_ if (!minimal) { _%>
6
6
  import NxWelcome from "./nx-welcome";
7
- <% } %>
7
+ <%_ } _%>
8
8
 
9
9
  const StyledApp = styled.div`
10
10
  // Your style here
11
11
  `;
12
12
 
13
- <% if (classComponent) { %>
13
+ <%_ if (classComponent) { _%>
14
14
  export class App extends Component {
15
- render() {
16
- <% } else { %>
17
- export function App() {
18
- <% } %>
19
- return (
15
+ override render() {
16
+ return (
20
17
  <StyledApp>
21
- <% if (!minimal) { %>
18
+ <%_ if (!minimal) { _%>
22
19
  <NxWelcome title="<%= projectName %>"/>
23
- <% } else { %>
24
- <h1>
25
- <span> Hello there, </span>
26
- Welcome <%= projectName %> 👋
27
- </h1>
28
- <% } %>
20
+ <%_ } else { _%>
21
+ <h1>
22
+ <span> Hello there, </span>
23
+ Welcome <%= projectName %> 👋
24
+ </h1>
25
+ <%_ } _%>
29
26
  </StyledApp>
30
- );
31
- <% if (classComponent) { %>
27
+ );
32
28
  }
33
29
  }
34
- <% } else { %>
30
+ <%_ } else { _%>
31
+ export function App() {
32
+ return (
33
+ <StyledApp>
34
+ <%_ if (!minimal) { _%>
35
+ <NxWelcome title="<%= projectName %>"/>
36
+ <%_ } else { _%>
37
+ <h1>
38
+ <span> Hello there, </span>
39
+ Welcome <%= projectName %> 👋
40
+ </h1>
41
+ <%_ } _%>
42
+ </StyledApp>
43
+ );
35
44
  }
36
- <% } %>
45
+ <%_ } _%>
37
46
 
38
47
  export default App;
39
48
 
@@ -1,32 +1,44 @@
1
- <% if (classComponent) { %>
1
+ <%_ if (classComponent) { _%>
2
2
  import { Component } from 'react';
3
- <% } if (!minimal) { %>
3
+ <%_ } if (!minimal) { _%>
4
4
  import NxWelcome from "./nx-welcome";
5
- <% } %>
5
+ <%_ } if (bundler === "rspack") { _%>
6
+ import '../styles.css';
7
+ <%_ } _%>
6
8
 
7
- <% if (classComponent) { %>
9
+ <%_ if (classComponent) { _%>
8
10
  export class App extends Component {
9
- render() {
10
- <% } else { %>
11
+ override render() {
12
+ return (
13
+ <div>
14
+ <%_ if (!minimal) { _%>
15
+ <NxWelcome title="<%= projectName %>"/>
16
+ <%_ } else { _%>
17
+ <h1>
18
+ <span> Hello there, </span>
19
+ Welcome <%= projectName %> 👋
20
+ </h1>
21
+ <%_ } _%>
22
+ </div>
23
+ );
24
+ }
25
+ }
26
+ <%_ } else { _%>
11
27
  export function App() {
12
- <% } %>
13
28
  return (
14
- <div>
15
- <% if (!minimal) { %>
16
- <NxWelcome title="<%= projectName %>"/>
17
- <% } else { %>
29
+ <div>
30
+ <%_ if (!minimal) { _%>
31
+ <NxWelcome title="<%= projectName %>"/>
32
+ <%_ } else { _%>
18
33
  <h1>
19
34
  <span> Hello there, </span>
20
35
  Welcome <%= projectName %> 👋
21
36
  </h1>
22
- <% } %>
23
- </div>);
24
- <% if (classComponent) { %>
25
- }
26
- }
27
- <% } else { %>
37
+ <%_ } _%>
38
+ </div>
39
+ );
28
40
  }
29
- <% } %>
41
+ <%_ } _%>
30
42
 
31
43
  export default App;
32
44
 
@@ -30,6 +30,7 @@ async function createApplicationFiles(host, options) {
30
30
  else {
31
31
  styleSolutionSpecificAppFiles = '../files/style-css-module';
32
32
  }
33
+ const hasStyleFile = ['scss', 'css', 'less'].includes(options.style);
33
34
  const onBoardingStatus = await (0, onboarding_1.createNxCloudOnboardingURLForWelcomeApp)(host, options.nxCloudToken);
34
35
  const connectCloudUrl = onBoardingStatus === 'unclaimed' &&
35
36
  (await (0, onboarding_1.getNxCloudAppOnBoardingUrl)(options.nxCloudToken));
@@ -44,6 +45,7 @@ async function createApplicationFiles(host, options) {
44
45
  appTests,
45
46
  inSourceVitestTests: (0, get_in_source_vitest_tests_template_1.getInSourceVitestTestsTemplate)(appTests),
46
47
  style: options.style === 'tailwind' ? 'css' : options.style,
48
+ hasStyleFile,
47
49
  };
48
50
  if (options.bundler === 'vite') {
49
51
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
@@ -2,19 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getAppTests = getAppTests;
4
4
  function getAppTests(options) {
5
- return `
6
- it('should render successfully', () => {
7
- ${options.routing
5
+ return `it('should render successfully', () => {
6
+ ${options.routing
8
7
  ? 'const { baseElement } = render(<BrowserRouter><App /></BrowserRouter>);'
9
8
  : 'const { baseElement } = render(<App />);'}
10
- expect(baseElement).toBeTruthy();
11
- });
9
+ expect(baseElement).toBeTruthy();
10
+ });
12
11
 
13
- it('should have a greeting as the title', () => {
14
- ${options.routing
12
+ it('should have a greeting as the title', () => {
13
+ ${options.routing
15
14
  ? 'const { getByText } = render(<BrowserRouter><App /></BrowserRouter>);'
16
15
  : 'const { getByText } = render(<App />);'}
17
- expect(getByText(/Welcome ${options.projectName}/gi)).toBeTruthy();
18
- });
16
+ expect(getByText(/Welcome ${options.projectName}/gi)).toBeTruthy();
17
+ });
19
18
  `;
20
19
  }
@@ -1,84 +1,83 @@
1
- <% if (classComponent) { %>
1
+ <%_ if (classComponent) { _%>
2
2
  import { Component } from 'react';
3
- <% } %>
4
-
5
- <% if (routing) { %>
3
+ <%_ } _%>
4
+ <%_ if (routing) { _%>
6
5
  import { Route, Link } from 'react-router-dom';
7
- <% } %>
6
+ <%_ } _%>
8
7
 
9
- <% if (hasStyles) {
8
+ <%_ if (hasStyles) {
10
9
  if (styledModule && styledModule !== 'styled-jsx') {
11
10
  var wrapper = 'Styled' + className;
12
11
  var extras = '';
13
- %>
14
- import styled from '<%= styledModule %>';
15
- <% } else {
12
+ _%>
13
+ import styled from '<%= styledModule %>';
14
+ <%_ } else {
16
15
  var wrapper = 'div';
17
16
  var extras = globalCss || styledModule === 'styled-jsx' ? '' : " className={styles['container']}";
18
- %>
19
- <%- style !== 'styled-jsx' ? globalCss ? `import './${fileName}.${style}';` : `import styles from './${fileName}.module.${style}';`: '' %>
20
- <% }
17
+ _%>
18
+ <%- style !== 'styled-jsx' ? globalCss ? `import './${fileName}.${style}';` : `import styles from './${fileName}.module.${style}';`: '' %>
19
+ <%_ }
21
20
  } else {
22
21
  var wrapper = 'div';
23
22
  var extras = '';
24
- } %>
23
+ } _%>
25
24
 
26
- <% if (styledModule && styledModule !== 'styled-jsx') { %>
25
+ <%_ if (styledModule && styledModule !== 'styled-jsx') { _%>
27
26
  const Styled<%= className %> = styled.div`
28
27
  color: pink;
29
28
  `;
30
- <% }%>
31
- <% if(!isNextPage) { %>
32
- <% if (classComponent) { %>
33
- export class <%= className %> extends Component<{}> {
34
- override render() {
35
- return (
36
- <<%= wrapper %><%- extras %>>
37
- <%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
38
- <p>Welcome to <%= className %>!</p>
39
- <% if (routing) { %>
40
- <ul>
41
- <li><Link to="/"><%= name %> root</Link></li>
42
- </ul>
43
- <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
44
- <% } %>
45
- </<%= wrapper %>>
46
- );
47
- }
48
- }
49
- <% } else { %>
50
- export function <%= className %>() {
29
+ <%_ } _%>
30
+ <%_ if(!isNextPage) { _%>
31
+ <%_ if (classComponent) { _%>
32
+ export class <%= className %> extends Component<{}> {
33
+ override render() {
51
34
  return (
52
35
  <<%= wrapper %><%- extras %>>
53
- <% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
54
- <h1>Welcome to <%= className %>!</h1>
55
- <% if (routing) { %>
36
+ <%= styledModule === 'styled-jsx' ? `<style jsx>{\`div { color: pink; }\`}</style>` : `` %>
37
+ <p>Welcome to <%= className %>!</p>
38
+ <%_ if (routing) { _%>
56
39
  <ul>
57
40
  <li><Link to="/"><%= name %> root</Link></li>
58
41
  </ul>
59
42
  <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
60
- <% } %>
43
+ <%_ } _%>
61
44
  </<%= wrapper %>>
62
45
  );
63
46
  }
64
- <% } %>
47
+ }
48
+ <%_ } else { _%>
49
+ export function <%= className %>() {
50
+ return (
51
+ <<%= wrapper %><%- extras %>>
52
+ <%_ if (styledModule === 'styled-jsx') { _%><style jsx>{`div { color: pink; }`}</style><%_ } _%>
53
+ <h1>Welcome to <%= className %>!</h1>
54
+ <%_ if (routing) { _%>
55
+ <ul>
56
+ <li><Link to="/"><%= name %> root</Link></li>
57
+ </ul>
58
+ <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
59
+ <%_ } _%>
60
+ </<%= wrapper %>>
61
+ );
62
+ }
63
+ <%_ } _%>
65
64
 
66
- export default <%= className %>;
67
- <% } else { %>
68
- export default function <%= className %>() {
69
- return (
70
- <<%= wrapper %><%- extras %>>
71
- <% if (styledModule === 'styled-jsx') { %><style jsx>{`div { color: pink; }`}</style><% } %>
72
- <h1>Welcome to <%= className %>!</h1>
73
- <% if (routing) { %>
74
- <ul>
75
- <li><Link to="/"><%= name %> root</Link></li>
76
- </ul>
77
- <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
78
- <% } %>
79
- </<%= wrapper %>>
80
- );
81
- };
65
+ export default <%= className %>;
66
+ <%_ } else { _%>
67
+ export default function <%= className %>() {
68
+ return (
69
+ <<%= wrapper %><%- extras %>>
70
+ <%_ if (styledModule === 'styled-jsx') { _%><style jsx>{`div { color: pink; }`}</style><%_ } _%>
71
+ <h1>Welcome to <%= className %>!</h1>
72
+ <% if (routing) { %>
73
+ <ul>
74
+ <li><Link to="/"><%= name %> root</Link></li>
75
+ </ul>
76
+ <Route path="/" element={<div>This is the <%= name %> root route.</div>} />
77
+ <% } %>
78
+ </<%= wrapper %>>
79
+ );
80
+ };
82
81
  <% } %>
83
82
 
84
83
  <% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
@@ -1,8 +1,8 @@
1
1
  import componentName from './<%= componentImportFileName %>';
2
- <% if ( interactionTests ) { %>
2
+ <%_ if ( interactionTests ) { _%>
3
3
  import { within } from '@storybook/testing-library';
4
4
  import { expect } from '@storybook/jest';
5
- <% } %>
5
+ <%_ } _%>
6
6
 
7
7
  export default {
8
8
  component: <%= componentName %>,
@@ -10,7 +10,7 @@ export default {
10
10
  argTypes: {<% for (let argType of argTypes) { %>
11
11
  <%= argType.name %>: { <%- argType.type %> : "<%- argType.actionText %>" },<% } %>
12
12
  }
13
- <% } %>
13
+ <%_ } _%>
14
14
  };
15
15
 
16
16
  export const Primary = {
@@ -19,11 +19,11 @@ export const Primary = {
19
19
  },
20
20
  };
21
21
 
22
- <% if ( interactionTests ) { %>
22
+ <%_ if ( interactionTests ) { _%>
23
23
  export const Heading: Story = {
24
24
  play: async ({ canvasElement }) => {
25
25
  const canvas = within(canvasElement);
26
26
  expect(canvas.getByText(/Welcome to <%=componentName%>!/gi)).toBeTruthy();
27
27
  },
28
28
  };
29
- <% } %>
29
+ <%_ } _%>
@@ -1,9 +1,9 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react';
2
2
  import { <%= componentName %> } from './<%= componentImportFileName %>';
3
- <% if ( interactionTests ) { %>
3
+ <%_ if ( interactionTests ) { _%>
4
4
  import { within } from '@storybook/testing-library';
5
5
  import { expect } from '@storybook/jest';
6
- <% } %>
6
+ <%_ } _%>
7
7
 
8
8
  const meta: Meta<typeof <%= componentName %>> = {
9
9
  component: <%= componentName %>,
@@ -16,14 +16,13 @@ const meta: Meta<typeof <%= componentName %>> = {
16
16
  export default meta;
17
17
  type Story = StoryObj<typeof <%= componentName %>>;
18
18
 
19
-
20
19
  export const Primary = {
21
20
  args: {<% for (let prop of props) { %>
22
21
  <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
23
22
  },
24
23
  };
25
24
 
26
- <% if ( interactionTests ) { %>
25
+ <%_ if ( interactionTests ) { _%>
27
26
  export const Heading: Story = {
28
27
  args: {<% for (let prop of props) { %>
29
28
  <%= prop.name %>: <%- prop.defaultValue %>,<% } %>
@@ -1,31 +1,38 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
+ <%_ if (dynamic) { _%>
7
+ import { loadRemote } from '@module-federation/enhanced/runtime';
8
+ <%_ } _%>
6
9
 
7
- <% if (remotes.length > 0) { %>
8
- <% remotes.forEach(function(r) { %>
9
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
10
- <% }); %>
11
- <% } %>
10
+ <%_ if (remotes.length > 0) {
11
+ remotes.forEach(function(r) { _%>
12
+ <%_ if (dynamic) { _%>
13
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
14
+ <%_ } else { _%>
15
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
+ <%_ } _%>
17
+ <%_ }); _%>
18
+ <%_ } _%>
12
19
  export function App() {
13
20
  return (
14
21
  <React.Suspense fallback={null}>
15
- <ul>
16
- <li><Link to="/">Home</Link></li>
17
- <% remotes.forEach(function(r) { %>
18
- <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
19
- <% }); %>
20
- </ul>
21
- <Routes>
22
- <% if (!minimal) { %>
23
- <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
24
- <% } %>
25
- <% remotes.forEach(function(r) { %>
26
- <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
27
- <% }); %>
28
- </Routes>
22
+ <ul>
23
+ <li><Link to="/">Home</Link></li>
24
+ <%_ remotes.forEach(function(r) { _%>
25
+ <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
26
+ <%_ }); _%>
27
+ </ul>
28
+ <Routes>
29
+ <%_ if (!minimal) { _%>
30
+ <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
31
+ <%_ } _%>
32
+ <%_ remotes.forEach(function(r) { _%>
33
+ <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
34
+ <%_ }); _%>
35
+ </Routes>
29
36
  </React.Suspense>
30
37
  );
31
38
  }
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -1,39 +1,39 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
- <% if (dynamic) { %>
7
- import { loadRemoteModule } from '@nx/react/mf';
8
- <% } %>
6
+ <%_ if (dynamic) { _%>
7
+ import { loadRemote } from '@module-federation/enhanced/runtime';
8
+ <%_ } _%>
9
9
 
10
- <% if (remotes.length > 0) { %>
11
- <% remotes.forEach(function(r) { %>
12
- <% if (dynamic) { %>
13
- const <%= r.className %> = React.lazy(() => loadRemoteModule('<%= r.fileName %>', './Module'))
14
- <% } else { %>
15
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
- <% } %>
17
- <% }); %>
18
- <% } %>
10
+ <%_ if (remotes.length > 0) {
11
+ remotes.forEach(function(r) { _%>
12
+ <%_ if (dynamic) { _%>
13
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
14
+ <%_ } else { _%>
15
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
16
+ <%_ } _%>
17
+ <%_ }); _%>
18
+ <%_ } _%>
19
19
 
20
20
  export function App() {
21
21
  return (
22
22
  <React.Suspense fallback={null}>
23
- <ul>
24
- <li><Link to="/">Home</Link></li>
25
- <% remotes.forEach(function(r) { %>
26
- <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
27
- <% }); %>
28
- </ul>
29
- <Routes>
30
- <% if (!minimal) { %>
31
- <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
32
- <% } %>
33
- <% remotes.forEach(function(r) { %>
34
- <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
35
- <% }); %>
36
- </Routes>
23
+ <ul>
24
+ <li><Link to="/">Home</Link></li>
25
+ <%_ remotes.forEach(function(r) { _%>
26
+ <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
27
+ <%_ }); _%>
28
+ </ul>
29
+ <Routes>
30
+ <%_ if (!minimal) { _%>
31
+ <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
32
+ <%_ } _%>
33
+ <%_ remotes.forEach(function(r) { _%>
34
+ <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
35
+ <%_ }); _%>
36
+ </Routes>
37
37
  </React.Suspense>
38
38
  );
39
39
  }
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -1,30 +1,39 @@
1
1
  import * as React from 'react';
2
- <% if (!minimal) { %>
2
+ <%_ if (!minimal) { _%>
3
3
  import NxWelcome from "./nx-welcome";
4
- <% } %>
4
+ <%_ } _%>
5
5
  import { Link, Route, Routes } from 'react-router-dom';
6
6
 
7
- <% if (remotes.length > 0) { %>
8
- <% remotes.forEach(function(r) { %>
9
- const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
10
- <% }); %>
11
- <% } %>
7
+ <%_ if (dynamic) { _%>
8
+ import { loadRemote } from '@module-federation/enhanced/runtime';
9
+ <%_ } _%>
10
+
11
+ <%_ if (remotes.length > 0) {
12
+ remotes.forEach(function(r) { _%>
13
+ <%_ if (dynamic) { _%>
14
+ const <%= r.className %> = React.lazy(() => loadRemote('<%= r.fileName %>/Module') as any)
15
+ <%_ } else { _%>
16
+ const <%= r.className %> = React.lazy(() => import('<%= r.fileName %>/Module'));
17
+ <%_ } _%>
18
+ <%_ }); _%>
19
+ <%_ } _%>
20
+
12
21
  export function App() {
13
22
  return (
14
23
  <React.Suspense fallback={null}>
15
24
  <ul>
16
25
  <li><Link to="/">Home</Link></li>
17
- <% remotes.forEach(function(r) { %>
26
+ <%_ remotes.forEach(function(r) { _%>
18
27
  <li><Link to="/<%=r.fileName%>"><%=r.className%></Link></li>
19
- <% }); %>
28
+ <%_ }); _%>
20
29
  </ul>
21
30
  <Routes>
22
- <% if (!minimal) { %>
31
+ <%_ if (!minimal) { _%>
23
32
  <Route path="/" element={<NxWelcome title="<%= projectName %>"/>} />
24
- <% } %>
25
- <% remotes.forEach(function(r) { %>
33
+ <%_ } _%>
34
+ <%_ remotes.forEach(function(r) { _%>
26
35
  <Route path="/<%=r.fileName%>" element={<<%= r.className %>/>} />
27
- <% }); %>
36
+ <%_ }); _%>
28
37
  </Routes>
29
38
  </React.Suspense>
30
39
  );
@@ -1,10 +1,13 @@
1
- <% if (dynamic) { %>
2
- import { setRemoteDefinitions } from '@nx/react/mf';
1
+ <%_ if (dynamic) { _%>
2
+ import { init } from '@module-federation/enhanced/runtime';
3
3
 
4
- fetch('/assets/module-federation.manifest.json')
5
- .then((res) => res.json())
6
- .then(definitions => setRemoteDefinitions(definitions))
7
- .then(() => import('./bootstrap').catch(err => console.error(err)));
8
- <% } else { %>
9
- import('./bootstrap').catch(err => console.error(err));
10
- <% } %>
4
+ fetch('/assets/module-federation.manifest.json')
5
+ .then((res) => res.json())
6
+ .then((remotes: Record<string, string>) =>
7
+ Object.entries(remotes).map(([name, entry]) => ({ name, entry }))
8
+ )
9
+ .then((remotes) => init({ name: '<%= projectName %>', remotes }))
10
+ .then(() => import('./bootstrap').catch(err => console.error(err)));
11
+ <%_ } else { _%>
12
+ import('./bootstrap').catch(err => console.error(err));
13
+ <%_ } _%>
@@ -16,9 +16,9 @@ module.exports = {
16
16
  *
17
17
  */
18
18
  remotes: [
19
- <% if (static) {
20
- remotes.forEach(function(r) { %> "<%= r.fileName %>", <% });
21
- }
22
- %>
19
+ <%_ if (static) {
20
+ remotes.forEach(function(r) { %>
21
+ "<%= r.fileName %>",
22
+ <%_ }); } _%>
23
23
  ],
24
24
  };