@nx/react 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca
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.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/generators.json +9 -13
- package/index.d.ts +1 -2
- package/index.js +2 -5
- package/mf/dynamic-federation.d.ts +64 -0
- package/mf/dynamic-federation.js +64 -0
- package/migrations.json +80 -148
- package/module-federation.d.ts +6 -4
- package/module-federation.js +16 -7
- package/package.json +11 -11
- package/plugins/bundle-rollup.js +4 -1
- package/plugins/component-testing/index.js +1 -1
- package/plugins/jest.js +6 -11
- package/plugins/nx-react-webpack-plugin/lib/apply-react-config.js +6 -22
- package/plugins/storybook/index.js +1 -2
- package/plugins/with-react.d.ts +4 -0
- package/router-plugin.d.ts +1 -0
- package/router-plugin.js +5 -0
- package/src/executors/module-federation-dev-server/lib/index.d.ts +2 -0
- package/src/executors/module-federation-dev-server/lib/index.js +5 -0
- package/src/executors/module-federation-dev-server/lib/normalize-options.d.ts +4 -0
- package/src/executors/module-federation-dev-server/lib/normalize-options.js +19 -0
- package/src/executors/module-federation-dev-server/lib/start-remotes.d.ts +5 -0
- package/src/executors/module-federation-dev-server/lib/start-remotes.js +33 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +1 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -110
- package/src/executors/module-federation-dev-server/schema.d.ts +9 -7
- package/src/executors/module-federation-dev-server/schema.json +15 -10
- package/src/executors/module-federation-ssr-dev-server/lib/index.d.ts +2 -0
- package/src/executors/module-federation-ssr-dev-server/lib/index.js +5 -0
- package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.d.ts +4 -0
- package/src/executors/module-federation-ssr-dev-server/lib/normalize-options.js +23 -0
- package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.d.ts +5 -0
- package/src/executors/module-federation-ssr-dev-server/lib/start-remotes.js +34 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +1 -17
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +5 -153
- package/src/executors/module-federation-ssr-dev-server/schema.d.ts +29 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +14 -9
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts +2 -2
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +11 -12
- package/src/executors/module-federation-static-server/schema.json +2 -1
- package/src/generators/application/application.d.ts +3 -3
- package/src/generators/application/application.js +108 -186
- package/src/generators/application/files/base-rsbuild/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-rsbuild/src/assets/.gitkeep +0 -0
- package/src/generators/application/files/base-rsbuild/src/favicon.ico +0 -0
- package/src/generators/application/files/base-rsbuild/src/index.html +14 -0
- package/src/generators/application/files/base-rsbuild/src/main.tsx__tmpl__ +32 -0
- package/src/generators/application/files/base-rsbuild/tsconfig.app.json__tmpl__ +31 -0
- package/src/generators/application/files/base-rspack/rspack.config.js__tmpl__ +53 -0
- package/src/generators/application/files/base-rspack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-rspack/src/main.tsx__tmpl__ +27 -5
- package/src/generators/application/files/base-rspack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-vite/src/main.tsx__tmpl__ +31 -6
- package/src/generators/application/files/base-vite/tsconfig.app.json__tmpl__ +20 -3
- package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +3 -3
- package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +22 -2
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +21 -4
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +4 -4
- package/src/generators/application/files/react-router-ssr/common/app/app-nav.tsx__tmpl__ +14 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.client.tsx__tmpl__ +18 -0
- package/src/generators/application/files/react-router-ssr/common/app/entry.server.tsx__tmpl__ +74 -0
- package/src/generators/application/files/react-router-ssr/common/app/root.tsx__tmpl__ +51 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes/about.tsx__tmpl__ +7 -0
- package/src/generators/application/files/react-router-ssr/common/app/routes.tsx__tmpl__ +6 -0
- package/src/generators/application/files/react-router-ssr/common/public/favicon.ico +0 -0
- package/src/generators/application/files/react-router-ssr/common/react-router.config.ts__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/common/tests/routes/_index.spec.tsx__tmpl__ +16 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.app.json__tmpl__ +23 -0
- package/src/generators/application/files/react-router-ssr/common/tsconfig.json__tmpl__ +27 -0
- package/src/generators/application/files/react-router-ssr/non-root/.gitignore__tmpl__ +5 -0
- package/src/generators/application/files/react-router-ssr/non-root/package.json__tmpl__ +21 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/claimed/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/not-configured/app/nx-welcome.tsx__tmpl__ +866 -0
- package/src/generators/application/files/react-router-ssr/nx-welcome/unclaimed/app/nx-welcome.tsx__tmpl__ +864 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/package.json__tmpl__ +21 -0
- package/src/generators/application/files/react-router-ssr/ts-solution/tsconfig.app.json__tmpl__ +39 -0
- package/src/generators/application/files/style-css-module/src/app/__fileName__.tsx__tmpl__ +28 -18
- package/src/generators/application/files/style-global-css/src/app/__fileName__.tsx__tmpl__ +29 -20
- package/src/generators/application/files/style-none/src/app/__fileName__.tsx__tmpl__ +26 -16
- package/src/generators/application/files/style-styled-jsx/src/app/__fileName__.tsx__tmpl__ +31 -22
- package/src/generators/application/files/style-styled-module/src/app/__fileName__.tsx__tmpl__ +30 -21
- package/src/generators/application/files/style-tailwind/src/app/__fileName__.tsx__tmpl__ +29 -19
- package/src/generators/application/lib/add-e2e.d.ts +1 -1
- package/src/generators/application/lib/add-e2e.js +74 -65
- package/src/generators/application/lib/add-jest.js +27 -2
- package/src/generators/application/lib/add-linting.d.ts +4 -0
- package/src/generators/application/lib/add-linting.js +86 -0
- package/src/generators/application/lib/add-project.js +112 -6
- package/src/generators/application/lib/add-routing.js +1 -1
- package/src/generators/application/lib/bundlers/add-rsbuild.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rsbuild.js +63 -0
- package/src/generators/application/lib/bundlers/add-rspack.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-rspack.js +37 -0
- package/src/generators/application/lib/bundlers/add-vite.d.ts +4 -0
- package/src/generators/application/lib/bundlers/add-vite.js +76 -0
- package/src/generators/application/lib/bundlers/add-webpack.d.ts +3 -0
- package/src/generators/application/lib/bundlers/add-webpack.js +18 -0
- package/src/generators/application/lib/create-application-files.d.ts +61 -0
- package/src/generators/application/lib/create-application-files.js +102 -19
- package/src/generators/application/lib/get-app-tests.js +10 -11
- package/src/generators/application/lib/install-common-dependencies.d.ts +1 -1
- package/src/generators/application/lib/install-common-dependencies.js +18 -4
- package/src/generators/application/lib/normalize-options.d.ts +1 -3
- package/src/generators/application/lib/normalize-options.js +17 -19
- package/src/generators/application/lib/update-jest-config.js +5 -0
- package/src/generators/application/schema.d.ts +12 -6
- package/src/generators/application/schema.json +44 -42
- package/src/generators/component/component.d.ts +0 -1
- package/src/generators/component/component.js +19 -37
- package/src/generators/component/files/__fileName__.__ext__ +83 -0
- package/src/generators/component/lib/normalize-options.js +13 -15
- package/src/generators/component/schema.d.ts +13 -25
- package/src/generators/component/schema.json +13 -49
- package/src/generators/component-story/component-story.js +1 -2
- package/src/generators/component-story/files/jsx/__componentFileName__.stories.jsx__tmpl__ +5 -5
- package/src/generators/component-story/files/tsx/__componentFileName__.stories.tsx__tmpl__ +3 -4
- package/src/generators/component-test/component-test.js +1 -1
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +0 -2
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.js +7 -4
- package/src/generators/federate-module/federate-module.js +12 -22
- package/src/generators/federate-module/schema.d.ts +0 -1
- package/src/generators/federate-module/schema.json +13 -12
- package/src/generators/hook/files/{__fileName__.ts__tmpl__ → __fileName__.__ext__} +3 -1
- package/src/generators/hook/hook.d.ts +0 -1
- package/src/generators/hook/hook.js +35 -83
- package/src/generators/hook/schema.d.ts +4 -17
- package/src/generators/hook/schema.json +19 -46
- package/src/generators/host/files/common/src/app/__fileName__.js__tmpl__ +28 -21
- package/src/generators/host/files/common/src/main.js__tmpl__ +12 -9
- package/src/generators/host/files/common-ts/src/app/__fileName__.tsx__tmpl__ +28 -28
- package/src/generators/host/files/common-ts/src/main.ts__tmpl__ +12 -9
- package/src/generators/host/files/rspack-common/src/app/__fileName__.jsx__tmpl__ +22 -13
- package/src/generators/host/files/rspack-common/src/main.jsx__tmpl__ +12 -9
- package/src/generators/host/files/rspack-module-federation/module-federation.config.js__tmpl__ +8 -5
- package/src/generators/host/files/rspack-module-federation/rspack.config.js__tmpl__ +37 -13
- package/src/generators/host/files/rspack-module-federation/rspack.config.prod.js__tmpl__ +60 -30
- package/src/generators/host/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +16 -5
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +16 -7
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +66 -0
- package/src/generators/host/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +49 -0
- package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +61 -30
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +37 -13
- package/src/generators/host/files/webpack-module-federation/module-federation.config.js__tmpl__ +8 -5
- package/src/generators/host/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation/webpack.config.prod.js__tmpl__ +24 -22
- package/src/generators/host/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +10 -7
- package/src/generators/host/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +10 -7
- package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +22 -19
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +25 -23
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +4 -3
- package/src/generators/host/host.d.ts +0 -1
- package/src/generators/host/host.js +31 -27
- package/src/generators/host/lib/add-module-federation-files.js +29 -13
- package/src/generators/host/lib/normalize-host-name.d.ts +2 -0
- package/src/generators/host/lib/normalize-host-name.js +12 -0
- package/src/generators/host/lib/normalize-remote.js +10 -6
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +3 -3
- package/src/generators/host/lib/setup-ssr-for-host.js +46 -22
- package/src/generators/host/lib/update-module-federation-tsconfig.d.ts +3 -0
- package/src/generators/host/lib/update-module-federation-tsconfig.js +39 -0
- package/src/generators/host/schema.d.ts +2 -5
- package/src/generators/host/schema.json +16 -27
- package/src/generators/init/init.d.ts +1 -1
- package/src/generators/init/init.js +31 -6
- package/src/generators/init/schema.d.ts +2 -0
- package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/files/vite/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/lib/add-linting.js +1 -1
- package/src/generators/library/lib/add-rollup-build-target.d.ts +3 -1
- package/src/generators/library/lib/add-rollup-build-target.js +34 -32
- package/src/generators/library/lib/create-files.d.ts +1 -1
- package/src/generators/library/lib/create-files.js +23 -2
- package/src/generators/library/lib/determine-entry-fields.d.ts +3 -0
- package/src/generators/library/lib/determine-entry-fields.js +22 -0
- package/src/generators/library/lib/install-common-dependencies.d.ts +1 -1
- package/src/generators/library/lib/install-common-dependencies.js +5 -3
- package/src/generators/library/lib/normalize-options.js +11 -6
- package/src/generators/library/library.js +80 -35
- package/src/generators/library/schema.d.ts +5 -5
- package/src/generators/library/schema.json +38 -36
- package/src/generators/redux/files/js/__fileName__.__ext__ +114 -0
- package/src/generators/redux/files/{__fileName__.slice.spec.ts__tmpl__ → js/__fileName__.spec.__ext__} +1 -1
- package/src/generators/redux/files/ts/__fileName__.spec.__ext__ +56 -0
- package/src/generators/redux/redux.d.ts +0 -1
- package/src/generators/redux/redux.js +27 -36
- package/src/generators/redux/schema.d.ts +12 -8
- package/src/generators/redux/schema.json +21 -23
- package/src/generators/remote/files/rspack-module-federation/module-federation.config.js__tmpl__ +10 -7
- package/src/generators/remote/files/rspack-module-federation/rspack.config.js__tmpl__ +40 -13
- package/src/generators/remote/files/rspack-module-federation-ssr/module-federation.server.config.js__tmpl__ +13 -4
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.config.js__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +13 -4
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +69 -0
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/server.ts__tmpl__ +2 -2
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__ +45 -0
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +40 -13
- package/src/generators/remote/files/webpack-module-federation/module-federation.config.js__tmpl__ +10 -7
- package/src/generators/remote/files/webpack-module-federation/webpack.config.js__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr/module-federation.server.config.js__tmpl__ +7 -4
- package/src/generators/remote/files/webpack-module-federation-ssr/webpack.server.config.js__tmpl__ +2 -2
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +8 -5
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +2 -2
- package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +11 -8
- package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +2 -2
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +1 -1
- package/src/generators/remote/lib/setup-ssr-for-remote.js +37 -15
- package/src/generators/remote/lib/setup-tspath-for-remote.js +1 -3
- package/src/generators/remote/lib/update-host-with-remote.js +2 -2
- package/src/generators/remote/remote.d.ts +0 -1
- package/src/generators/remote/remote.js +57 -33
- package/src/generators/remote/schema.d.ts +2 -5
- package/src/generators/remote/schema.json +16 -27
- package/src/generators/setup-tailwind/lib/update-project.js +1 -2
- package/src/generators/stories/schema.json +0 -10
- package/src/generators/stories/stories.d.ts +1 -3
- package/src/generators/stories/stories.js +9 -20
- package/src/generators/storybook-configuration/configuration.js +2 -11
- package/src/generators/storybook-configuration/schema.d.ts +0 -3
- package/src/generators/storybook-configuration/schema.json +0 -15
- package/src/migrations/update-18-0-0/add-mf-env-var-to-target-defaults.js +11 -6
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-mf-imports-to-new-package.js +66 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts +2 -0
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +41 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts +2 -0
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +18 -0
- package/src/migrations/update-21-0-0/update-babel-loose.d.ts +2 -0
- package/src/migrations/update-21-0-0/update-babel-loose.js +30 -0
- package/src/plugins/router-plugin.d.ts +10 -0
- package/src/plugins/router-plugin.js +221 -0
- package/src/rules/update-module-federation-project.d.ts +2 -1
- package/src/rules/update-module-federation-project.js +37 -48
- package/src/utils/add-mf-env-to-inputs.d.ts +1 -1
- package/src/utils/add-mf-env-to-inputs.js +8 -11
- package/src/utils/assertion.d.ts +2 -0
- package/src/utils/assertion.js +6 -0
- package/src/utils/ast-utils.d.ts +1 -1
- package/src/utils/ast-utils.js +2 -2
- package/src/utils/create-ts-config.js +57 -7
- package/src/utils/ct-utils.d.ts +1 -1
- package/src/utils/ct-utils.js +2 -7
- package/src/utils/has-rsbuild-plugin.d.ts +2 -0
- package/src/utils/has-rsbuild-plugin.js +10 -0
- package/src/utils/has-rspack-plugin.d.ts +2 -0
- package/src/utils/has-rspack-plugin.js +10 -0
- package/src/utils/testing-generators.js +2 -4
- package/src/utils/version-utils.d.ts +14 -0
- package/src/utils/version-utils.js +56 -0
- package/src/utils/versions.d.ts +25 -17
- package/src/utils/versions.js +28 -19
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +0 -84
- package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +0 -13
- package/src/generators/component-cypress-spec/component-cypress-spec.js +0 -104
- package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +0 -13
- package/src/generators/component-cypress-spec/schema.json +0 -45
- package/src/generators/host/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/generators/library/files/common/package.json__tmpl__ +0 -4
- package/src/generators/library/files/vite/package.json__tmpl__ +0 -12
- package/src/generators/remote/files/rspack-module-federation-ssr/rspack.server.config.js__tmpl__ +0 -16
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.server.config.ts__tmpl__ +0 -16
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
- package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.d.ts +0 -2
- package/src/migrations/update-16-2-0-remove-package/update-16-2-0-remove-package.js +0 -8
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.d.ts +0 -2
- package/src/migrations/update-16-3-0/remove-types-react-router-dom-package.js +0 -8
- package/src/migrations/update-16-7-0/add-babel-core.d.ts +0 -2
- package/src/migrations/update-16-7-0/add-babel-core.js +0 -14
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.d.ts +0 -2
- package/src/migrations/update-16-7-0-add-typings/update-16-7-0-add-typings.js +0 -57
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.d.ts +0 -2
- package/src/migrations/update-18-1-1/fix-target-defaults-inputs.js +0 -53
- package/src/module-federation/load-config.d.ts +0 -3
- package/src/module-federation/load-config.js +0 -15
- package/src/module-federation/models.d.ts +0 -24
- package/src/module-federation/models.js +0 -2
- package/src/module-federation/package-json.d.ts +0 -8
- package/src/module-federation/package-json.js +0 -12
- package/src/module-federation/utils.d.ts +0 -12
- package/src/module-federation/utils.js +0 -75
- package/src/module-federation/with-module-federation-ssr.d.ts +0 -2
- package/src/module-federation/with-module-federation-ssr.js +0 -50
- package/src/module-federation/with-module-federation.d.ts +0 -7
- package/src/module-federation/with-module-federation.js +0 -63
- package/src/utils/build-static.remotes.d.ts +0 -4
- package/src/utils/build-static.remotes.js +0 -65
- package/src/utils/format-file.d.ts +0 -1
- package/src/utils/format-file.js +0 -11
- /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__ext__} +0 -0
- /package/src/generators/hook/files/{__fileName__.spec.tsx__tmpl__ → __fileName__.spec.__specExt__} +0 -0
- /package/src/generators/redux/files/{__fileName__.slice.ts__tmpl__ → ts/__fileName__.__ext__} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reduxGenerator = reduxGenerator;
|
|
4
|
-
exports.reduxGeneratorInternal = reduxGeneratorInternal;
|
|
5
4
|
const path = require("path");
|
|
6
5
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
7
6
|
const versions_1 = require("../../utils/versions");
|
|
@@ -9,14 +8,9 @@ const devkit_1 = require("@nx/devkit");
|
|
|
9
8
|
const js_1 = require("@nx/js");
|
|
10
9
|
const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
|
|
11
10
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
11
|
+
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
12
12
|
let tsModule;
|
|
13
13
|
async function reduxGenerator(host, schema) {
|
|
14
|
-
return reduxGeneratorInternal(host, {
|
|
15
|
-
nameAndDirectoryFormat: 'derived',
|
|
16
|
-
...schema,
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
async function reduxGeneratorInternal(host, schema) {
|
|
20
14
|
const options = await normalizeOptions(host, schema);
|
|
21
15
|
generateReduxFiles(host, options);
|
|
22
16
|
addExportsToBarrel(host, options);
|
|
@@ -27,13 +21,10 @@ async function reduxGeneratorInternal(host, schema) {
|
|
|
27
21
|
return installTask;
|
|
28
22
|
}
|
|
29
23
|
function generateReduxFiles(host, options) {
|
|
30
|
-
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, '
|
|
24
|
+
(0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, 'files', options.fileExtensionType), options.projectDirectory, {
|
|
31
25
|
...options,
|
|
32
|
-
|
|
26
|
+
ext: options.fileExtension,
|
|
33
27
|
});
|
|
34
|
-
if (options.js) {
|
|
35
|
-
(0, devkit_1.toJS)(host);
|
|
36
|
-
}
|
|
37
28
|
}
|
|
38
29
|
function addReduxPackageDependencies(host) {
|
|
39
30
|
return (0, devkit_1.addDependenciesToPackageJson)(host, {
|
|
@@ -45,16 +36,17 @@ function addExportsToBarrel(host, options) {
|
|
|
45
36
|
if (!tsModule) {
|
|
46
37
|
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
47
38
|
}
|
|
48
|
-
const indexFilePath =
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
52
|
-
const statePath = options.directory
|
|
53
|
-
? `./lib/${options.directory}/${options.fileName}`
|
|
54
|
-
: `./lib/${options.fileName}`;
|
|
55
|
-
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from '${statePath}.slice';`));
|
|
56
|
-
host.write(indexFilePath, changes);
|
|
39
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourcePath, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
|
|
40
|
+
if (!host.exists(indexFilePath)) {
|
|
41
|
+
return;
|
|
57
42
|
}
|
|
43
|
+
const indexSource = host.read(indexFilePath, 'utf-8');
|
|
44
|
+
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
45
|
+
const statePath = options.path
|
|
46
|
+
? `./lib/${options.path}/${options.fileName}`
|
|
47
|
+
: `./lib/${options.fileName}`;
|
|
48
|
+
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, ast_utils_1.addImport)(indexSourceFile, `export * from '${statePath}.slice';`));
|
|
49
|
+
host.write(indexFilePath, changes);
|
|
58
50
|
}
|
|
59
51
|
function addStoreConfiguration(host, options) {
|
|
60
52
|
if (!options.appProjectSourcePath) {
|
|
@@ -84,30 +76,27 @@ function updateReducerConfiguration(host, options) {
|
|
|
84
76
|
host.write(options.appMainFilePath, changes);
|
|
85
77
|
}
|
|
86
78
|
async function normalizeOptions(host, options) {
|
|
87
|
-
const { artifactName: name, directory, fileName, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
88
|
-
|
|
89
|
-
callingGenerator: '@nx/react:redux',
|
|
79
|
+
const { artifactName: name, directory, fileName, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
80
|
+
path: options.path,
|
|
90
81
|
name: options.name,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
project: options.project,
|
|
96
|
-
fileExtension: 'tsx',
|
|
82
|
+
suffix: 'slice',
|
|
83
|
+
allowedFileExtensions: ['js', 'ts'],
|
|
84
|
+
fileExtension: options.js ? 'js' : 'ts',
|
|
85
|
+
js: options.js,
|
|
97
86
|
});
|
|
98
87
|
let appProjectSourcePath;
|
|
99
88
|
let appMainFilePath;
|
|
100
89
|
const extraNames = (0, devkit_1.names)(name);
|
|
101
90
|
const projects = (0, devkit_1.getProjects)(host);
|
|
102
91
|
const project = projects.get(projectName);
|
|
103
|
-
const { sourceRoot, projectType } = project;
|
|
92
|
+
const { root, sourceRoot, projectType } = project;
|
|
104
93
|
const tsConfigJson = (0, devkit_1.readJson)(host, (0, js_1.getRootTsConfigPathInTree)(host));
|
|
105
94
|
const tsPaths = tsConfigJson.compilerOptions
|
|
106
95
|
? tsConfigJson.compilerOptions.paths || {}
|
|
107
96
|
: {};
|
|
108
|
-
const modulePath = projectType === 'application'
|
|
109
|
-
? options.
|
|
110
|
-
? `./app/${options.
|
|
97
|
+
const modulePath = (0, ts_solution_setup_1.getProjectType)(host, root, projectType) === 'application'
|
|
98
|
+
? options.path
|
|
99
|
+
? `./app/${options.path}/${extraNames.fileName}.slice`
|
|
111
100
|
: `./app/${extraNames.fileName}.slice`
|
|
112
101
|
: Object.keys(tsPaths).find((k) => tsPaths[k].some((s) => s.includes(sourceRoot)));
|
|
113
102
|
// If --project is set to an app, automatically configure store
|
|
@@ -130,8 +119,10 @@ async function normalizeOptions(host, options) {
|
|
|
130
119
|
...options,
|
|
131
120
|
...extraNames,
|
|
132
121
|
fileName,
|
|
133
|
-
|
|
134
|
-
|
|
122
|
+
fileExtension,
|
|
123
|
+
fileExtensionType,
|
|
124
|
+
constantName: (0, devkit_1.names)(name).constantName.toUpperCase(),
|
|
125
|
+
projectDirectory: directory,
|
|
135
126
|
projectType,
|
|
136
127
|
projectSourcePath: sourceRoot,
|
|
137
128
|
projectModulePath: modulePath,
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
+
import type { FileExtensionType } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
|
+
|
|
1
3
|
export interface Schema {
|
|
2
|
-
|
|
4
|
+
path: string;
|
|
5
|
+
name?: string;
|
|
6
|
+
appProject?: string;
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
|
-
* @deprecated Provide the
|
|
9
|
+
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
5
10
|
*/
|
|
6
|
-
|
|
7
|
-
directory?: string;
|
|
8
|
-
appProject?: string;
|
|
9
|
-
js?: string;
|
|
10
|
-
nameAndDirectoryFormat?: 'as-provided' | 'derived';
|
|
11
|
+
js?: boolean;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
interface NormalizedSchema extends Schema {
|
|
14
|
+
interface NormalizedSchema extends Omit<Schema, 'js'> {
|
|
14
15
|
projectType: string;
|
|
16
|
+
projectDirectory: string;
|
|
15
17
|
projectSourcePath: string;
|
|
16
18
|
projectModulePath: string;
|
|
17
19
|
appProjectSourcePath: string;
|
|
@@ -20,4 +22,6 @@ interface NormalizedSchema extends Schema {
|
|
|
20
22
|
constantName: string;
|
|
21
23
|
propertyName: string;
|
|
22
24
|
fileName: string;
|
|
25
|
+
fileExtension: string;
|
|
26
|
+
fileExtensionType: FileExtensionType;
|
|
23
27
|
}
|
|
@@ -5,36 +5,34 @@
|
|
|
5
5
|
"title": "Create Redux state",
|
|
6
6
|
"description": "Create a Redux state slice for a React project.",
|
|
7
7
|
"type": "object",
|
|
8
|
+
"examples": [
|
|
9
|
+
{
|
|
10
|
+
"description": "Generate a Redux state slice with the exported symbol matching the file name. It results in the slice `fooSlice` at `mylib/src/lib/foo.slice.ts`",
|
|
11
|
+
"command": "nx g @nx/react:redux mylib/src/lib/foo.slice.ts"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"description": "Generate a Redux state slice with the exported symbol different from the file name. It results in the slice `customSlice` at `mylib/src/lib/foo.slice.ts`",
|
|
15
|
+
"command": "nx g @nx/react:redux mylib/src/lib/foo.slice.ts --name=custom"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "Generate a Redux state slice without providing the \"slice\" suffix and the file extension. It results in the slice `fooSlice` at `mylib/src/lib/foo.slice.ts`",
|
|
19
|
+
"command": "nx g @nx/react:redux mylib/src/lib/foo"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
8
22
|
"properties": {
|
|
9
|
-
"
|
|
23
|
+
"path": {
|
|
10
24
|
"type": "string",
|
|
11
|
-
"description": "Redux slice
|
|
25
|
+
"description": "The file path to the Redux state slice. Relative to the current working directory.",
|
|
12
26
|
"$default": {
|
|
13
27
|
"$source": "argv",
|
|
14
28
|
"index": 0
|
|
15
29
|
},
|
|
30
|
+
"x-prompt": "What is the Redux stateslice file path?",
|
|
16
31
|
"x-priority": "important"
|
|
17
32
|
},
|
|
18
|
-
"
|
|
19
|
-
"type": "string",
|
|
20
|
-
"description": "The name of the project to add the slice to. If it is an application, then the store configuration will be updated too.",
|
|
21
|
-
"alias": "p",
|
|
22
|
-
"$default": {
|
|
23
|
-
"$source": "projectName"
|
|
24
|
-
},
|
|
25
|
-
"x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v20."
|
|
26
|
-
},
|
|
27
|
-
"directory": {
|
|
28
|
-
"type": "string",
|
|
29
|
-
"alias": "dir",
|
|
30
|
-
"default": "",
|
|
31
|
-
"description": "The directory at which to create the Redux files. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
|
|
32
|
-
"x-priority": "important"
|
|
33
|
-
},
|
|
34
|
-
"nameAndDirectoryFormat": {
|
|
35
|
-
"description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
|
|
33
|
+
"name": {
|
|
36
34
|
"type": "string",
|
|
37
|
-
"
|
|
35
|
+
"description": "The Redux state slice symbol name. Defaults to the last segment of the file path."
|
|
38
36
|
},
|
|
39
37
|
"appProject": {
|
|
40
38
|
"type": "string",
|
|
@@ -44,8 +42,8 @@
|
|
|
44
42
|
"js": {
|
|
45
43
|
"type": "boolean",
|
|
46
44
|
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
47
|
-
"
|
|
45
|
+
"x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
|
|
48
46
|
}
|
|
49
47
|
},
|
|
50
|
-
"required": ["
|
|
48
|
+
"required": ["path"]
|
|
51
49
|
}
|
package/src/generators/remote/files/rspack-module-federation/module-federation.config.js__tmpl__
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nx requires a default export of the config to allow correct resolution of the module federation graph.
|
|
3
|
+
**/
|
|
1
4
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
name: '<%= projectName %>',
|
|
6
|
+
<%_ if (dynamic) { _%>
|
|
7
|
+
library: { type: 'var', name: '<%= projectName %>'},
|
|
8
|
+
<%_ } _%>
|
|
9
|
+
exposes: {
|
|
10
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
11
|
+
},
|
|
9
12
|
};
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
const {
|
|
2
|
-
const {
|
|
1
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
2
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
3
|
+
const { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } = require('@nx/module-federation/rspack');
|
|
4
|
+
const { join } = require('path');
|
|
3
5
|
|
|
4
|
-
const
|
|
6
|
+
const config = require('./module-federation.config');
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
+
module.exports = {
|
|
9
|
+
output: {
|
|
10
|
+
path: join(__dirname, '<%= rspackPluginOptions.outputPath %>'),
|
|
11
|
+
publicPath: 'auto'
|
|
12
|
+
},
|
|
13
|
+
devServer: {
|
|
14
|
+
port: <%= devServerPort %>,
|
|
15
|
+
headers: {
|
|
16
|
+
"Access-Control-Allow-Origin": "*"
|
|
17
|
+
},
|
|
18
|
+
historyApiFallback: {
|
|
19
|
+
index: '/index.html',
|
|
20
|
+
disableDotRule: true,
|
|
21
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
plugins: [
|
|
25
|
+
new NxAppRspackPlugin({
|
|
26
|
+
tsConfig: '<%= rspackPluginOptions.tsConfig %>',
|
|
27
|
+
main: '<%= rspackPluginOptions.main %>',
|
|
28
|
+
index: '<%= rspackPluginOptions.index %>',
|
|
29
|
+
baseHref: '<%= rspackPluginOptions.baseHref %>',
|
|
30
|
+
assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
|
|
31
|
+
styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
|
|
32
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
33
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
34
|
+
}),
|
|
35
|
+
new NxReactRspackPlugin({
|
|
36
|
+
// Uncomment this line if you don't want to use SVGR
|
|
37
|
+
// See: https://react-svgr.com/
|
|
38
|
+
// svgr: false
|
|
39
|
+
}),
|
|
40
|
+
new NxModuleFederationPlugin({ config }, { dts: false }),
|
|
41
|
+
new NxModuleFederationDevServerPlugin({ config }),
|
|
42
|
+
],
|
|
8
43
|
};
|
|
9
|
-
|
|
10
|
-
// Nx plugins for rspack to build config object from Nx options and context.
|
|
11
|
-
/**
|
|
12
|
-
* DTS Plugin is disabled in Nx Workspaces as Nx already provides Typing support Module Federation
|
|
13
|
-
* The DTS Plugin can be enabled by setting dts: true
|
|
14
|
-
* Learn more about the DTS Plugin here: https://module-federation.io/configure/dts.html
|
|
15
|
-
*/
|
|
16
|
-
module.exports = composePlugins(withNx(), withReact(), withModuleFederation(config, { dts: false }));
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nx requires a default export of the config to allow correct resolution of the module federation graph.
|
|
3
|
+
**/
|
|
1
4
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
name: '<%= projectName %>',
|
|
6
|
+
exposes: {
|
|
7
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
8
|
+
},
|
|
9
|
+
shared: (libraryName, libraryConfig) => {
|
|
10
|
+
return {
|
|
11
|
+
...libraryConfig,
|
|
12
|
+
eager: true
|
|
13
|
+
}
|
|
14
|
+
},
|
|
6
15
|
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { NxAppRspackPlugin } = require('@nx/rspack/app-plugin');
|
|
2
|
+
const { NxReactRspackPlugin } = require('@nx/rspack/react-plugin');
|
|
3
|
+
const { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } = require('@nx/module-federation/rspack');
|
|
4
|
+
const { join } = require('path');
|
|
5
|
+
|
|
6
|
+
const browserMfConfig = require('./module-federation.config');
|
|
7
|
+
const serverMfConfig = require('./module-federation.server.config');
|
|
8
|
+
|
|
9
|
+
const browserRspackConfig = {
|
|
10
|
+
name: 'browser',
|
|
11
|
+
output: {
|
|
12
|
+
path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'browser'),
|
|
13
|
+
publicPath: 'auto'
|
|
14
|
+
},
|
|
15
|
+
devServer: {
|
|
16
|
+
port: <%= devServerPort %>,
|
|
17
|
+
headers: {
|
|
18
|
+
"Access-Control-Allow-Origin": "*"
|
|
19
|
+
},
|
|
20
|
+
historyApiFallback: {
|
|
21
|
+
index: '/index.html',
|
|
22
|
+
disableDotRule: true,
|
|
23
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
24
|
+
},
|
|
25
|
+
devMiddleware: {
|
|
26
|
+
writeToDisk: (file: string) => !file.includes('.hot-update.'),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
plugins: [
|
|
30
|
+
new NxAppRspackPlugin({
|
|
31
|
+
tsConfig: '<%= rspackPluginOptions.tsConfig %>',
|
|
32
|
+
main: '<%= rspackPluginOptions.main %>',
|
|
33
|
+
index: '<%= rspackPluginOptions.index %>',
|
|
34
|
+
baseHref: '<%= rspackPluginOptions.baseHref %>',
|
|
35
|
+
assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
|
|
36
|
+
styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
|
|
37
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
38
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
39
|
+
}),
|
|
40
|
+
new NxReactRspackPlugin({
|
|
41
|
+
// Uncomment this line if you don't want to use SVGR
|
|
42
|
+
// See: https://react-svgr.com/
|
|
43
|
+
// svgr: false
|
|
44
|
+
}),
|
|
45
|
+
new NxModuleFederationPlugin({ config: browserMfConfig }, { dts: false }),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const serverRspackConfig = {
|
|
50
|
+
name: 'server',
|
|
51
|
+
target: 'async-node',
|
|
52
|
+
output: {
|
|
53
|
+
path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
|
|
54
|
+
filename: 'server.js'
|
|
55
|
+
},
|
|
56
|
+
plugins: [
|
|
57
|
+
new NxAppRspackPlugin({
|
|
58
|
+
outputPath: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
|
|
59
|
+
outputFileName: 'server.js',
|
|
60
|
+
tsConfig: '<%= rspackPluginOptions.tsConfig %>',
|
|
61
|
+
main: '<%= rspackPluginOptions.mainServer %>',
|
|
62
|
+
baseHref: '<%= rspackPluginOptions.baseHref %>',
|
|
63
|
+
}),
|
|
64
|
+
new NxModuleFederationPlugin({ config: serverMfConfig, isServer: true }, { dts: false }),
|
|
65
|
+
new NxModuleFederationSSRDevServerPlugin({ config: serverMfConfig }),
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
module.exports = [browserRspackConfig, serverRspackConfig];
|
|
@@ -7,8 +7,8 @@ import { handleRequest } from './src/main.server';
|
|
|
7
7
|
const port = process.env['PORT'] || <%= port %>;
|
|
8
8
|
const app = express();
|
|
9
9
|
|
|
10
|
-
const browserDist = path.join(process.cwd(), '<%=
|
|
11
|
-
const serverDist = path.join(process.cwd(), '<%=
|
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'browser');
|
|
11
|
+
const serverDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'server');
|
|
12
12
|
const indexPath = path.join(browserDist, 'index.html');
|
|
13
13
|
|
|
14
14
|
app.use(cors());
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
4
|
+
import isbot from 'isbot';
|
|
5
|
+
|
|
6
|
+
import App from './app/app';
|
|
7
|
+
|
|
8
|
+
let indexHtml: null | string = null;
|
|
9
|
+
|
|
10
|
+
export function handleRequest(indexPath: string) {
|
|
11
|
+
return function render(req: Request, res: Response) {
|
|
12
|
+
let didError = false;
|
|
13
|
+
|
|
14
|
+
if (!indexHtml) {
|
|
15
|
+
indexHtml = fs.readFileSync(indexPath).toString();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
|
|
19
|
+
|
|
20
|
+
// For bots (e.g. search engines), the content will not be streamed but render all at once.
|
|
21
|
+
// For users, content should be streamed to the user as they are ready.
|
|
22
|
+
const callbackName = isbot(req.headers['user-agent'])
|
|
23
|
+
? 'onAllReady'
|
|
24
|
+
: 'onShellReady';
|
|
25
|
+
|
|
26
|
+
const stream = ReactDOMServer.renderToPipeableStream(<App />, {
|
|
27
|
+
[callbackName]() {
|
|
28
|
+
res.statusCode = didError ? 500 : 200;
|
|
29
|
+
res.setHeader('Content-type', 'text/html; charset=utf-8');
|
|
30
|
+
res.write(`${htmlStart}<div id="root">`);
|
|
31
|
+
stream.pipe(res);
|
|
32
|
+
res.write(`</div>${htmlEnd}`);
|
|
33
|
+
},
|
|
34
|
+
onShellError(error) {
|
|
35
|
+
console.error(error);
|
|
36
|
+
res.statusCode = 500;
|
|
37
|
+
res.send('<!doctype html><h1>Server Error</h1>');
|
|
38
|
+
},
|
|
39
|
+
onError(error) {
|
|
40
|
+
didError = true;
|
|
41
|
+
console.error(error);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import {ModuleFederationConfig} from '@nx/
|
|
1
|
+
import {ModuleFederationConfig} from '@nx/module-federation';
|
|
2
2
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
name: '<%= projectName %>',
|
|
5
|
+
exposes: {
|
|
6
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
7
|
+
},
|
|
8
|
+
shared: (libraryName, libraryConfig) => {
|
|
9
|
+
return {
|
|
10
|
+
...libraryConfig,
|
|
11
|
+
eager: true
|
|
12
|
+
}
|
|
7
13
|
},
|
|
8
14
|
};
|
|
9
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Nx requires a default export of the config to allow correct resolution of the module federation graph.
|
|
18
|
+
**/
|
|
10
19
|
export default config;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { NxAppRspackPlugin } from '@nx/rspack/app-plugin';
|
|
2
|
+
import { NxReactRspackPlugin } from '@nx/rspack/react-plugin';
|
|
3
|
+
import { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } from '@nx/module-federation/rspack';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
|
|
6
|
+
import browserMfConfig from './module-federation.config';
|
|
7
|
+
import serverMfConfig from './module-federation.server.config';
|
|
8
|
+
|
|
9
|
+
const browserRspackConfig = {
|
|
10
|
+
name: 'browser',
|
|
11
|
+
output: {
|
|
12
|
+
path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'browser'),
|
|
13
|
+
publicPath: 'auto'
|
|
14
|
+
},
|
|
15
|
+
devServer: {
|
|
16
|
+
port: <%= devServerPort %>,
|
|
17
|
+
headers: {
|
|
18
|
+
"Access-Control-Allow-Origin": "*"
|
|
19
|
+
},
|
|
20
|
+
historyApiFallback: {
|
|
21
|
+
index: '/index.html',
|
|
22
|
+
disableDotRule: true,
|
|
23
|
+
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml'],
|
|
24
|
+
},
|
|
25
|
+
devMiddleware: {
|
|
26
|
+
writeToDisk: (file: string) => !file.includes('.hot-update.'),
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
plugins: [
|
|
30
|
+
new NxAppRspackPlugin({
|
|
31
|
+
tsConfig: '<%= rspackPluginOptions.tsConfig %>',
|
|
32
|
+
main: '<%= rspackPluginOptions.main %>',
|
|
33
|
+
index: '<%= rspackPluginOptions.index %>',
|
|
34
|
+
baseHref: '<%= rspackPluginOptions.baseHref %>',
|
|
35
|
+
assets: <%- JSON.stringify(rspackPluginOptions.assets) %>,
|
|
36
|
+
styles: <%- JSON.stringify(rspackPluginOptions.styles) %>,
|
|
37
|
+
outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
|
|
38
|
+
optimization: process.env['NODE_ENV'] === 'production',
|
|
39
|
+
}),
|
|
40
|
+
new NxReactRspackPlugin({
|
|
41
|
+
// Uncomment this line if you don't want to use SVGR
|
|
42
|
+
// See: https://react-svgr.com/
|
|
43
|
+
// svgr: false
|
|
44
|
+
}),
|
|
45
|
+
new NxModuleFederationPlugin({ config: browserMfConfig }, { dts: false }),
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const serverRspackConfig = {
|
|
50
|
+
name: 'server',
|
|
51
|
+
target: 'async-node',
|
|
52
|
+
output: {
|
|
53
|
+
path: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
|
|
54
|
+
filename: 'server.js'
|
|
55
|
+
},
|
|
56
|
+
plugins: [
|
|
57
|
+
new NxAppRspackPlugin({
|
|
58
|
+
outputPath: join(__dirname, '<%= rspackPluginOptions.outputPath %>', 'server'),
|
|
59
|
+
outputFileName: 'server.js',
|
|
60
|
+
tsConfig: '<%= rspackPluginOptions.tsConfig %>',
|
|
61
|
+
main: '<%= rspackPluginOptions.mainServer %>',
|
|
62
|
+
baseHref: '<%= rspackPluginOptions.baseHref %>',
|
|
63
|
+
}),
|
|
64
|
+
new NxModuleFederationPlugin({ config: serverMfConfig, isServer: true }, { dts: false }),
|
|
65
|
+
new NxModuleFederationSSRDevServerPlugin({ config: serverMfConfig }),
|
|
66
|
+
],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default [browserRspackConfig, serverRspackConfig];
|
|
@@ -7,8 +7,8 @@ import { handleRequest } from './src/main.server';
|
|
|
7
7
|
const port = process.env['PORT'] || <%= port %>;
|
|
8
8
|
const app = express();
|
|
9
9
|
|
|
10
|
-
const browserDist = path.join(process.cwd(), '<%=
|
|
11
|
-
const serverDist = path.join(process.cwd(), '<%=
|
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'browser');
|
|
11
|
+
const serverDist = path.join(process.cwd(), '<%= rspackPluginOptions.outputPath %>', 'server');
|
|
12
12
|
const indexPath = path.join(browserDist, 'index.html');
|
|
13
13
|
|
|
14
14
|
app.use(cors());
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/src/main.server.tsx__tmpl__
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Request, Response } from 'express';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import * as ReactDOMServer from 'react-dom/server';
|
|
4
|
+
import isbot from 'isbot';
|
|
5
|
+
|
|
6
|
+
import App from './app/app';
|
|
7
|
+
|
|
8
|
+
let indexHtml: null | string = null;
|
|
9
|
+
|
|
10
|
+
export function handleRequest(indexPath: string) {
|
|
11
|
+
return function render(req: Request, res: Response) {
|
|
12
|
+
let didError = false;
|
|
13
|
+
|
|
14
|
+
if (!indexHtml) {
|
|
15
|
+
indexHtml = fs.readFileSync(indexPath).toString();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
|
|
19
|
+
|
|
20
|
+
// For bots (e.g. search engines), the content will not be streamed but render all at once.
|
|
21
|
+
// For users, content should be streamed to the user as they are ready.
|
|
22
|
+
const callbackName = isbot(req.headers['user-agent'])
|
|
23
|
+
? 'onAllReady'
|
|
24
|
+
: 'onShellReady';
|
|
25
|
+
|
|
26
|
+
const stream = ReactDOMServer.renderToPipeableStream(<App />, {
|
|
27
|
+
[callbackName]() {
|
|
28
|
+
res.statusCode = didError ? 500 : 200;
|
|
29
|
+
res.setHeader('Content-type', 'text/html; charset=utf-8');
|
|
30
|
+
res.write(`${htmlStart}<div id="root">`);
|
|
31
|
+
stream.pipe(res);
|
|
32
|
+
res.write(`</div>${htmlEnd}`);
|
|
33
|
+
},
|
|
34
|
+
onShellError(error) {
|
|
35
|
+
console.error(error);
|
|
36
|
+
res.statusCode = 500;
|
|
37
|
+
res.send('<!doctype html><h1>Server Error</h1>');
|
|
38
|
+
},
|
|
39
|
+
onError(error) {
|
|
40
|
+
didError = true;
|
|
41
|
+
console.error(error);
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {ModuleFederationConfig} from '@nx/
|
|
1
|
+
import {ModuleFederationConfig} from '@nx/module-federation';
|
|
2
2
|
|
|
3
3
|
const config: ModuleFederationConfig = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
name: '<%= projectName %>',
|
|
5
|
+
<%_ if (dynamic) { _%>
|
|
6
|
+
library: { type: 'var', name: '<%= projectName %>'},
|
|
7
|
+
<%_ } _%>
|
|
8
|
+
exposes: {
|
|
9
|
+
'./Module': './src/remote-entry.<%= js ? 'js' : 'ts' %>',
|
|
10
|
+
},
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Nx requires a default export of the config to allow correct resolution of the module federation graph.
|
|
15
|
+
**/
|
|
13
16
|
export default config;
|