@nx/react 17.0.3 → 17.0.5

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 (154) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +9 -4
  3. package/generators.json +1 -1
  4. package/index.d.ts +1 -0
  5. package/index.js +3 -1
  6. package/mf/dynamic-federation.d.ts +4 -0
  7. package/mf/dynamic-federation.js +75 -0
  8. package/mf/index.d.ts +1 -0
  9. package/mf/index.js +7 -0
  10. package/migrations.json +21 -0
  11. package/package.json +7 -7
  12. package/plugins/component-testing/index.js +52 -24
  13. package/plugins/component-testing/webpack-fallback.js +1 -1
  14. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.d.ts +4 -0
  15. package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +86 -0
  16. package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.d.ts +8 -0
  17. package/plugins/nx-react-webpack-plugin/nx-react-webpack-plugin.js +13 -0
  18. package/plugins/storybook/index.js +6 -2
  19. package/plugins/storybook/merge-plugins.d.ts +1 -1
  20. package/plugins/webpack.d.ts +1 -3
  21. package/plugins/webpack.js +3 -11
  22. package/plugins/with-react.d.ts +2 -4
  23. package/plugins/with-react.js +2 -58
  24. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +13 -0
  25. package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +173 -58
  26. package/src/executors/module-federation-dev-server/schema.json +13 -1
  27. package/src/generators/application/application.js +41 -18
  28. package/src/generators/application/files/base-vite/index.html__tmpl__ +1 -1
  29. package/src/generators/application/files/base-webpack/src/index.html +0 -2
  30. package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +46 -5
  31. package/src/generators/application/files/nx-welcome/src/app/nx-welcome.tsx +54 -13
  32. package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +33 -0
  33. package/src/generators/application/files/style-tailwind/src/styles.css +1 -0
  34. package/src/generators/application/lib/add-e2e.js +25 -7
  35. package/src/generators/application/lib/add-jest.js +2 -2
  36. package/src/generators/application/lib/add-project.d.ts +2 -2
  37. package/src/generators/application/lib/add-project.js +12 -15
  38. package/src/generators/application/lib/add-routing.d.ts +1 -1
  39. package/src/generators/application/lib/add-routing.js +4 -8
  40. package/src/generators/application/lib/create-application-files.js +30 -1
  41. package/src/generators/application/lib/install-common-dependencies.js +15 -1
  42. package/src/generators/application/lib/normalize-options.js +35 -1
  43. package/src/generators/application/lib/set-defaults.js +1 -0
  44. package/src/generators/application/lib/update-jest-config.js +8 -8
  45. package/src/generators/application/schema.d.ts +5 -0
  46. package/src/generators/application/schema.json +7 -3
  47. package/src/generators/component/files/__fileName__.tsx__tmpl__ +39 -22
  48. package/src/generators/component/lib/normalize-options.js +4 -2
  49. package/src/generators/component/schema.d.ts +6 -4
  50. package/src/generators/component/schema.json +7 -7
  51. package/src/generators/component-cypress-spec/schema.json +1 -1
  52. package/src/generators/component-story/schema.json +1 -1
  53. package/src/generators/component-test/schema.json +1 -1
  54. package/src/generators/cypress-component-configuration/cypress-component-configuration.d.ts +2 -1
  55. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +18 -7
  56. package/src/generators/cypress-component-configuration/lib/add-files.js +1 -6
  57. package/src/generators/cypress-component-configuration/schema.d.ts +1 -0
  58. package/src/generators/federate-module/federate-module.js +2 -2
  59. package/src/generators/federate-module/schema.d.ts +1 -1
  60. package/src/generators/federate-module/schema.json +4 -3
  61. package/src/generators/hook/files/__fileName__.ts__tmpl__ +15 -15
  62. package/src/generators/hook/schema.d.ts +4 -4
  63. package/src/generators/hook/schema.json +5 -5
  64. package/src/generators/host/files/common/src/main.js__tmpl__ +10 -0
  65. package/src/generators/host/files/common/tsconfig.lint.json__tmpl__ +19 -0
  66. package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +41 -0
  67. package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +10 -0
  68. package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +17 -2
  69. package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +5 -2
  70. package/src/generators/host/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +5 -2
  71. package/src/generators/host/files/module-federation-ts/module-federation.config.ts__tmpl__ +17 -2
  72. package/src/generators/host/files/module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -1
  73. package/src/generators/host/files/module-federation-ts/webpack.config.ts__tmpl__ +2 -2
  74. package/src/generators/host/host.js +15 -1
  75. package/src/generators/host/lib/add-module-federation-files.d.ts +2 -1
  76. package/src/generators/host/lib/add-module-federation-files.js +24 -11
  77. package/src/generators/host/lib/setup-ssr-for-host.js +1 -0
  78. package/src/generators/host/lib/update-module-federation-e2e-project.js +7 -5
  79. package/src/generators/host/schema.d.ts +5 -2
  80. package/src/generators/host/schema.json +16 -6
  81. package/src/generators/init/init.d.ts +1 -1
  82. package/src/generators/init/init.js +10 -49
  83. package/src/generators/init/schema.d.ts +1 -6
  84. package/src/generators/init/schema.json +5 -22
  85. package/src/generators/library/lib/add-linting.js +2 -2
  86. package/src/generators/library/lib/add-rollup-build-target.d.ts +2 -1
  87. package/src/generators/library/lib/add-rollup-build-target.js +16 -8
  88. package/src/generators/library/lib/install-common-dependencies.js +13 -5
  89. package/src/generators/library/lib/normalize-options.js +34 -5
  90. package/src/generators/library/lib/update-app-routes.js +1 -1
  91. package/src/generators/library/library.js +17 -6
  92. package/src/generators/library/schema.d.ts +1 -0
  93. package/src/generators/library/schema.json +3 -3
  94. package/src/generators/redux/schema.d.ts +1 -1
  95. package/src/generators/redux/schema.json +2 -2
  96. package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +4 -1
  97. package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +1 -1
  98. package/src/generators/remote/files/module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
  99. package/src/generators/remote/files/module-federation-ssr-ts/tsconfig.lint.json__tmpl__ +19 -0
  100. package/src/generators/remote/files/module-federation-ts/module-federation.config.ts__tmpl__ +4 -1
  101. package/src/generators/remote/files/module-federation-ts/tsconfig.lint.json__tmpl__ +19 -0
  102. package/src/generators/remote/lib/add-remote-to-dynamic-host.d.ts +2 -0
  103. package/src/generators/remote/lib/add-remote-to-dynamic-host.js +11 -0
  104. package/src/generators/remote/lib/setup-ssr-for-remote.js +5 -1
  105. package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -1
  106. package/src/generators/remote/lib/update-host-with-remote.js +10 -1
  107. package/src/generators/remote/remote.js +22 -2
  108. package/src/generators/remote/schema.d.ts +3 -2
  109. package/src/generators/remote/schema.json +17 -6
  110. package/src/generators/setup-ssr/schema.json +1 -1
  111. package/src/generators/setup-ssr/setup-ssr.js +23 -7
  112. package/src/generators/setup-tailwind/schema.json +1 -1
  113. package/src/generators/stories/schema.json +1 -1
  114. package/src/generators/stories/stories.js +17 -5
  115. package/src/generators/storybook-configuration/configuration.d.ts +2 -0
  116. package/src/generators/storybook-configuration/configuration.js +37 -15
  117. package/src/generators/storybook-configuration/schema.d.ts +2 -1
  118. package/src/generators/storybook-configuration/schema.json +7 -7
  119. package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.d.ts +2 -0
  120. package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +26 -0
  121. package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +2 -0
  122. package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +53 -0
  123. package/src/module-federation/ast-utils.js +1 -1
  124. package/src/module-federation/utils.js +8 -1
  125. package/src/module-federation/with-module-federation-ssr.js +3 -0
  126. package/src/module-federation/with-module-federation.d.ts +3 -3
  127. package/src/module-federation/with-module-federation.js +14 -4
  128. package/src/rules/update-module-federation-project.d.ts +2 -0
  129. package/src/rules/update-module-federation-project.js +12 -3
  130. package/src/utils/add-mf-env-to-inputs.d.ts +2 -0
  131. package/src/utils/add-mf-env-to-inputs.js +27 -0
  132. package/src/utils/assertion.js +1 -0
  133. package/src/utils/ct-utils.d.ts +6 -1
  134. package/src/utils/ct-utils.js +39 -9
  135. package/src/utils/get-in-source-vitest-tests-template.js +1 -1
  136. package/src/utils/has-vite-plugin.d.ts +2 -0
  137. package/src/utils/has-vite-plugin.js +11 -0
  138. package/src/utils/has-webpack-plugin.d.ts +2 -0
  139. package/src/utils/has-webpack-plugin.js +11 -0
  140. package/src/utils/maybe-js.d.ts +3 -0
  141. package/src/utils/versions.d.ts +1 -1
  142. package/src/utils/versions.js +1 -1
  143. package/typings/style.d.ts +1 -0
  144. package/src/generators/application/files/base-webpack/src/environments/environment.prod.ts__tmpl__ +0 -3
  145. package/src/generators/application/files/base-webpack/src/environments/environment.ts__tmpl__ +0 -6
  146. package/src/generators/host/files/module-federation/src/main.ts__tmpl__ +0 -1
  147. package/src/generators/host/files/module-federation-ts/src/main.ts__tmpl__ +0 -1
  148. package/src/generators/library/lib/maybe-js.d.ts +0 -2
  149. /package/src/generators/host/files/common/src/app/{__fileName__.tsx__tmpl__ → __fileName__.js__tmpl__} +0 -0
  150. /package/src/generators/remote/files/{module-federation/src/main.ts__tmpl__ → common/src/main.js__tmpl__} +0 -0
  151. /package/src/generators/remote/files/{module-federation/src/remote-entry.ts__tmpl__ → common/src/remote-entry.js__tmpl__} +0 -0
  152. /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/main.ts__tmpl__ +0 -0
  153. /package/src/generators/remote/files/{module-federation-ts → common-ts}/src/remote-entry.ts__tmpl__ +0 -0
  154. /package/src/{generators/library/lib → utils}/maybe-js.js +0 -0
@@ -274,12 +274,21 @@ export function NxWelcome({ title }: { title: string }) {
274
274
  .button-pill:hover {
275
275
  color: rgba(255, 255, 255, 1) !important;
276
276
  }
277
- .nx-console:hover {
277
+ #nx-console:hover {
278
278
  background-color: rgba(0, 122, 204, 1);
279
279
  }
280
- .nx-console svg {
280
+ #nx-console svg {
281
281
  color: rgba(0, 122, 204, 1);
282
282
  }
283
+ #nx-console-jetbrains {
284
+ margin-top: 2rem;
285
+ }
286
+ #nx-console-jetbrains:hover {
287
+ background-color: rgba(255, 49, 140, 1);
288
+ }
289
+ #nx-console-jetbrains svg {
290
+ color: rgba(255, 49, 140, 1);
291
+ }
283
292
  #nx-repo:hover {
284
293
  background-color: rgba(24, 23, 23, 1);
285
294
  }
@@ -644,7 +653,8 @@ export function NxWelcome({ title }: { title: string }) {
644
653
  </div>
645
654
  <div id="other-links">
646
655
  <a
647
- className="button-pill nx-console rounded shadow"
656
+ id="nx-console"
657
+ className="button-pill rounded shadow"
648
658
  href="https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console&utm_source=nx-project"
649
659
  target="_blank"
650
660
  rel="noreferrer"
@@ -660,23 +670,35 @@ export function NxWelcome({ title }: { title: string }) {
660
670
  </svg>
661
671
  <span>
662
672
  Install Nx Console for VSCode
663
- <span>The official VSCode plugin for Nx.</span>
673
+ <span>The official VSCode extension for Nx.</span>
664
674
  </span>
665
675
  </a>
666
676
  <a
667
- className="button-pill nx-console rounded shadow"
677
+ id="nx-console-jetbrains"
678
+ className="button-pill rounded shadow"
668
679
  href="https://plugins.jetbrains.com/plugin/21060-nx-console"
669
680
  target="_blank"
670
681
  rel="noreferrer"
671
682
  >
672
683
  <svg
673
- fill="currentColor"
674
- role="img"
675
- viewBox="0 0 24 24"
684
+ height="48"
685
+ width="48"
686
+ viewBox="20 20 60 60"
676
687
  xmlns="http://www.w3.org/2000/svg"
677
688
  >
678
- <title>IntelliJ</title>
679
- <path d="M0 0v24h24V0zm3.723 3.111h5v1.834h-1.39v6.277h1.39v1.834h-5v-1.834h1.444V4.945H3.723zm11.055 0H17v6.5c0 .612-.055 1.111-.222 1.556-.167.444-.39.777-.723 1.11-.277.279-.666.557-1.11.668a3.933 3.933 0 0 1-1.445.278c-.778 0-1.444-.167-1.944-.445a4.81 4.81 0 0 1-1.279-1.056l1.39-1.555c.277.334.555.555.833.722.277.167.611.278.945.278.389 0 .721-.111 1-.389.221-.278.333-.667.333-1.278zM2.222 19.5h9V21h-9z"></path>
689
+ <path d="m22.5 22.5h60v60h-60z" />
690
+ <g fill="#fff">
691
+ <path d="m29.03 71.25h22.5v3.75h-22.5z" />
692
+ <path d="m28.09 38 1.67-1.58a1.88 1.88 0 0 0 1.47.87c.64 0 1.06-.44 1.06-1.31v-5.98h2.58v6a3.48 3.48 0 0 1 -.87 2.6 3.56 3.56 0 0 1 -2.57.95 3.84 3.84 0 0 1 -3.34-1.55z" />
693
+ <path d="m36 30h7.53v2.19h-5v1.44h4.49v2h-4.42v1.49h5v2.21h-7.6z" />
694
+ <path d="m47.23 32.29h-2.8v-2.29h8.21v2.27h-2.81v7.1h-2.6z" />
695
+ <path d="m29.13 43.08h4.42a3.53 3.53 0 0 1 2.55.83 2.09 2.09 0 0 1 .6 1.53 2.16 2.16 0 0 1 -1.44 2.09 2.27 2.27 0 0 1 1.86 2.29c0 1.61-1.31 2.59-3.55 2.59h-4.44zm5 2.89c0-.52-.42-.8-1.18-.8h-1.29v1.64h1.24c.79 0 1.25-.26 1.25-.81zm-.9 2.66h-1.57v1.73h1.62c.8 0 1.24-.31 1.24-.86 0-.5-.4-.87-1.27-.87z" />
696
+ <path d="m38 43.08h4.1a4.19 4.19 0 0 1 3 1 2.93 2.93 0 0 1 .9 2.19 3 3 0 0 1 -1.93 2.89l2.24 3.27h-3l-1.88-2.84h-.87v2.84h-2.56zm4 4.5c.87 0 1.39-.43 1.39-1.11 0-.75-.54-1.12-1.4-1.12h-1.44v2.26z" />
697
+ <path d="m49.59 43h2.5l4 9.44h-2.79l-.67-1.69h-3.63l-.67 1.69h-2.71zm2.27 5.73-1-2.65-1.06 2.65z" />
698
+ <path d="m56.46 43.05h2.6v9.37h-2.6z" />
699
+ <path d="m60.06 43.05h2.42l3.37 5v-5h2.57v9.37h-2.26l-3.53-5.14v5.14h-2.57z" />
700
+ <path d="m68.86 51 1.45-1.73a4.84 4.84 0 0 0 3 1.13c.71 0 1.08-.24 1.08-.65 0-.4-.31-.6-1.59-.91-2-.46-3.53-1-3.53-2.93 0-1.74 1.37-3 3.62-3a5.89 5.89 0 0 1 3.86 1.25l-1.26 1.84a4.63 4.63 0 0 0 -2.62-.92c-.63 0-.94.25-.94.6 0 .42.32.61 1.63.91 2.14.46 3.44 1.16 3.44 2.91 0 1.91-1.51 3-3.79 3a6.58 6.58 0 0 1 -4.35-1.5z" />
701
+ </g>
680
702
  </svg>
681
703
  <span>
682
704
  Install Nx Console for JetBrains
@@ -705,7 +727,7 @@ export function NxWelcome({ title }: { title: string }) {
705
727
  />
706
728
  </svg>
707
729
  <h2>
708
- NxCloud
730
+ Nx Cloud
709
731
  <span>Enable faster CI & better DX</span>
710
732
  </h2>
711
733
  </div>
@@ -713,7 +735,7 @@ export function NxWelcome({ title }: { title: string }) {
713
735
  You can activate distributed tasks executions and caching by
714
736
  running:
715
737
  </p>
716
- <pre>nx connect-to-nx-cloud</pre>
738
+ <pre>nx connect</pre>
717
739
  <a
718
740
  href="https://nx.app/?utm_source=nx-project"
719
741
  target="_blank"
@@ -770,9 +792,28 @@ export function NxWelcome({ title }: { title: string }) {
770
792
  <span># Generate UI lib</span>
771
793
  nx g @nx/react:lib ui
772
794
  <span># Add a component</span>
773
- nx g @nx/react:component button --project ui
795
+ nx g @nx/react:component ui/src/lib/button
774
796
  </pre>
775
797
  </details>
798
+ <details>
799
+ <summary>
800
+ <svg
801
+ fill="none"
802
+ stroke="currentColor"
803
+ viewBox="0 0 24 24"
804
+ xmlns="http://www.w3.org/2000/svg"
805
+ >
806
+ <path
807
+ strokeLinecap="round"
808
+ strokeLinejoin="round"
809
+ strokeWidth="2"
810
+ d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"
811
+ />
812
+ </svg>
813
+ View project details
814
+ </summary>
815
+ <pre>nx show project {title} --web</pre>
816
+ </details>
776
817
  <details>
777
818
  <summary>
778
819
  <svg
@@ -0,0 +1,33 @@
1
+ <% if (classComponent) { %>
2
+ import { Component } from 'react';
3
+ <% } if (!minimal) { %>
4
+ import NxWelcome from "./nx-welcome";
5
+ <% } %>
6
+
7
+ <% if (classComponent) { %>
8
+ export class App extends Component {
9
+ render() {
10
+ <% } else { %>
11
+ export function App() {
12
+ <% } %>
13
+ return (
14
+ <div>
15
+ <% if (!minimal) { %>
16
+ <NxWelcome title="<%= projectName %>"/>
17
+ <% } else { %>
18
+ <h1>
19
+ <span> Hello there, </span>
20
+ Welcome <%= projectName %> 👋
21
+ </h1>
22
+ <% } %>
23
+ </div>);
24
+ <% if (classComponent) { %>
25
+ }
26
+ }
27
+ <% } else { %>
28
+ }
29
+ <% } %>
30
+
31
+ export default App;
32
+
33
+ <% if (inSourceTests === true) { %> <%- inSourceVitestTests %> <% } %>
@@ -0,0 +1 @@
1
+ /* You can add global styles to this file, and also import other style files */
@@ -4,13 +4,20 @@ exports.addE2e = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const web_1 = require("@nx/web");
6
6
  const versions_1 = require("../../../utils/versions");
7
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
8
+ const has_vite_plugin_1 = require("../../../utils/has-vite-plugin");
7
9
  async function addE2e(tree, options) {
8
10
  switch (options.e2eTestRunner) {
9
11
  case 'cypress': {
10
- (0, web_1.webStaticServeGenerator)(tree, {
11
- buildTarget: `${options.projectName}:build`,
12
- targetName: 'serve-static',
13
- });
12
+ const hasNxBuildPlugin = (options.bundler === 'webpack' && (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) ||
13
+ (options.bundler === 'vite' && (0, has_vite_plugin_1.hasVitePlugin)(tree));
14
+ if (!hasNxBuildPlugin) {
15
+ await (0, web_1.webStaticServeGenerator)(tree, {
16
+ buildTarget: `${options.projectName}:build`,
17
+ targetName: 'serve-static',
18
+ spa: true,
19
+ });
20
+ }
14
21
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
15
22
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
16
23
  projectType: 'application',
@@ -27,9 +34,19 @@ async function addE2e(tree, options) {
27
34
  // the name and root are already normalized, instruct the generator to use them as is
28
35
  bundler: options.bundler === 'rspack' ? 'webpack' : options.bundler,
29
36
  skipFormat: true,
30
- devServerTarget: `${options.projectName}:serve`,
37
+ devServerTarget: `${options.projectName}:${options.e2eWebServerTarget}`,
38
+ baseUrl: options.e2eWebServerAddress,
31
39
  jsx: true,
32
40
  rootProject: options.rootProject,
41
+ webServerCommands: hasNxBuildPlugin
42
+ ? {
43
+ default: `nx run ${options.projectName}:${options.e2eWebServerTarget}`,
44
+ production: `nx run ${options.projectName}:preview`,
45
+ }
46
+ : undefined,
47
+ ciWebServerCommand: hasNxBuildPlugin
48
+ ? `nx run ${options.projectName}:serve-static`
49
+ : undefined,
33
50
  });
34
51
  }
35
52
  case 'playwright': {
@@ -49,9 +66,10 @@ async function addE2e(tree, options) {
49
66
  js: false,
50
67
  linter: options.linter,
51
68
  setParserOptionsProject: options.setParserOptionsProject,
52
- webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx serve ${options.name}`,
53
- webServerAddress: 'http://localhost:4200',
69
+ webServerCommand: `${(0, devkit_1.getPackageManagerCommand)().exec} nx ${options.e2eWebServerTarget} ${options.name}`,
70
+ webServerAddress: options.e2eWebServerAddress,
54
71
  rootProject: options.rootProject,
72
+ addPlugin: options.addPlugin,
55
73
  });
56
74
  }
57
75
  case 'none':
@@ -4,10 +4,10 @@ exports.addJest = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../../../utils/versions");
6
6
  async function addJest(host, options) {
7
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
8
- if (options.unitTestRunner !== 'jest') {
7
+ if (options.unitTestRunner === 'none') {
9
8
  return () => { };
10
9
  }
10
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
11
11
  return await configurationGenerator(host, {
12
12
  ...options,
13
13
  project: options.projectName,
@@ -1,3 +1,3 @@
1
1
  import { NormalizedSchema } from '../schema';
2
- export declare function addProject(host: any, options: NormalizedSchema): void;
3
- export declare function maybeJs(options: NormalizedSchema, path: string): string;
2
+ import { Tree } from '@nx/devkit';
3
+ export declare function addProject(host: Tree, options: NormalizedSchema): void;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maybeJs = exports.addProject = void 0;
3
+ exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
6
+ const maybe_js_1 = require("../../../utils/maybe-js");
5
7
  function addProject(host, options) {
6
8
  const project = {
7
9
  root: options.appProjectRoot,
@@ -11,22 +13,18 @@ function addProject(host, options) {
11
13
  tags: options.parsedTags,
12
14
  };
13
15
  if (options.bundler === 'webpack') {
14
- project.targets = {
15
- build: createBuildTarget(options),
16
- serve: createServeTarget(options),
17
- };
16
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(host) || !options.addPlugin) {
17
+ project.targets = {
18
+ build: createBuildTarget(options),
19
+ serve: createServeTarget(options),
20
+ };
21
+ }
18
22
  }
19
23
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
20
24
  ...project,
21
25
  });
22
26
  }
23
27
  exports.addProject = addProject;
24
- function maybeJs(options, path) {
25
- return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
26
- ? path.replace(/\.tsx?$/, '.js')
27
- : path;
28
- }
29
- exports.maybeJs = maybeJs;
30
28
  function createBuildTarget(options) {
31
29
  return {
32
30
  executor: '@nx/webpack:webpack',
@@ -39,7 +37,7 @@ function createBuildTarget(options) {
39
37
  : options.projectName),
40
38
  index: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/index.html'),
41
39
  baseHref: '/',
42
- main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/main.tsx`)),
40
+ main: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/main.tsx`)),
43
41
  tsConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
44
42
  assets: [
45
43
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'src/favicon.ico'),
@@ -51,7 +49,6 @@ function createBuildTarget(options) {
51
49
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, `src/styles.${options.style}`),
52
50
  ],
53
51
  scripts: [],
54
- isolatedConfig: true,
55
52
  webpackConfig: (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'webpack.config.js'),
56
53
  },
57
54
  configurations: {
@@ -64,8 +61,8 @@ function createBuildTarget(options) {
64
61
  production: {
65
62
  fileReplacements: [
66
63
  {
67
- replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.ts`)),
68
- with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/environments/environment.prod.ts`)),
64
+ replace: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.ts`)),
65
+ with: (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/environments/environment.prod.ts`)),
69
66
  },
70
67
  ],
71
68
  optimization: true,
@@ -1,3 +1,3 @@
1
- import { NormalizedSchema } from '../schema';
2
1
  import { Tree } from '@nx/devkit';
2
+ import { NormalizedSchema } from '../schema';
3
3
  export declare function addRouting(host: Tree, options: NormalizedSchema): import("@nx/devkit").GeneratorCallback;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addRouting = void 0;
4
- const ast_utils_1 = require("../../../utils/ast-utils");
5
- const versions_1 = require("../../../utils/versions");
6
4
  const devkit_1 = require("@nx/devkit");
7
5
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
6
+ const ast_utils_1 = require("../../../utils/ast-utils");
7
+ const versions_1 = require("../../../utils/versions");
8
+ const maybe_js_1 = require("../../../utils/maybe-js");
8
9
  let tsModule;
9
10
  function addRouting(host, options) {
10
11
  if (!options.routing) {
@@ -13,7 +14,7 @@ function addRouting(host, options) {
13
14
  if (!tsModule) {
14
15
  tsModule = (0, ensure_typescript_1.ensureTypescript)();
15
16
  }
16
- const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, maybeJs(options, `src/app/${options.fileName}.tsx`));
17
+ const appPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, (0, maybe_js_1.maybeJs)(options, `src/app/${options.fileName}.tsx`));
17
18
  const appFileContent = host.read(appPath, 'utf-8');
18
19
  const appSource = tsModule.createSourceFile(appPath, appFileContent, tsModule.ScriptTarget.Latest, true);
19
20
  const changes = (0, devkit_1.applyChangesToString)(appFileContent, (0, ast_utils_1.addInitialRoutes)(appPath, appSource));
@@ -24,8 +25,3 @@ function addRouting(host, options) {
24
25
  return () => { };
25
26
  }
26
27
  exports.addRouting = addRouting;
27
- function maybeJs(options, path) {
28
- return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
29
- ? path.replace(/\.tsx?$/, '.js')
30
- : path;
31
- }
@@ -6,6 +6,8 @@ const js_1 = require("@nx/js");
6
6
  const path_1 = require("path");
7
7
  const create_ts_config_1 = require("../../../utils/create-ts-config");
8
8
  const get_in_source_vitest_tests_template_1 = require("../../../utils/get-in-source-vitest-tests-template");
9
+ const maybe_js_1 = require("../../../utils/maybe-js");
10
+ const has_webpack_plugin_1 = require("../../../utils/has-webpack-plugin");
9
11
  const get_app_tests_1 = require("./get-app-tests");
10
12
  function createApplicationFiles(host, options) {
11
13
  let styleSolutionSpecificAppFiles;
@@ -15,6 +17,9 @@ function createApplicationFiles(host, options) {
15
17
  else if (options.style === 'styled-jsx') {
16
18
  styleSolutionSpecificAppFiles = '../files/style-styled-jsx';
17
19
  }
20
+ else if (options.style === 'tailwind') {
21
+ styleSolutionSpecificAppFiles = '../files/style-tailwind';
22
+ }
18
23
  else if (options.style === 'none') {
19
24
  styleSolutionSpecificAppFiles = '../files/style-none';
20
25
  }
@@ -38,7 +43,12 @@ function createApplicationFiles(host, options) {
38
43
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-vite'), options.appProjectRoot, templateVariables);
39
44
  }
40
45
  else if (options.bundler === 'webpack') {
41
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, templateVariables);
46
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '../files/base-webpack'), options.appProjectRoot, {
47
+ ...templateVariables,
48
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(host)
49
+ ? createNxWebpackPluginOptions(options)
50
+ : null,
51
+ });
42
52
  if (options.compiler === 'babel') {
43
53
  (0, devkit_1.writeJson)(host, `${options.appProjectRoot}/.babelrc`, {
44
54
  presets: [
@@ -112,3 +122,22 @@ function createApplicationFiles(host, options) {
112
122
  (0, create_ts_config_1.createTsConfig)(host, options.appProjectRoot, 'app', options, relativePathToRootTsConfig);
113
123
  }
114
124
  exports.createApplicationFiles = createApplicationFiles;
125
+ function createNxWebpackPluginOptions(options) {
126
+ return {
127
+ target: 'web',
128
+ compiler: options.compiler ?? 'babel',
129
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.appProjectRoot != '.'
130
+ ? options.appProjectRoot
131
+ : options.projectName),
132
+ index: './src/index.html',
133
+ baseHref: '/',
134
+ main: (0, maybe_js_1.maybeJs)(options, `./src/main.tsx`),
135
+ tsConfig: './tsconfig.app.json',
136
+ assets: ['./src/favicon.ico', './src/assets'],
137
+ styles: options.styledModule || !options.hasStyles
138
+ ? []
139
+ : [
140
+ `./src/styles.${options.style !== 'tailwind' ? options.style : 'css'}`,
141
+ ],
142
+ };
143
+ }
@@ -4,7 +4,18 @@ exports.installCommonDependencies = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const versions_1 = require("../../../utils/versions");
6
6
  function installCommonDependencies(host, options) {
7
- const devDependencies = {};
7
+ if (options.skipPackageJson) {
8
+ return () => { };
9
+ }
10
+ const dependencies = {};
11
+ const devDependencies = {
12
+ '@types/node': versions_1.typesNodeVersion,
13
+ '@types/react': versions_1.typesReactVersion,
14
+ '@types/react-dom': versions_1.typesReactDomVersion,
15
+ };
16
+ if (options.bundler !== 'vite') {
17
+ dependencies['tslib'] = versions_1.tsLibVersion;
18
+ }
8
19
  // Vite requires style preprocessors to be installed manually.
9
20
  // `@nx/webpack` installs them automatically for now.
10
21
  if (options.bundler === 'vite' || options.unitTestRunner === 'vitest') {
@@ -28,6 +39,9 @@ function installCommonDependencies(host, options) {
28
39
  devDependencies['@babel/core'] = versions_1.babelCoreVersion;
29
40
  }
30
41
  }
42
+ if (options.unitTestRunner && options.unitTestRunner !== 'none') {
43
+ devDependencies['@testing-library/react'] = versions_1.testingLibraryReactVersion;
44
+ }
31
45
  return (0, devkit_1.addDependenciesToPackageJson)(host, {}, devDependencies);
32
46
  }
33
47
  exports.installCommonDependencies = installCommonDependencies;
@@ -26,15 +26,46 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
26
26
  rootProject: options.rootProject,
27
27
  callingGenerator,
28
28
  });
29
+ const nxJson = (0, devkit_1.readNxJson)(host);
30
+ const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
31
+ nxJson.useInferencePlugins !== false;
32
+ options.addPlugin ??= addPlugin;
29
33
  options.rootProject = appProjectRoot === '.';
30
34
  options.projectNameAndRootFormat = projectNameAndRootFormat;
35
+ let e2eWebServerTarget = 'serve';
36
+ if (options.addPlugin) {
37
+ if (nxJson.plugins) {
38
+ for (const plugin of nxJson.plugins) {
39
+ if (options.bundler === 'vite' &&
40
+ typeof plugin === 'object' &&
41
+ plugin.plugin === '@nx/vite/plugin' &&
42
+ plugin.options.serveTargetName) {
43
+ e2eWebServerTarget = plugin.options
44
+ .serveTargetName;
45
+ }
46
+ else if (options.bundler === 'webpack' &&
47
+ typeof plugin === 'object' &&
48
+ plugin.plugin === '@nx/webpack/plugin' &&
49
+ plugin.options.serveTargetName) {
50
+ e2eWebServerTarget = plugin.options
51
+ .serveTargetName;
52
+ }
53
+ }
54
+ }
55
+ }
56
+ let e2ePort = options.devServerPort ?? 4200;
57
+ if (nxJson.targetDefaults?.[e2eWebServerTarget] &&
58
+ nxJson.targetDefaults?.[e2eWebServerTarget].options?.port) {
59
+ e2ePort = nxJson.targetDefaults?.[e2eWebServerTarget].options?.port;
60
+ }
31
61
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
32
62
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
63
+ const e2eWebServerAddress = `http://localhost:${e2ePort}`;
33
64
  const parsedTags = options.tags
34
65
  ? options.tags.split(',').map((s) => s.trim())
35
66
  : [];
36
67
  const fileName = options.pascalCaseFiles ? 'App' : 'app';
37
- const styledModule = /^(css|scss|less|none)$/.test(options.style)
68
+ const styledModule = /^(css|scss|less|tailwind|none)$/.test(options.style)
38
69
  ? null
39
70
  : options.style;
40
71
  (0, assertion_1.assertValidStyle)(options.style);
@@ -48,6 +79,9 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
48
79
  appProjectRoot,
49
80
  e2eProjectName,
50
81
  e2eProjectRoot,
82
+ e2eWebServerAddress,
83
+ e2eWebServerTarget,
84
+ e2ePort,
51
85
  parsedTags,
52
86
  fileName,
53
87
  styledModule,
@@ -14,6 +14,7 @@ function setDefaults(host, options) {
14
14
  nxJson.generators['@nx/react'] = nxJson.generators['@nx/react'] || {};
15
15
  const prev = { ...nxJson.generators['@nx/react'] };
16
16
  const appDefaults = {
17
+ babel: true,
17
18
  style: options.style,
18
19
  linter: options.linter,
19
20
  bundler: options.bundler,
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateSpecConfig = void 0;
4
+ const maybe_js_1 = require("../../../utils/maybe-js");
4
5
  const jest_utils_1 = require("../../../utils/jest-utils");
5
6
  const devkit_1 = require("@nx/devkit");
6
7
  function updateSpecConfig(host, options) {
@@ -8,21 +9,20 @@ function updateSpecConfig(host, options) {
8
9
  return;
9
10
  }
10
11
  (0, devkit_1.updateJson)(host, `${options.appProjectRoot}/tsconfig.spec.json`, (json) => {
11
- json.types = json.types || [];
12
+ const compilerOptions = json.compilerOptions ?? {};
13
+ const types = compilerOptions.types ?? [];
12
14
  if (options.style === 'styled-jsx') {
13
- json.types.push('@nx/react/typings/styled-jsx.d.ts');
15
+ types.push('@nx/react/typings/styled-jsx.d.ts');
14
16
  }
15
- json.types = [
16
- ...json.types,
17
- '@nx/react/typings/cssmodule.d.ts',
18
- '@nx/react/typings/image.d.ts',
19
- ];
17
+ types.push('@nx/react/typings/cssmodule.d.ts', '@nx/react/typings/image.d.ts');
18
+ compilerOptions.types = types;
19
+ json.compilerOptions = compilerOptions;
20
20
  return json;
21
21
  });
22
22
  if (options.unitTestRunner !== 'jest') {
23
23
  return;
24
24
  }
25
- const configPath = `${options.appProjectRoot}/jest.config.${options.js ? 'js' : 'ts'}`;
25
+ const configPath = (0, maybe_js_1.maybeJs)(options, `${options.appProjectRoot}/jest.config.ts`);
26
26
  const originalContent = host.read(configPath, 'utf-8');
27
27
  const content = (0, jest_utils_1.updateJestConfigContent)(originalContent);
28
28
  host.write(configPath, content);
@@ -28,6 +28,7 @@ export interface Schema {
28
28
  rootProject?: boolean;
29
29
  bundler?: 'webpack' | 'vite' | 'rspack';
30
30
  minimal?: boolean;
31
+ addPlugin?: boolean;
31
32
  }
32
33
 
33
34
  export interface NormalizedSchema<T extends Schema = Schema> extends T {
@@ -35,9 +36,13 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
35
36
  appProjectRoot: string;
36
37
  e2eProjectName: string;
37
38
  e2eProjectRoot: string;
39
+ e2eWebServerAddress: string;
40
+ e2eWebServerTarget: string;
41
+ e2ePort: number;
38
42
  parsedTags: string[];
39
43
  fileName: string;
40
44
  styledModule: null | SupportedStyles;
41
45
  hasStyles: boolean;
42
46
  unitTestRunner: 'jest' | 'vitest' | 'none';
47
+ addPlugin?: boolean;
43
48
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxReactApp",
5
5
  "title": "Create a React Application",
@@ -56,11 +56,15 @@
56
56
  },
57
57
  {
58
58
  "value": "scss",
59
- "label": "SASS(.scss) [ http://sass-lang.com ]"
59
+ "label": "SASS(.scss) [ https://sass-lang.com ]"
60
60
  },
61
61
  {
62
62
  "value": "less",
63
- "label": "LESS [ http://lesscss.org ]"
63
+ "label": "LESS [ https://lesscss.org ]"
64
+ },
65
+ {
66
+ "value": "tailwind",
67
+ "label": "tailwind [ https://tailwindcss.com/ ]"
64
68
  },
65
69
  {
66
70
  "value": "styled-components",