@nrwl/react 14.8.8 → 14.9.0-beta.1
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/CHANGELOG.md +1 -1
- package/LICENSE +22 -22
- package/README.md +5 -26
- package/babel.d.ts +16 -1
- package/babel.js +4 -3
- package/babel.js.map +1 -1
- package/executors.json +10 -0
- package/generators.json +14 -0
- package/index.d.ts +4 -1
- package/index.js +8 -1
- package/index.js.map +1 -1
- package/migrations.json +160 -0
- package/module-federation.d.ts +2 -2
- package/module-federation.js +4 -4
- package/module-federation.js.map +1 -1
- package/package.json +9 -26
- package/plugins/bundle-rollup.js +20 -0
- package/plugins/bundle-rollup.js.map +1 -1
- package/plugins/component-testing/index.d.ts +13 -5
- package/plugins/component-testing/index.js +31 -44
- package/plugins/component-testing/index.js.map +1 -1
- package/plugins/component-testing/webpack-fallback.js +2 -2
- package/plugins/component-testing/webpack-fallback.js.map +1 -1
- package/plugins/jest.js +10 -6
- package/plugins/jest.js.map +1 -1
- package/plugins/storybook/index.d.ts +0 -4
- package/plugins/storybook/index.js +24 -74
- package/plugins/storybook/index.js.map +1 -1
- package/plugins/storybook/merge-plugins.d.ts +2 -2
- package/plugins/storybook/merge-plugins.js.map +1 -1
- package/plugins/webpack.d.ts +3 -2
- package/plugins/webpack.js +10 -72
- package/plugins/webpack.js.map +1 -1
- package/plugins/with-react.d.ts +12 -0
- package/plugins/with-react.js +82 -0
- package/plugins/with-react.js.map +1 -0
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts +6 -2
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +11 -7
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js.map +1 -1
- package/src/executors/module-federation-dev-server/schema.json +18 -4
- package/src/executors/module-federation-ssr-dev-server/compat.d.ts +2 -0
- package/src/executors/module-federation-ssr-dev-server/compat.js +6 -0
- package/src/executors/module-federation-ssr-dev-server/compat.js.map +1 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts +9 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +71 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js.map +1 -0
- package/src/executors/module-federation-ssr-dev-server/schema.json +48 -0
- package/src/generators/application/application.js +85 -25
- package/src/generators/application/application.js.map +1 -1
- package/src/generators/application/files/base-vite/index.html__tmpl__ +16 -0
- package/src/generators/application/files/base-vite/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/{common → base-vite}/tsconfig.app.json__tmpl__ +2 -2
- package/src/generators/application/files/base-webpack/src/app/__fileName__.spec.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-webpack/src/environments/environment.prod.ts__tmpl__ +3 -0
- package/src/generators/application/files/base-webpack/src/environments/environment.ts__tmpl__ +6 -0
- package/src/generators/application/files/base-webpack/src/favicon.ico +0 -0
- package/src/generators/application/files/base-webpack/src/main.tsx__tmpl__ +10 -0
- package/src/generators/application/files/base-webpack/tsconfig.app.json__tmpl__ +14 -0
- package/src/generators/application/files/base-webpack/webpack.config.js__tmpl__ +9 -0
- package/src/generators/application/files/{common → nx-welcome}/src/app/nx-welcome.tsx +30 -8
- package/src/generators/application/files/{css-module → style-css-module}/src/app/__fileName__.tsx__tmpl__ +11 -0
- package/src/generators/application/files/{global-css → style-global-css}/src/app/__fileName__.tsx__tmpl__ +11 -0
- package/src/generators/application/files/{none → style-none}/src/app/__fileName__.tsx__tmpl__ +11 -0
- package/src/generators/application/files/{styled-jsx → style-styled-jsx}/src/app/__fileName__.tsx__tmpl__ +4 -1
- package/src/generators/application/files/{styled-module → style-styled-module}/src/app/__fileName__.tsx__tmpl__ +11 -0
- package/src/generators/application/lib/add-cypress.d.ts +1 -1
- package/src/generators/application/lib/add-cypress.js +4 -2
- package/src/generators/application/lib/add-cypress.js.map +1 -1
- package/src/generators/application/lib/add-jest.d.ts +2 -2
- package/src/generators/application/lib/add-jest.js +4 -2
- package/src/generators/application/lib/add-jest.js.map +1 -1
- package/src/generators/application/lib/add-project.js +13 -8
- package/src/generators/application/lib/add-project.js.map +1 -1
- package/src/generators/application/lib/add-routing.js +10 -3
- package/src/generators/application/lib/add-routing.js.map +1 -1
- package/src/generators/application/lib/create-application-files.d.ts +1 -1
- package/src/generators/application/lib/create-application-files.js +21 -18
- package/src/generators/application/lib/create-application-files.js.map +1 -1
- package/src/generators/application/lib/get-app-tests.d.ts +2 -0
- package/src/generators/application/lib/get-app-tests.js +22 -0
- package/src/generators/application/lib/get-app-tests.js.map +1 -0
- package/src/generators/application/lib/install-common-dependencies.d.ts +3 -0
- package/src/generators/application/lib/install-common-dependencies.js +29 -0
- package/src/generators/application/lib/install-common-dependencies.js.map +1 -0
- package/src/generators/application/lib/normalize-options.d.ts +1 -1
- package/src/generators/application/lib/normalize-options.js +28 -14
- package/src/generators/application/lib/normalize-options.js.map +1 -1
- package/src/generators/application/lib/set-defaults.js +11 -9
- package/src/generators/application/lib/set-defaults.js.map +1 -1
- package/src/generators/application/lib/update-jest-config.d.ts +1 -1
- package/src/generators/application/lib/update-jest-config.js +7 -4
- package/src/generators/application/lib/update-jest-config.js.map +1 -1
- package/src/generators/application/schema.d.ts +9 -4
- package/src/generators/application/schema.json +42 -10
- package/src/generators/component/component.js +15 -7
- package/src/generators/component/component.js.map +1 -1
- package/src/generators/component/files/__fileName__.spec.tsx__tmpl__ +1 -4
- package/src/generators/component/files/__fileName__.tsx__tmpl__ +4 -2
- package/src/generators/component/get-component-tests.d.ts +2 -0
- package/src/generators/component/get-component-tests.js +13 -0
- package/src/generators/component/get-component-tests.js.map +1 -0
- package/src/generators/component/noramlized-schema.d.ts +8 -0
- package/src/generators/component/noramlized-schema.js +3 -0
- package/src/generators/component/noramlized-schema.js.map +1 -0
- package/src/generators/component/schema.d.ts +1 -0
- package/src/generators/component/schema.json +13 -4
- package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +1 -1
- package/src/generators/component-cypress-spec/component-cypress-spec.js +12 -5
- package/src/generators/component-cypress-spec/component-cypress-spec.js.map +1 -1
- package/src/generators/component-cypress-spec/schema.json +4 -2
- package/src/generators/component-story/component-story.d.ts +1 -1
- package/src/generators/component-story/component-story.js +6 -2
- package/src/generators/component-story/component-story.js.map +1 -1
- package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +6 -7
- package/src/generators/component-story/schema.json +4 -2
- package/src/generators/component-test/component-test.d.ts +1 -1
- package/src/generators/component-test/component-test.js +21 -12
- package/src/generators/component-test/component-test.js.map +1 -1
- package/src/generators/component-test/files/__fileName__.cy__ext__ +2 -3
- package/src/generators/component-test/schema.json +6 -3
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js +5 -4
- package/src/generators/cypress-component-configuration/cypress-component-configuration.js.map +1 -1
- package/src/generators/cypress-component-configuration/files/cypress/support/commands.ts__tpl__ +42 -0
- package/src/generators/cypress-component-configuration/files/cypress.config.ts__tpl__ +3 -1
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +2 -1
- package/src/generators/cypress-component-configuration/lib/add-files.js +52 -16
- package/src/generators/cypress-component-configuration/lib/add-files.js.map +1 -1
- package/src/generators/cypress-component-configuration/lib/update-configs.d.ts +6 -2
- package/src/generators/cypress-component-configuration/lib/update-configs.js +8 -4
- package/src/generators/cypress-component-configuration/lib/update-configs.js.map +1 -1
- package/src/generators/cypress-component-configuration/schema.d.ts +1 -0
- package/src/generators/cypress-component-configuration/schema.json +15 -4
- package/src/generators/hook/hook.js +6 -2
- package/src/generators/hook/hook.js.map +1 -1
- package/src/generators/hook/schema.json +7 -4
- package/src/generators/host/files/common/src/app/__fileName__.tsx__tmpl__ +4 -0
- package/src/generators/host/files/module-federation/module-federation.config.js__tmpl__ +5 -12
- package/src/generators/host/files/module-federation/webpack.config.js__tmpl__ +7 -8
- package/src/generators/host/files/module-federation/webpack.config.prod.js__tmpl__ +11 -12
- package/src/generators/host/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +13 -0
- package/src/generators/host/files/module-federation-ssr/server.ts__tmpl__ +28 -0
- package/src/generators/host/files/module-federation-ssr/tsconfig.server.json__tmpl__ +15 -0
- package/src/generators/host/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
- package/src/generators/host/host.d.ts +2 -2
- package/src/generators/host/host.js +21 -2
- package/src/generators/host/host.js.map +1 -1
- package/src/generators/host/lib/add-module-federation-files.js +1 -1
- package/src/generators/host/lib/add-module-federation-files.js.map +1 -1
- package/src/generators/host/lib/setup-ssr-for-host.d.ts +6 -0
- package/src/generators/host/lib/setup-ssr-for-host.js +27 -0
- package/src/generators/host/lib/setup-ssr-for-host.js.map +1 -0
- package/src/generators/host/schema.d.ts +16 -14
- package/src/generators/host/schema.json +27 -8
- package/src/generators/init/init.js +45 -22
- package/src/generators/init/init.js.map +1 -1
- package/src/generators/init/schema.d.ts +6 -1
- package/src/generators/init/schema.json +16 -0
- package/src/generators/library/files/common/src/index.ts__tmpl__ +0 -0
- package/src/generators/library/files/common/tsconfig.lib.json__tmpl__ +14 -0
- package/src/generators/library/files/vite/README.md +7 -0
- package/src/generators/library/files/vite/package.json__tmpl__ +12 -0
- package/src/generators/library/files/{lib → vite}/tsconfig.lib.json__tmpl__ +1 -1
- package/src/generators/library/lib/add-linting.d.ts +3 -0
- package/src/generators/library/lib/add-linting.js +37 -0
- package/src/generators/library/lib/add-linting.js.map +1 -0
- package/src/generators/library/lib/add-rollup-build-target.d.ts +3 -0
- package/src/generators/library/lib/add-rollup-build-target.js +59 -0
- package/src/generators/library/lib/add-rollup-build-target.js.map +1 -0
- package/src/generators/library/lib/create-files.d.ts +3 -0
- package/src/generators/library/lib/create-files.js +26 -0
- package/src/generators/library/lib/create-files.js.map +1 -0
- package/src/generators/library/lib/install-common-dependencies.d.ts +3 -0
- package/src/generators/library/lib/install-common-dependencies.js +30 -0
- package/src/generators/library/lib/install-common-dependencies.js.map +1 -0
- package/src/generators/library/lib/maybe-js.d.ts +2 -0
- package/src/generators/library/lib/maybe-js.js +10 -0
- package/src/generators/library/lib/maybe-js.js.map +1 -0
- package/src/generators/library/lib/normalize-options.d.ts +3 -0
- package/src/generators/library/lib/normalize-options.js +57 -0
- package/src/generators/library/lib/normalize-options.js.map +1 -0
- package/src/generators/library/lib/set-defaults.d.ts +3 -0
- package/src/generators/library/lib/set-defaults.js +16 -0
- package/src/generators/library/lib/set-defaults.js.map +1 -0
- package/src/generators/library/lib/update-app-routes.d.ts +3 -0
- package/src/generators/library/lib/update-app-routes.js +63 -0
- package/src/generators/library/lib/update-app-routes.js.map +1 -0
- package/src/generators/library/library.d.ts +0 -10
- package/src/generators/library/library.js +76 -214
- package/src/generators/library/library.js.map +1 -1
- package/src/generators/library/schema.d.ts +34 -16
- package/src/generators/library/schema.json +41 -10
- package/src/generators/redux/redux.js +13 -6
- package/src/generators/redux/redux.js.map +1 -1
- package/src/generators/redux/schema.json +6 -3
- package/src/generators/remote/files/module-federation/module-federation.config.js__tmpl__ +1 -8
- package/src/generators/remote/files/module-federation/webpack.config.js__tmpl__ +7 -8
- package/src/generators/remote/files/module-federation-ssr/module-federation.server.config.js__tmpl__ +6 -0
- package/src/generators/remote/files/module-federation-ssr/server.ts__tmpl__ +45 -0
- package/src/generators/remote/files/module-federation-ssr/webpack.server.config.js__tmpl__ +12 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.d.ts +4 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js +32 -0
- package/src/generators/remote/lib/setup-ssr-for-remote.js.map +1 -0
- package/src/generators/remote/lib/update-host-with-remote.js +8 -4
- package/src/generators/remote/lib/update-host-with-remote.js.map +1 -1
- package/src/generators/remote/remote.d.ts +2 -2
- package/src/generators/remote/remote.js +20 -3
- package/src/generators/remote/remote.js.map +1 -1
- package/src/generators/remote/schema.d.ts +14 -13
- package/src/generators/remote/schema.json +22 -8
- package/src/generators/setup-ssr/files/server.ts__tmpl__ +28 -0
- package/src/generators/setup-ssr/files/src/main.server.tsx__tmpl__ +47 -0
- package/src/generators/setup-ssr/files/tsconfig.server.json__tmpl__ +15 -0
- package/src/generators/setup-ssr/schema.d.ts +7 -0
- package/src/generators/setup-ssr/schema.json +48 -0
- package/src/generators/setup-ssr/setup-ssr.d.ts +5 -0
- package/src/generators/setup-ssr/setup-ssr.js +162 -0
- package/src/generators/setup-ssr/setup-ssr.js.map +1 -0
- package/src/generators/setup-tailwind/lib/add-tailwind-style-imports.js +2 -2
- package/src/generators/setup-tailwind/schema.json +8 -4
- package/src/generators/setup-tailwind/setup-tailwind.js +1 -2
- package/src/generators/setup-tailwind/setup-tailwind.js.map +1 -1
- package/src/generators/stories/schema.json +4 -2
- package/src/generators/stories/stories.d.ts +1 -1
- package/src/generators/stories/stories.js +29 -21
- package/src/generators/stories/stories.js.map +1 -1
- package/src/generators/storybook-configuration/configuration.d.ts +1 -1
- package/src/generators/storybook-configuration/configuration.js +24 -6
- package/src/generators/storybook-configuration/configuration.js.map +1 -1
- package/src/generators/storybook-configuration/schema.d.ts +2 -0
- package/src/generators/storybook-configuration/schema.json +25 -8
- package/src/migrations/update-13-0-0/webpack5-changes-utils.js +3 -3
- package/src/migrations/update-13-0-0/webpack5-changes-utils.js.map +1 -1
- package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js +3 -3
- package/src/migrations/update-14-0-0/update-react-dom-render-for-v18.js.map +1 -1
- package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js +1 -1
- package/src/migrations/update-14-1-0/update-external-emotion-jsx-runtime.js.map +1 -1
- package/src/migrations/update-14-6-0/add-preset-jest-config.js +1 -1
- package/src/migrations/update-14-6-0/add-preset-jest-config.js.map +1 -1
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.d.ts +3 -0
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js +39 -0
- package/src/migrations/update-15-3-0/install-webpack-rollup-dependencies.js.map +1 -0
- package/src/migrations/update-15-3-0/update-rollup-executor.d.ts +3 -0
- package/src/migrations/update-15-3-0/update-rollup-executor.js +17 -0
- package/src/migrations/update-15-3-0/update-rollup-executor.js.map +1 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.d.ts +2 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.js +108 -0
- package/src/migrations/update-15-6-3/webpack-config-setup.js.map +1 -0
- package/src/module-federation/ast-utils.d.ts +1 -1
- package/src/module-federation/ast-utils.js +10 -6
- package/src/module-federation/ast-utils.js.map +1 -1
- package/src/module-federation/load-config.js +1 -1
- package/src/module-federation/load-config.js.map +1 -1
- package/src/module-federation/models.d.ts +4 -4
- package/src/module-federation/utils.d.ts +10 -0
- package/src/module-federation/utils.js +38 -0
- package/src/module-federation/utils.js.map +1 -0
- package/src/module-federation/with-module-federation-ssr.d.ts +2 -0
- package/src/module-federation/with-module-federation-ssr.js +48 -0
- package/src/module-federation/with-module-federation-ssr.js.map +1 -0
- package/src/module-federation/with-module-federation.d.ts +7 -2
- package/src/module-federation/with-module-federation.js +15 -158
- package/src/module-federation/with-module-federation.js.map +1 -1
- package/src/rules/update-module-federation-project.d.ts +2 -2
- package/src/rules/update-module-federation-project.js +2 -0
- package/src/rules/update-module-federation-project.js.map +1 -1
- package/src/utils/ast-utils.d.ts +2 -1
- package/src/utils/ast-utils.js +132 -65
- package/src/utils/ast-utils.js.map +1 -1
- package/src/utils/component-props.d.ts +1 -1
- package/src/utils/component-props.js +13 -6
- package/src/utils/component-props.js.map +1 -1
- package/src/utils/create-ts-config.d.ts +9 -0
- package/src/utils/create-ts-config.js +64 -0
- package/src/utils/create-ts-config.js.map +1 -0
- package/src/utils/get-in-source-vitest-tests-template.d.ts +1 -0
- package/src/utils/get-in-source-vitest-tests-template.js +22 -0
- package/src/utils/get-in-source-vitest-tests-template.js.map +1 -0
- package/src/utils/lint.d.ts +26 -0
- package/src/utils/lint.js +10 -1
- package/src/utils/lint.js.map +1 -1
- package/src/utils/versions.d.ts +32 -18
- package/src/utils/versions.js +36 -19
- package/src/utils/versions.js.map +1 -1
- package/tailwind.js +1 -1
- package/tailwind.js.map +1 -1
- package/src/generators/application/files/common/.browserslistrc__tmpl__ +0 -16
- package/src/generators/application/files/common/src/app/__fileName__.spec.tsx__tmpl__ +0 -26
- package/src/generators/application/files/common/src/polyfills.ts__tmpl__ +0 -7
- package/src/generators/application/files/common/tsconfig.json__tmpl__ +0 -17
- package/src/generators/library/files/lib/tsconfig.json__tmpl__ +0 -17
- package/src/migrations/utils/rules.d.ts +0 -2
- package/src/migrations/utils/rules.js +0 -15
- package/src/migrations/utils/rules.js.map +0 -1
- package/src/migrations/utils/testing.d.ts +0 -6
- package/src/migrations/utils/testing.js +0 -76
- package/src/migrations/utils/testing.js.map +0 -1
- package/src/module-federation/webpack-utils.d.ts +0 -9
- package/src/module-federation/webpack-utils.js +0 -76
- package/src/module-federation/webpack-utils.js.map +0 -1
- package/src/utils/async-iterator.d.ts +0 -5
- package/src/utils/async-iterator.js +0 -76
- package/src/utils/async-iterator.js.map +0 -1
- /package/src/generators/application/files/{common/src → base-vite/public}/favicon.ico +0 -0
- /package/src/generators/application/files/{common → base-vite}/src/assets/.gitkeep +0 -0
- /package/src/generators/application/files/{common → base-vite}/src/environments/environment.prod.ts__tmpl__ +0 -0
- /package/src/generators/application/files/{common → base-vite}/src/environments/environment.ts__tmpl__ +0 -0
- /package/src/generators/application/files/{common → base-vite}/src/main.tsx__tmpl__ +0 -0
- /package/src/generators/application/files/{common → base-webpack}/.babelrc__tmpl__ +0 -0
- /package/src/generators/{library/files/lib/src/index.ts__tmpl__ → application/files/base-webpack/src/assets/.gitkeep} +0 -0
- /package/src/generators/application/files/{common → base-webpack}/src/index.html +0 -0
- /package/src/generators/application/files/{css-module → style-css-module}/src/app/__fileName__.module.__style__ +0 -0
- /package/src/generators/application/files/{css-module → style-css-module}/src/styles.__style__ +0 -0
- /package/src/generators/application/files/{global-css → style-global-css}/src/app/__fileName__.__style__ +0 -0
- /package/src/generators/application/files/{global-css → style-global-css}/src/styles.__style__ +0 -0
- /package/src/generators/library/files/{lib → common}/.babelrc__tmpl__ +0 -0
- /package/src/generators/library/files/{lib → common}/README.md +0 -0
- /package/src/generators/library/files/{lib → common}/package.json__tmpl__ +0 -0
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @type {import('@nrwl/react/module-federation').ModuleFederationConfig}
|
|
5
|
-
**/
|
|
6
|
-
const moduleFederationConfig = {
|
|
1
|
+
module.exports = {
|
|
7
2
|
name: '<%= projectName %>',
|
|
8
3
|
exposes: {
|
|
9
4
|
'./Module': './src/remote-entry.ts',
|
|
10
5
|
},
|
|
11
6
|
};
|
|
12
|
-
|
|
13
|
-
module.exports = moduleFederationConfig;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
const { composePlugins, withNx } = require('@nrwl/webpack');
|
|
2
|
+
const { withReact } = require('@nrwl/react');
|
|
3
3
|
const { withModuleFederation } = require('@nrwl/react/module-federation');
|
|
4
|
+
|
|
4
5
|
const baseConfig = require('./module-federation.config');
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
**/
|
|
9
|
-
const defaultConfig = {
|
|
10
|
-
...baseConfig,
|
|
7
|
+
const config = {
|
|
8
|
+
...baseConfig,
|
|
11
9
|
};
|
|
12
10
|
|
|
13
|
-
|
|
11
|
+
// Nx plugins for webpack to build config object from Nx options and context.
|
|
12
|
+
module.exports = composePlugins(withNx(), withReact(), withModuleFederation(config));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
|
|
5
|
+
import { handleRequest } from './src/main.server';
|
|
6
|
+
|
|
7
|
+
const port = process.env['PORT'] || 4200;
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
|
|
11
|
+
const serverDist = path.join(process.cwd(), '<%= serverBuildOutputPath %>');
|
|
12
|
+
const indexPath = path.join(browserDist, 'index.html');
|
|
13
|
+
|
|
14
|
+
app.use(cors());
|
|
15
|
+
|
|
16
|
+
// Client-side static bundles
|
|
17
|
+
app.get(
|
|
18
|
+
'*.*',
|
|
19
|
+
express.static(browserDist, {
|
|
20
|
+
maxAge: '1y',
|
|
21
|
+
})
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
// Static bundles for server-side module federation
|
|
25
|
+
app.use('/server',
|
|
26
|
+
express.static(serverDist, {
|
|
27
|
+
maxAge: '1y'
|
|
28
|
+
})
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
app.use('*', handleRequest(indexPath));
|
|
32
|
+
|
|
33
|
+
const server = app.listen(port, () => {
|
|
34
|
+
console.log(`Express server listening on http://localhost:${port}`);
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* DO NOT REMOVE IF USING @nrwl/react:module-federation-dev-ssr executor
|
|
38
|
+
* to serve your Host application with this Remote application.
|
|
39
|
+
* This message allows Nx to determine when the Remote is ready to be
|
|
40
|
+
* consumed by the Host.
|
|
41
|
+
*/
|
|
42
|
+
process.send?.('nx.server.ready');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
server.on('error', console.error);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const { composePlugins, withNx } = require('@nrwl/webpack');
|
|
2
|
+
const { withReact } = require('@nrwl/react');
|
|
3
|
+
const { withModuleFederationForSSR } = require('@nrwl/react/module-federation');
|
|
4
|
+
|
|
5
|
+
const baseConfig = require("./module-federation.server.config");
|
|
6
|
+
|
|
7
|
+
const defaultConfig = {
|
|
8
|
+
...baseConfig,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Nx plugins for webpack to build config object from Nx options and context.
|
|
12
|
+
module.exports = composePlugins(withNx(), withReact(), withModuleFederationForSSR(defaultConfig));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GeneratorCallback, Tree } from '@nrwl/devkit';
|
|
2
|
+
import { NormalizedSchema } from '../../application/schema';
|
|
3
|
+
import type { Schema } from '../schema';
|
|
4
|
+
export declare function setupSsrForRemote(tree: Tree, options: NormalizedSchema<Schema>, appName: string): Promise<GeneratorCallback>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupSsrForRemote = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nrwl/devkit");
|
|
6
|
+
const versions_1 = require("../../../utils/versions");
|
|
7
|
+
function setupSsrForRemote(tree, options, appName) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
10
|
+
const tasks = [];
|
|
11
|
+
const project = (0, devkit_1.readProjectConfiguration)(tree, appName);
|
|
12
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, '../files/module-federation-ssr'), project.root, Object.assign(Object.assign({}, options), { appName, tmpl: '', browserBuildOutputPath: project.targets.build.options.outputPath, serverBuildOutputPath: project.targets.server.options.outputPath }));
|
|
13
|
+
// For hosts to use when running remotes in static mode.
|
|
14
|
+
const originalOutputPath = (_b = (_a = project.targets.build) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.outputPath;
|
|
15
|
+
project.targets['serve-static'] = {
|
|
16
|
+
dependsOn: ['build', 'server'],
|
|
17
|
+
executor: 'nx:run-commands',
|
|
18
|
+
defaultConfiguration: 'development',
|
|
19
|
+
options: {
|
|
20
|
+
command: `PORT=${(_c = options.devServerPort) !== null && _c !== void 0 ? _c : 4200} node ${(0, devkit_1.joinPathFragments)(originalOutputPath, 'server', 'main.js')}`,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
(0, devkit_1.updateProjectConfiguration)(tree, appName, project);
|
|
24
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {
|
|
25
|
+
'@module-federation/node': versions_1.moduleFederationNodeVersion,
|
|
26
|
+
}, {});
|
|
27
|
+
tasks.push(installTask);
|
|
28
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
exports.setupSsrForRemote = setupSsrForRemote;
|
|
32
|
+
//# sourceMappingURL=setup-ssr-for-remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-ssr-for-remote.js","sourceRoot":"","sources":["../../../../../../../packages/react/src/generators/remote/lib/setup-ssr-for-remote.ts"],"names":[],"mappings":";;;;AACA,yCAOsB;AAItB,sDAAsE;AAEtE,SAAsB,iBAAiB,CACrC,IAAU,EACV,OAAiC,EACjC,OAAe;;;QAEf,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAExD,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,0BAAiB,EAAC,SAAS,EAAE,gCAAgC,CAAC,EAC9D,OAAO,CAAC,IAAI,kCAEP,OAAO,KACV,OAAO,EACP,IAAI,EAAE,EAAE,EACR,sBAAsB,EAAE,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAChE,qBAAqB,EAAE,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,UAAU,IAEnE,CAAC;QAEF,wDAAwD;QACxD,MAAM,kBAAkB,GAAG,MAAA,MAAA,OAAO,CAAC,OAAO,CAAC,KAAK,0CAAE,OAAO,0CAAE,UAAU,CAAC;QACtE,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG;YAChC,SAAS,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;YAC9B,QAAQ,EAAE,iBAAiB;YAC3B,oBAAoB,EAAE,aAAa;YACnC,OAAO,EAAE;gBACP,OAAO,EAAE,QAAQ,MAAA,OAAO,CAAC,aAAa,mCAAI,IAAI,SAAS,IAAA,0BAAiB,EACtE,kBAAkB,EAClB,QAAQ,EACR,SAAS,CACV,EAAE;aACJ;SACF,CAAC;QACF,IAAA,mCAA0B,EAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,WAAW,GAAG,IAAA,qCAA4B,EAC9C,IAAI,EACJ;YACE,yBAAyB,EAAE,sCAA2B;SACvD,EACD,EAAE,CACH,CAAC;QACF,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAExB,OAAO,IAAA,yBAAgB,EAAC,GAAG,KAAK,CAAC,CAAC;;CACnC;AA/CD,8CA+CC"}
|
|
@@ -3,8 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateHostWithRemote = void 0;
|
|
4
4
|
const devkit_1 = require("@nrwl/devkit");
|
|
5
5
|
const ast_utils_1 = require("../../../module-federation/ast-utils");
|
|
6
|
-
const
|
|
6
|
+
const ensure_typescript_1 = require("@nrwl/js/src/utils/typescript/ensure-typescript");
|
|
7
|
+
let tsModule;
|
|
7
8
|
function updateHostWithRemote(host, hostName, remoteName) {
|
|
9
|
+
if (!tsModule) {
|
|
10
|
+
tsModule = (0, ensure_typescript_1.ensureTypescript)();
|
|
11
|
+
}
|
|
8
12
|
const hostConfig = (0, devkit_1.readProjectConfiguration)(host, hostName);
|
|
9
13
|
const moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(hostConfig.root, 'module-federation.config.js');
|
|
10
14
|
const remoteDefsPath = (0, devkit_1.joinPathFragments)(hostConfig.sourceRoot, 'remotes.d.ts');
|
|
@@ -13,7 +17,7 @@ function updateHostWithRemote(host, hostName, remoteName) {
|
|
|
13
17
|
// find the host project path
|
|
14
18
|
// Update remotes inside ${host_path}/src/remotes.d.ts
|
|
15
19
|
let sourceCode = host.read(moduleFederationConfigPath).toString();
|
|
16
|
-
const source =
|
|
20
|
+
const source = tsModule.createSourceFile(moduleFederationConfigPath, sourceCode, tsModule.ScriptTarget.Latest, true);
|
|
17
21
|
host.write(moduleFederationConfigPath, (0, devkit_1.applyChangesToString)(sourceCode, (0, ast_utils_1.addRemoteToConfig)(source, remoteName)));
|
|
18
22
|
}
|
|
19
23
|
else {
|
|
@@ -22,7 +26,7 @@ function updateHostWithRemote(host, hostName, remoteName) {
|
|
|
22
26
|
}
|
|
23
27
|
if (host.exists(remoteDefsPath)) {
|
|
24
28
|
let sourceCode = host.read(remoteDefsPath).toString();
|
|
25
|
-
const source =
|
|
29
|
+
const source = tsModule.createSourceFile(moduleFederationConfigPath, sourceCode, tsModule.ScriptTarget.Latest, true);
|
|
26
30
|
host.write(remoteDefsPath, (0, devkit_1.applyChangesToString)(sourceCode, (0, ast_utils_1.addRemoteDefinition)(source, remoteName)));
|
|
27
31
|
}
|
|
28
32
|
else {
|
|
@@ -30,7 +34,7 @@ function updateHostWithRemote(host, hostName, remoteName) {
|
|
|
30
34
|
}
|
|
31
35
|
if (host.exists(appComponentPath)) {
|
|
32
36
|
let sourceCode = host.read(appComponentPath).toString();
|
|
33
|
-
const source =
|
|
37
|
+
const source = tsModule.createSourceFile(moduleFederationConfigPath, sourceCode, tsModule.ScriptTarget.Latest, true);
|
|
34
38
|
host.write(appComponentPath, (0, devkit_1.applyChangesToString)(sourceCode, (0, ast_utils_1.addRemoteRoute)(source, (0, devkit_1.names)(remoteName))));
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"update-host-with-remote.js","sourceRoot":"","sources":["../../../../../../../packages/react/src/generators/remote/lib/update-host-with-remote.ts"],"names":[],"mappings":";;;AAAA,yCAOsB;AACtB,oEAI8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"update-host-with-remote.js","sourceRoot":"","sources":["../../../../../../../packages/react/src/generators/remote/lib/update-host-with-remote.ts"],"names":[],"mappings":";;;AAAA,yCAOsB;AACtB,oEA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 +1,6 @@
|
|
|
1
|
-
import { Tree } from '@nrwl/devkit';
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nrwl/devkit';
|
|
2
2
|
import { NormalizedSchema } from '../application/schema';
|
|
3
3
|
import { Schema } from './schema';
|
|
4
4
|
export declare function addModuleFederationFiles(host: Tree, options: NormalizedSchema): void;
|
|
5
|
-
export declare function remoteGenerator(host: Tree, schema: Schema): Promise<
|
|
5
|
+
export declare function remoteGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
|
|
6
6
|
export default remoteGenerator;
|
|
@@ -4,11 +4,12 @@ exports.remoteGenerator = exports.addModuleFederationFiles = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const devkit_1 = require("@nrwl/devkit");
|
|
7
|
-
const run_tasks_in_serial_1 = require("@nrwl/workspace/src/utilities/run-tasks-in-serial");
|
|
8
7
|
const normalize_options_1 = require("../application/lib/normalize-options");
|
|
9
8
|
const application_1 = require("../application/application");
|
|
10
9
|
const update_host_with_remote_1 = require("./lib/update-host-with-remote");
|
|
11
10
|
const update_module_federation_project_1 = require("../../rules/update-module-federation-project");
|
|
11
|
+
const setup_ssr_1 = require("../setup-ssr/setup-ssr");
|
|
12
|
+
const setup_ssr_for_remote_1 = require("./lib/setup-ssr-for-remote");
|
|
12
13
|
function addModuleFederationFiles(host, options) {
|
|
13
14
|
const templateVariables = Object.assign(Object.assign(Object.assign({}, (0, devkit_1.names)(options.name)), options), { tmpl: '' });
|
|
14
15
|
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, `./files/module-federation`), options.appProjectRoot, templateVariables);
|
|
@@ -16,8 +17,12 @@ function addModuleFederationFiles(host, options) {
|
|
|
16
17
|
exports.addModuleFederationFiles = addModuleFederationFiles;
|
|
17
18
|
function remoteGenerator(host, schema) {
|
|
18
19
|
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
const tasks = [];
|
|
19
21
|
const options = (0, normalize_options_1.normalizeOptions)(host, schema);
|
|
20
|
-
const
|
|
22
|
+
const initAppTask = yield (0, application_1.default)(host, Object.assign(Object.assign({}, options), {
|
|
23
|
+
// Only webpack works with module federation for now.
|
|
24
|
+
bundler: 'webpack' }));
|
|
25
|
+
tasks.push(initAppTask);
|
|
21
26
|
if (schema.host) {
|
|
22
27
|
(0, update_host_with_remote_1.updateHostWithRemote)(host, schema.host, options.name);
|
|
23
28
|
}
|
|
@@ -27,10 +32,22 @@ function remoteGenerator(host, schema) {
|
|
|
27
32
|
host.rename((0, path_1.join)(options.appProjectRoot, 'src/main.tsx'), (0, path_1.join)(options.appProjectRoot, 'src/bootstrap.tsx'));
|
|
28
33
|
addModuleFederationFiles(host, options);
|
|
29
34
|
(0, update_module_federation_project_1.updateModuleFederationProject)(host, options);
|
|
35
|
+
if (options.ssr) {
|
|
36
|
+
const setupSsrTask = yield (0, setup_ssr_1.default)(host, {
|
|
37
|
+
project: options.projectName,
|
|
38
|
+
serverPort: options.devServerPort,
|
|
39
|
+
});
|
|
40
|
+
tasks.push(setupSsrTask);
|
|
41
|
+
const setupSsrForRemoteTask = yield (0, setup_ssr_for_remote_1.setupSsrForRemote)(host, options, options.projectName);
|
|
42
|
+
tasks.push(setupSsrForRemoteTask);
|
|
43
|
+
const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
|
|
44
|
+
projectConfig.targets.server.options.webpackConfig = (0, devkit_1.joinPathFragments)(projectConfig.root, 'webpack.server.config.js');
|
|
45
|
+
(0, devkit_1.updateProjectConfiguration)(host, options.projectName, projectConfig);
|
|
46
|
+
}
|
|
30
47
|
if (!options.skipFormat) {
|
|
31
48
|
yield (0, devkit_1.formatFiles)(host);
|
|
32
49
|
}
|
|
33
|
-
return (0,
|
|
50
|
+
return (0, devkit_1.runTasksInSerial)(...tasks);
|
|
34
51
|
});
|
|
35
52
|
}
|
|
36
53
|
exports.remoteGenerator = remoteGenerator;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/remote/remote.ts"],"names":[],"mappings":";;;;AAAA,+BAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"remote.js","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/remote/remote.ts"],"names":[],"mappings":";;;;AAAA,+BAA4B;AAC5B,yCAUsB;AAEtB,4EAAwE;AACxE,4DAA8D;AAE9D,2EAAqE;AACrE,mGAA6F;AAE7F,sDAAuD;AACvD,qEAA+D;AAE/D,SAAgB,wBAAwB,CACtC,IAAU,EACV,OAAyB;IAEzB,MAAM,iBAAiB,iDAClB,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,GACnB,OAAO,KACV,IAAI,EAAE,EAAE,GACT,CAAC;IAEF,IAAA,sBAAa,EACX,IAAI,EACJ,IAAA,WAAI,EAAC,SAAS,EAAE,2BAA2B,CAAC,EAC5C,OAAO,CAAC,cAAc,EACtB,iBAAiB,CAClB,CAAC;AACJ,CAAC;AAhBD,4DAgBC;AAED,SAAsB,eAAe,CAAC,IAAU,EAAE,MAAc;;QAC9D,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,MAAM,OAAO,GAAG,IAAA,oCAAgB,EAAS,IAAI,EAAE,MAAM,CAAC,CAAC;QACvD,MAAM,WAAW,GAAG,MAAM,IAAA,qBAAoB,EAAC,IAAI,kCAC9C,OAAO;YACV,qDAAqD;YACrD,OAAO,EAAE,SAAS,IAClB,CAAC;QACH,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAExB,IAAI,MAAM,CAAC,IAAI,EAAE;YACf,IAAA,8CAAoB,EAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;SACvD;QAED,wEAAwE;QACxE,sEAAsE;QACtE,kBAAkB;QAClB,IAAI,CAAC,MAAM,CACT,IAAA,WAAI,EAAC,OAAO,CAAC,cAAc,EAAE,cAAc,CAA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
|
-
|
|
8
|
-
|
|
6
|
+
classComponent?: boolean;
|
|
7
|
+
compiler?: 'babel' | 'swc';
|
|
8
|
+
devServerPort?: number;
|
|
9
9
|
directory?: string;
|
|
10
|
-
tags?: string;
|
|
11
|
-
unitTestRunner: 'jest' | 'none';
|
|
12
10
|
e2eTestRunner: 'cypress' | 'none';
|
|
11
|
+
globalCss?: boolean;
|
|
12
|
+
host?: string;
|
|
13
|
+
js?: boolean;
|
|
13
14
|
linter: Linter;
|
|
15
|
+
name: string;
|
|
14
16
|
pascalCaseFiles?: boolean;
|
|
15
|
-
classComponent?: boolean;
|
|
16
17
|
routing?: boolean;
|
|
17
|
-
skipWorkspaceJson?: boolean;
|
|
18
|
-
js?: boolean;
|
|
19
|
-
globalCss?: boolean;
|
|
20
|
-
strict?: boolean;
|
|
21
18
|
setParserOptionsProject?: boolean;
|
|
19
|
+
skipFormat: boolean;
|
|
20
|
+
skipWorkspaceJson?: boolean;
|
|
21
|
+
ssr?: boolean;
|
|
22
22
|
standaloneConfig?: boolean;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
strict?: boolean;
|
|
24
|
+
style: SupportedStyles;
|
|
25
|
+
tags?: string;
|
|
26
|
+
unitTestRunner: 'jest' | 'vitest' | 'none';
|
|
26
27
|
}
|
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
"index": 0
|
|
15
15
|
},
|
|
16
16
|
"x-prompt": "What name would you like to use as the remote application?",
|
|
17
|
-
"pattern": "^[a-zA-Z].*$"
|
|
17
|
+
"pattern": "^[a-zA-Z].*$",
|
|
18
|
+
"x-priority": "important"
|
|
18
19
|
},
|
|
19
20
|
"directory": {
|
|
20
21
|
"description": "The directory of the new application.",
|
|
21
22
|
"type": "string",
|
|
22
|
-
"alias": "dir"
|
|
23
|
+
"alias": "dir",
|
|
24
|
+
"x-priority": "important"
|
|
23
25
|
},
|
|
24
26
|
"style": {
|
|
25
27
|
"description": "The file extension to be used for style files.",
|
|
@@ -68,7 +70,7 @@
|
|
|
68
70
|
"linter": {
|
|
69
71
|
"description": "The tool to use for running lint checks.",
|
|
70
72
|
"type": "string",
|
|
71
|
-
"enum": ["eslint"
|
|
73
|
+
"enum": ["eslint"],
|
|
72
74
|
"default": "eslint"
|
|
73
75
|
},
|
|
74
76
|
"routing": {
|
|
@@ -79,12 +81,14 @@
|
|
|
79
81
|
"skipFormat": {
|
|
80
82
|
"description": "Skip formatting files.",
|
|
81
83
|
"type": "boolean",
|
|
82
|
-
"default": false
|
|
84
|
+
"default": false,
|
|
85
|
+
"x-priority": "internal"
|
|
83
86
|
},
|
|
84
87
|
"skipWorkspaceJson": {
|
|
85
88
|
"description": "Skip updating workspace.json with default options based on values provided to this app (e.g. babel, style).",
|
|
86
89
|
"type": "boolean",
|
|
87
|
-
"default": false
|
|
90
|
+
"default": false,
|
|
91
|
+
"x-priority": "internal"
|
|
88
92
|
},
|
|
89
93
|
"unitTestRunner": {
|
|
90
94
|
"type": "string",
|
|
@@ -137,7 +141,9 @@
|
|
|
137
141
|
},
|
|
138
142
|
"standaloneConfig": {
|
|
139
143
|
"description": "Split the project configuration into <projectRoot>/project.json rather than including it inside workspace.json",
|
|
140
|
-
"type": "boolean"
|
|
144
|
+
"type": "boolean",
|
|
145
|
+
"default": true,
|
|
146
|
+
"x-deprecated": "Nx only supports standaloneConfig"
|
|
141
147
|
},
|
|
142
148
|
"compiler": {
|
|
143
149
|
"type": "string",
|
|
@@ -147,11 +153,19 @@
|
|
|
147
153
|
},
|
|
148
154
|
"host": {
|
|
149
155
|
"type": "string",
|
|
150
|
-
"description": "The host / shell application for this remote."
|
|
156
|
+
"description": "The host / shell application for this remote.",
|
|
157
|
+
"x-priority": "important"
|
|
151
158
|
},
|
|
152
159
|
"devServerPort": {
|
|
153
160
|
"type": "number",
|
|
154
|
-
"description": "The port for the dev server of the remote app."
|
|
161
|
+
"description": "The port for the dev server of the remote app.",
|
|
162
|
+
"default": 4200,
|
|
163
|
+
"x-priority": "important"
|
|
164
|
+
},
|
|
165
|
+
"ssr": {
|
|
166
|
+
"description": "Whether to configure SSR for the host application",
|
|
167
|
+
"type": "boolean",
|
|
168
|
+
"default": false
|
|
155
169
|
}
|
|
156
170
|
},
|
|
157
171
|
"required": ["name"],
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import * as path from 'path';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
import cors from 'cors';
|
|
4
|
+
|
|
5
|
+
import { handleRequest } from './src/main.server';
|
|
6
|
+
|
|
7
|
+
const port = process.env['PORT'] || 4200;
|
|
8
|
+
const app = express();
|
|
9
|
+
|
|
10
|
+
const browserDist = path.join(process.cwd(), '<%= browserBuildOutputPath %>');
|
|
11
|
+
const indexPath =path.join(browserDist, 'index.html');
|
|
12
|
+
|
|
13
|
+
app.use(cors());
|
|
14
|
+
|
|
15
|
+
app.get(
|
|
16
|
+
'*.*',
|
|
17
|
+
express.static(browserDist, {
|
|
18
|
+
maxAge: '1y',
|
|
19
|
+
})
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
app.use('*', handleRequest(indexPath));
|
|
23
|
+
|
|
24
|
+
const server = app.listen(port, () => {
|
|
25
|
+
// Server has started
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
server.on('error', console.error);
|
|
@@ -0,0 +1,47 @@
|
|
|
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 './<%= appComponentImport %>';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
let indexHtml: null | string = null;
|
|
10
|
+
|
|
11
|
+
export function handleRequest(indexPath: string) {
|
|
12
|
+
return function render(req: Request, res: Response) {
|
|
13
|
+
let didError = false;
|
|
14
|
+
|
|
15
|
+
if (!indexHtml) {
|
|
16
|
+
indexHtml = fs.readFileSync(indexPath).toString();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const [htmlStart, htmlEnd] = indexHtml.split(`<div id="root"></div>`);
|
|
20
|
+
|
|
21
|
+
// For bots (e.g. search engines), the content will not be streamed but render all at once.
|
|
22
|
+
// For users, content should be streamed to the user as they are ready.
|
|
23
|
+
const callbackName = isbot(req.headers['user-agent']) ? 'onAllReady' : 'onShellReady';
|
|
24
|
+
|
|
25
|
+
const stream = ReactDOMServer.renderToPipeableStream(
|
|
26
|
+
<App />,
|
|
27
|
+
{
|
|
28
|
+
[callbackName]() {
|
|
29
|
+
res.statusCode = didError ? 500 : 200;
|
|
30
|
+
res.setHeader('Content-type', 'text/html; charset=utf-8');
|
|
31
|
+
res.write(`${htmlStart}<div id="root">`);
|
|
32
|
+
stream.pipe(res);
|
|
33
|
+
res.write(`</div>${htmlEnd}`);
|
|
34
|
+
},
|
|
35
|
+
onShellError(error) {
|
|
36
|
+
console.error(error);
|
|
37
|
+
res.statusCode = 500;
|
|
38
|
+
res.send('<!doctype html><h1>Server Error</h1>');
|
|
39
|
+
},
|
|
40
|
+
onError(error) {
|
|
41
|
+
didError = true;
|
|
42
|
+
console.error(error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"$id": "GeneratorReactSSRSetup",
|
|
4
|
+
"cli": "nx",
|
|
5
|
+
"title": "Generate SSR setup for a React app",
|
|
6
|
+
"description": "Create the additional configuration required to enable SSR via Express for a React application.",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"project": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "The name of the application to add SSR support to.",
|
|
12
|
+
"$default": {
|
|
13
|
+
"$source": "argv",
|
|
14
|
+
"index": 0
|
|
15
|
+
},
|
|
16
|
+
"x-prompt": "What app would you like to add SSR support to?",
|
|
17
|
+
"x-dropdown": "projects",
|
|
18
|
+
"x-priority": "important"
|
|
19
|
+
},
|
|
20
|
+
"appComponentImportPath": {
|
|
21
|
+
"type": "string",
|
|
22
|
+
"description": "The import path of the <App/ > component, relative to project sourceRoot.",
|
|
23
|
+
"default": "app/app"
|
|
24
|
+
},
|
|
25
|
+
"serverPort": {
|
|
26
|
+
"type": "number",
|
|
27
|
+
"default": 4200,
|
|
28
|
+
"description": "The port for the Express server.",
|
|
29
|
+
"x-priority": "important"
|
|
30
|
+
},
|
|
31
|
+
"skipFormat": {
|
|
32
|
+
"type": "boolean",
|
|
33
|
+
"description": "Skip formatting the workspace after the generator completes.",
|
|
34
|
+
"x-priority": "internal"
|
|
35
|
+
},
|
|
36
|
+
"extraInclude": {
|
|
37
|
+
"type": "array",
|
|
38
|
+
"items": {
|
|
39
|
+
"type": "string"
|
|
40
|
+
},
|
|
41
|
+
"hidden": true,
|
|
42
|
+
"description": "Extra include entries in tsconfig.",
|
|
43
|
+
"default": []
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"required": ["project"],
|
|
47
|
+
"additionalProperties": false
|
|
48
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Tree } from '@nrwl/devkit';
|
|
2
|
+
import type { Schema } from './schema';
|
|
3
|
+
export declare function setupSsrGenerator(tree: Tree, options: Schema): Promise<import("@nrwl/devkit").GeneratorCallback>;
|
|
4
|
+
export default setupSsrGenerator;
|
|
5
|
+
export declare const setupSsrSchematic: (generatorOptions: Schema) => (tree: any, context: any) => Promise<any>;
|