@nx/react 23.0.0-beta.2 → 23.0.0-beta.21
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/generators.json +16 -3
- package/index.d.ts +0 -3
- package/index.d.ts.map +1 -1
- package/index.js +1 -4
- package/migrations.json +6 -0
- package/package.json +18 -18
- package/plugins/component-testing/index.js +7 -7
- package/plugins/component-testing/webpack-fallback.js +2 -2
- package/plugins/storybook/index.js +3 -3
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-dev-server/module-federation-dev-server.impl.js +6 -4
- package/src/executors/module-federation-dev-server/schema.json +1 -0
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-ssr-dev-server/module-federation-ssr-dev-server.impl.js +7 -5
- package/src/executors/module-federation-ssr-dev-server/schema.json +1 -0
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.d.ts.map +1 -1
- package/src/executors/module-federation-static-server/module-federation-static-server.impl.js +6 -4
- package/src/executors/module-federation-static-server/schema.json +1 -0
- package/src/generators/_utils/mf-dependencies.d.ts +8 -0
- package/src/generators/_utils/mf-dependencies.d.ts.map +1 -0
- package/src/generators/_utils/mf-dependencies.js +84 -0
- package/src/generators/_utils/mf-versions.d.ts +12 -0
- package/src/generators/_utils/mf-versions.d.ts.map +1 -0
- package/src/generators/_utils/mf-versions.js +29 -0
- package/src/generators/_utils/normalize.d.ts +20 -0
- package/src/generators/_utils/normalize.d.ts.map +1 -0
- package/src/generators/_utils/normalize.js +48 -0
- package/src/generators/application/application.d.ts.map +1 -1
- package/src/generators/application/application.js +32 -18
- package/src/generators/application/lib/add-e2e.d.ts.map +1 -1
- package/src/generators/application/lib/add-linting.js +10 -11
- package/src/generators/application/lib/add-project.d.ts.map +1 -1
- package/src/generators/application/lib/add-project.js +10 -0
- package/src/generators/application/lib/add-routing.js +2 -2
- package/src/generators/application/lib/bundlers/add-vite.d.ts.map +1 -1
- package/src/generators/application/lib/bundlers/add-vite.js +10 -2
- package/src/generators/application/lib/create-application-files.d.ts +1 -1
- package/src/generators/application/lib/create-application-files.js +2 -2
- package/src/generators/application/lib/normalize-options.js +5 -5
- package/src/generators/component/component.js +2 -2
- package/src/generators/component/lib/normalize-options.d.ts.map +1 -1
- package/src/generators/component/lib/normalize-options.js +5 -6
- package/src/generators/component/schema.d.ts +2 -7
- package/src/generators/component/schema.json +0 -5
- package/src/generators/component-story/component-story.d.ts.map +1 -1
- package/src/generators/component-story/component-story.js +3 -4
- package/src/generators/component-test/component-test.d.ts.map +1 -1
- package/src/generators/component-test/component-test.js +3 -4
- package/src/generators/consumer/consumer.d.ts +5 -0
- package/src/generators/consumer/consumer.d.ts.map +1 -0
- package/src/generators/consumer/consumer.js +135 -0
- package/src/generators/consumer/files/_common/src/App.tsx__tmpl__ +53 -0
- package/src/generators/consumer/files/_common/src/bootstrap.tsx__tmpl__ +12 -0
- package/src/generators/consumer/files/_common/src/index.ts__tmpl__ +4 -0
- package/src/generators/consumer/files/_common/src/mf.ts__tmpl__ +35 -0
- package/src/generators/consumer/files/_common/tsconfig.json__tmpl__ +17 -0
- package/src/generators/consumer/files/rsbuild/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/rsbuild/package.json__tmpl__ +23 -0
- package/src/generators/consumer/files/rsbuild/rsbuild.config.ts__tmpl__ +25 -0
- package/src/generators/consumer/files/rspack/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/rspack/package.json__tmpl__ +23 -0
- package/src/generators/consumer/files/rspack/rspack.config.ts__tmpl__ +59 -0
- package/src/generators/consumer/files/vite/index.html__tmpl__ +12 -0
- package/src/generators/consumer/files/vite/package.json__tmpl__ +24 -0
- package/src/generators/consumer/files/vite/vite.config.ts__tmpl__ +27 -0
- package/src/generators/consumer/schema.d.ts +8 -0
- package/src/generators/consumer/schema.json +43 -0
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.d.ts.map +1 -1
- package/src/generators/cypress-component-configuration/lib/add-files.js +4 -4
- package/src/generators/federate-module/federate-module.d.ts.map +1 -1
- package/src/generators/federate-module/federate-module.js +4 -2
- package/src/generators/federate-module/lib/utils.js +2 -2
- package/src/generators/hook/hook.d.ts.map +1 -1
- package/src/generators/hook/hook.js +5 -6
- package/src/generators/host/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.prod.ts__tmpl__ +2 -2
- package/src/generators/host/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.prod.ts__tmpl__ +2 -2
- package/src/generators/host/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +2 -2
- package/src/generators/host/host.d.ts.map +1 -1
- package/src/generators/host/host.js +7 -5
- package/src/generators/host/lib/add-module-federation-files.d.ts.map +1 -1
- package/src/generators/host/lib/add-module-federation-files.js +3 -3
- package/src/generators/host/lib/normalize-host-name.js +2 -2
- package/src/generators/host/lib/update-module-federation-tsconfig.js +2 -2
- package/src/generators/init/init.d.ts.map +1 -1
- package/src/generators/init/init.js +2 -2
- package/src/generators/library/lib/add-linting.js +7 -8
- package/src/generators/library/lib/add-rollup-build-target.d.ts.map +1 -1
- package/src/generators/library/lib/add-rollup-build-target.js +6 -0
- package/src/generators/library/lib/install-common-dependencies.js +2 -2
- package/src/generators/library/lib/normalize-options.d.ts.map +1 -1
- package/src/generators/library/lib/normalize-options.js +7 -7
- package/src/generators/library/lib/update-app-routes.js +2 -2
- package/src/generators/library/library.d.ts.map +1 -1
- package/src/generators/library/library.js +14 -18
- package/src/generators/provider/files/_common/src/__componentName__.tsx__tmpl__ +11 -0
- package/src/generators/provider/files/_common/src/bootstrap.tsx__tmpl__ +12 -0
- package/src/generators/provider/files/_common/src/index.ts__tmpl__ +5 -0
- package/src/generators/provider/files/_common/tsconfig.json__tmpl__ +17 -0
- package/src/generators/provider/files/rsbuild/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/rsbuild/package.json__tmpl__ +22 -0
- package/src/generators/provider/files/rsbuild/rsbuild.config.ts__tmpl__ +31 -0
- package/src/generators/provider/files/rspack/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/rspack/package.json__tmpl__ +22 -0
- package/src/generators/provider/files/rspack/rspack.config.ts__tmpl__ +69 -0
- package/src/generators/provider/files/vite/index.html__tmpl__ +12 -0
- package/src/generators/provider/files/vite/package.json__tmpl__ +23 -0
- package/src/generators/provider/files/vite/vite.config.ts__tmpl__ +37 -0
- package/src/generators/provider/provider.d.ts +5 -0
- package/src/generators/provider/provider.d.ts.map +1 -0
- package/src/generators/provider/provider.js +92 -0
- package/src/generators/provider/schema.d.ts +9 -0
- package/src/generators/provider/schema.json +46 -0
- package/src/generators/redux/redux.d.ts.map +1 -1
- package/src/generators/redux/redux.js +7 -8
- package/src/generators/redux/schema.d.ts +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/rspack-module-federation-ts/rspack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/module-federation.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ssr-ts/webpack.server.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/module-federation.config.ts__tmpl__ +1 -1
- package/src/generators/remote/files/webpack-module-federation-ts/webpack.config.ts__tmpl__ +1 -1
- package/src/generators/remote/lib/setup-package-json-exports-for-remote.js +2 -2
- package/src/generators/remote/lib/update-host-with-remote.js +4 -5
- package/src/generators/remote/remote.d.ts.map +1 -1
- package/src/generators/remote/remote.js +9 -7
- package/src/generators/setup-ssr/setup-ssr.d.ts.map +1 -1
- package/src/generators/setup-ssr/setup-ssr.js +5 -7
- package/src/generators/stories/stories.js +5 -6
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.d.ts.map +1 -1
- package/src/migrations/update-20-2-0/migrate-with-mf-import-to-new-package.js +2 -2
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.d.ts.map +1 -1
- package/src/migrations/update-20-3-0/ensure-nx-module-federation-package.js +2 -2
- package/src/migrations/update-22-0-0/add-svgr-to-webpack-config.d.ts.map +1 -1
- package/src/migrations/update-22-0-0/add-svgr-to-webpack-config.js +2 -2
- package/src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import.d.ts +3 -0
- package/src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import.d.ts.map +1 -0
- package/src/migrations/update-23-0-0/remove-nx-react-webpack-plugin-import.js +128 -0
- package/src/module-federation/ast-utils.js +2 -2
- package/src/plugins/router-plugin.d.ts.map +1 -1
- package/src/plugins/router-plugin.js +14 -23
- package/src/rules/update-module-federation-project.js +3 -3
- package/src/utils/add-mf-env-to-inputs.d.ts.map +1 -1
- package/src/utils/add-mf-env-to-inputs.js +15 -8
- package/src/utils/ast-utils.js +15 -15
- package/src/utils/component-props.js +3 -3
- package/src/utils/create-ts-config.js +3 -3
- package/src/utils/ct-utils.d.ts +1 -1
- package/src/utils/ct-utils.d.ts.map +1 -1
- package/src/utils/ct-utils.js +6 -6
- package/src/utils/module-federation-deprecation.d.ts +13 -0
- package/src/utils/module-federation-deprecation.d.ts.map +1 -0
- package/src/utils/module-federation-deprecation.js +46 -0
- package/src/utils/normalize-remote.js +2 -2
- package/src/utils/versions.d.ts +1 -1
- package/src/utils/versions.js +1 -1
- package/tailwind.js +2 -2
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= projectName %>",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "rsbuild dev --port <%= port %>",
|
|
7
|
+
"build": "rsbuild build",
|
|
8
|
+
"preview": "rsbuild preview --port <%= port %>"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"react": "<%= versions.reactVersion %>",
|
|
12
|
+
"react-dom": "<%= versions.reactDomVersion %>"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@module-federation/rsbuild-plugin": "<%= versions.moduleFederationRsbuildPluginVersion %>",
|
|
16
|
+
"@rsbuild/core": "<%= versions.rsbuildCoreVersion %>",
|
|
17
|
+
"@rsbuild/plugin-react": "<%= versions.rsbuildPluginReactVersion %>",
|
|
18
|
+
"@types/react": "<%= versions.typesReactVersion %>",
|
|
19
|
+
"@types/react-dom": "<%= versions.typesReactDomVersion %>",
|
|
20
|
+
"typescript": "<%= versions.typescriptVersion %>"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { defineConfig } from '@rsbuild/core';
|
|
2
|
+
import { pluginReact } from '@rsbuild/plugin-react';
|
|
3
|
+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
|
|
4
|
+
|
|
5
|
+
const PORT = <%= port %>;
|
|
6
|
+
const NAME = '<%= federationName %>';
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
server: {
|
|
10
|
+
port: PORT,
|
|
11
|
+
// Allow cross-origin fetches from a consumer on a different port.
|
|
12
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
13
|
+
},
|
|
14
|
+
// assetPrefix:true tells rsbuild to emit chunks with the dev-server URL as
|
|
15
|
+
// their public path. Without it a consumer on a different port asks its
|
|
16
|
+
// own origin for the federated chunks and gets the SPA-fallback HTML.
|
|
17
|
+
dev: { assetPrefix: true },
|
|
18
|
+
html: { template: './index.html' },
|
|
19
|
+
source: { entry: { index: './src/index.ts' } },
|
|
20
|
+
plugins: [
|
|
21
|
+
pluginReact(),
|
|
22
|
+
pluginModuleFederation({
|
|
23
|
+
name: NAME,
|
|
24
|
+
filename: 'remoteEntry.js',
|
|
25
|
+
exposes: {
|
|
26
|
+
'./<%= exposeName %>': './src/<%= componentName %>.tsx',
|
|
27
|
+
},
|
|
28
|
+
shared: ['react', 'react-dom'],
|
|
29
|
+
}),
|
|
30
|
+
],
|
|
31
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<title><%= projectName %> (standalone)</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<!-- HtmlRspackPlugin injects the entry script automatically; do not add it here. -->
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= projectName %>",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"scripts": {
|
|
6
|
+
"dev": "rspack serve --mode=development",
|
|
7
|
+
"build": "rspack build --mode=production"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"@module-federation/enhanced": "<%= versions.moduleFederationEnhancedVersion %>",
|
|
11
|
+
"react": "<%= versions.reactVersion %>",
|
|
12
|
+
"react-dom": "<%= versions.reactDomVersion %>"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {
|
|
15
|
+
"@rspack/cli": "<%= versions.rspackCliVersion %>",
|
|
16
|
+
"@rspack/core": "<%= versions.rspackCoreVersion %>",
|
|
17
|
+
"@rspack/dev-server": "<%= versions.rspackDevServerVersion %>",
|
|
18
|
+
"@types/react": "<%= versions.typesReactVersion %>",
|
|
19
|
+
"@types/react-dom": "<%= versions.typesReactDomVersion %>",
|
|
20
|
+
"typescript": "<%= versions.typescriptVersion %>"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineConfig } from '@rspack/cli';
|
|
2
|
+
import { rspack } from '@rspack/core';
|
|
3
|
+
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
// __dirname is undefined when @rspack/cli loads this config as ESM (it
|
|
8
|
+
// does, because the file uses `import` statements). Derive it from the
|
|
9
|
+
// module URL so the config works regardless of how the loader interprets it.
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
const PORT = <%= port %>;
|
|
13
|
+
const NAME = '<%= federationName %>';
|
|
14
|
+
|
|
15
|
+
// Read mode from the rspack CLI arg (`--mode=development|production`) so the
|
|
16
|
+
// config works the same on Windows + POSIX without depending on a shell
|
|
17
|
+
// `NODE_ENV=...` prefix.
|
|
18
|
+
export default defineConfig((_env, argv) => {
|
|
19
|
+
const isDev = argv.mode !== 'production';
|
|
20
|
+
return {
|
|
21
|
+
context: __dirname,
|
|
22
|
+
entry: { main: './src/index.ts' },
|
|
23
|
+
output: {
|
|
24
|
+
path: path.resolve(__dirname, 'dist'),
|
|
25
|
+
publicPath: 'auto',
|
|
26
|
+
uniqueName: NAME,
|
|
27
|
+
clean: true,
|
|
28
|
+
},
|
|
29
|
+
devServer: {
|
|
30
|
+
port: PORT,
|
|
31
|
+
historyApiFallback: true,
|
|
32
|
+
hot: true,
|
|
33
|
+
headers: { 'Access-Control-Allow-Origin': '*' },
|
|
34
|
+
},
|
|
35
|
+
resolve: { extensions: ['...', '.ts', '.tsx', '.jsx'] },
|
|
36
|
+
module: {
|
|
37
|
+
rules: [
|
|
38
|
+
{
|
|
39
|
+
test: /\.(j|t)sx?$/,
|
|
40
|
+
exclude: [/node_modules/],
|
|
41
|
+
use: {
|
|
42
|
+
loader: 'builtin:swc-loader',
|
|
43
|
+
options: {
|
|
44
|
+
jsc: {
|
|
45
|
+
parser: { syntax: 'typescript', tsx: true },
|
|
46
|
+
transform: { react: { runtime: 'automatic', development: isDev } },
|
|
47
|
+
},
|
|
48
|
+
env: { targets: 'Chrome >= 87, Firefox >= 78, Edge >= 88, Safari >= 14' },
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
plugins: [
|
|
55
|
+
// excludeChunks is REQUIRED on a provider: without it the federation
|
|
56
|
+
// remoteEntry chunk gets injected into the standalone HTML and breaks
|
|
57
|
+
// direct serves.
|
|
58
|
+
new rspack.HtmlRspackPlugin({ template: './index.html', excludeChunks: [NAME] }),
|
|
59
|
+
new ModuleFederationPlugin({
|
|
60
|
+
name: NAME,
|
|
61
|
+
filename: 'remoteEntry.js',
|
|
62
|
+
exposes: {
|
|
63
|
+
'./<%= exposeName %>': './src/<%= componentName %>.tsx',
|
|
64
|
+
},
|
|
65
|
+
shared: ['react', 'react-dom'],
|
|
66
|
+
}),
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
6
|
+
<title><%= projectName %> (standalone)</title>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" src="/src/index.ts"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= projectName %>",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"private": true,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite --port <%= port %> --strictPort",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"preview": "vite preview --port <%= port %> --strictPort"
|
|
10
|
+
},
|
|
11
|
+
"dependencies": {
|
|
12
|
+
"react": "<%= versions.reactVersion %>",
|
|
13
|
+
"react-dom": "<%= versions.reactDomVersion %>"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@module-federation/vite": "<%= versions.moduleFederationVitePluginVersion %>",
|
|
17
|
+
"@types/react": "<%= versions.typesReactVersion %>",
|
|
18
|
+
"@types/react-dom": "<%= versions.typesReactDomVersion %>",
|
|
19
|
+
"@vitejs/plugin-react": "<%= versions.vitejsPluginReactVersion %>",
|
|
20
|
+
"typescript": "<%= versions.typescriptVersion %>",
|
|
21
|
+
"vite": "<%= versions.viteVersion %>"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { defineConfig } from 'vite';
|
|
2
|
+
import react from '@vitejs/plugin-react';
|
|
3
|
+
import { federation } from '@module-federation/vite';
|
|
4
|
+
|
|
5
|
+
// Port deliberately avoids 5000 (macOS AirTunes binds it on 0.0.0.0, leading
|
|
6
|
+
// to silent EADDRINUSE on 127.0.0.1). Override `--port` only if 5000+ is free.
|
|
7
|
+
const PORT = <%= port %>;
|
|
8
|
+
|
|
9
|
+
export default defineConfig({
|
|
10
|
+
server: {
|
|
11
|
+
port: PORT,
|
|
12
|
+
strictPort: true,
|
|
13
|
+
origin: `http://localhost:${PORT}`,
|
|
14
|
+
host: '127.0.0.1',
|
|
15
|
+
// Allow cross-origin fetches of mf-manifest.json + chunks from a consumer
|
|
16
|
+
// running on a different port. Vite 8 narrows the default CORS allowlist
|
|
17
|
+
// to specific localhost patterns; setting `cors: true` emits a wildcard
|
|
18
|
+
// `Access-Control-Allow-Origin: *` for dev which is what federation needs.
|
|
19
|
+
cors: true,
|
|
20
|
+
},
|
|
21
|
+
preview: { port: PORT, strictPort: true, cors: true },
|
|
22
|
+
build: { target: 'chrome89' },
|
|
23
|
+
plugins: [
|
|
24
|
+
federation({
|
|
25
|
+
name: '<%= federationName %>',
|
|
26
|
+
filename: 'remoteEntry.js',
|
|
27
|
+
exposes: {
|
|
28
|
+
'./<%= exposeName %>': './src/<%= componentName %>.tsx',
|
|
29
|
+
},
|
|
30
|
+
shared: {
|
|
31
|
+
react: { singleton: true },
|
|
32
|
+
'react-dom': { singleton: true },
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
react(),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { GeneratorCallback, Tree } from '@nx/devkit';
|
|
2
|
+
import type { ProviderGeneratorSchema } from './schema';
|
|
3
|
+
export declare function providerGenerator(tree: Tree, schema: ProviderGeneratorSchema): Promise<GeneratorCallback>;
|
|
4
|
+
export default providerGenerator;
|
|
5
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,iBAAiB,EAIjB,IAAI,EACL,MAAM,YAAY,CAAC;AAWpB,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAgBxD,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAwF5B;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.providerGenerator = providerGenerator;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const versions_1 = require("@nx/js/src/utils/versions");
|
|
7
|
+
const versions_2 = require("../../utils/versions");
|
|
8
|
+
const mfVersions = tslib_1.__importStar(require("../_utils/mf-versions"));
|
|
9
|
+
const mf_dependencies_1 = require("../_utils/mf-dependencies");
|
|
10
|
+
const normalize_1 = require("../_utils/normalize");
|
|
11
|
+
// `--mode=...` is rspack's portable equivalent of `NODE_ENV=...` and works on
|
|
12
|
+
// Windows without a shell prefix.
|
|
13
|
+
const BUNDLER_DEV_COMMAND = {
|
|
14
|
+
vite: 'vite',
|
|
15
|
+
rsbuild: 'rsbuild dev',
|
|
16
|
+
rspack: 'rspack serve --mode=development',
|
|
17
|
+
};
|
|
18
|
+
const BUNDLER_BUILD_COMMAND = {
|
|
19
|
+
vite: 'vite build',
|
|
20
|
+
rsbuild: 'rsbuild build',
|
|
21
|
+
rspack: 'rspack build --mode=production',
|
|
22
|
+
};
|
|
23
|
+
async function providerGenerator(tree, schema) {
|
|
24
|
+
const opts = await (0, normalize_1.normalizeScaffoldOptions)(tree, {
|
|
25
|
+
directory: schema.directory,
|
|
26
|
+
surface: 'provider',
|
|
27
|
+
bundler: schema.bundler,
|
|
28
|
+
port: schema.port,
|
|
29
|
+
});
|
|
30
|
+
// `exposeName` is the public MF expose key (consumers reference
|
|
31
|
+
// `<provider>/<exposeName>`) and may be kebab-case, e.g. `cart-widget`.
|
|
32
|
+
// `componentName` is the PascalCase identifier used for the React function
|
|
33
|
+
// and its filename, since `export function cart-widget()` would be invalid.
|
|
34
|
+
const exposeName = schema.exposeName?.trim() || 'App';
|
|
35
|
+
const componentName = (0, devkit_1.names)(exposeName).className;
|
|
36
|
+
// `dependsOn` on a `continuous: true` target lets nx spin up the consumer
|
|
37
|
+
// alongside the provider - matches the deprecated host/remote 'serve a
|
|
38
|
+
// remote, host comes along' UX. Only wired when --consumer is set (e.g.
|
|
39
|
+
// when the consumer generator scaffolds this provider).
|
|
40
|
+
const serveTarget = {
|
|
41
|
+
executor: 'nx:run-commands',
|
|
42
|
+
continuous: true,
|
|
43
|
+
options: {
|
|
44
|
+
command: BUNDLER_DEV_COMMAND[opts.bundler],
|
|
45
|
+
cwd: opts.projectRoot,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
if (schema.consumer) {
|
|
49
|
+
serveTarget.dependsOn = [`${schema.consumer}:serve`];
|
|
50
|
+
}
|
|
51
|
+
(0, devkit_1.addProjectConfiguration)(tree, opts.projectName, {
|
|
52
|
+
root: opts.projectRoot,
|
|
53
|
+
sourceRoot: (0, devkit_1.joinPathFragments)(opts.projectRoot, 'src'),
|
|
54
|
+
projectType: 'application',
|
|
55
|
+
targets: {
|
|
56
|
+
serve: serveTarget,
|
|
57
|
+
build: {
|
|
58
|
+
executor: 'nx:run-commands',
|
|
59
|
+
options: {
|
|
60
|
+
command: BUNDLER_BUILD_COMMAND[opts.bundler],
|
|
61
|
+
cwd: opts.projectRoot,
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const templateSubstitutions = {
|
|
67
|
+
projectName: opts.projectName,
|
|
68
|
+
federationName: opts.federationName,
|
|
69
|
+
port: opts.port,
|
|
70
|
+
exposeName,
|
|
71
|
+
componentName,
|
|
72
|
+
versions: {
|
|
73
|
+
...mfVersions,
|
|
74
|
+
reactVersion: versions_2.reactVersion,
|
|
75
|
+
reactDomVersion: versions_2.reactDomVersion,
|
|
76
|
+
typesReactVersion: versions_2.typesReactVersion,
|
|
77
|
+
typesReactDomVersion: versions_2.typesReactDomVersion,
|
|
78
|
+
typescriptVersion: versions_1.typescriptVersion,
|
|
79
|
+
},
|
|
80
|
+
tmpl: '',
|
|
81
|
+
};
|
|
82
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', '_common'), opts.projectRoot, templateSubstitutions);
|
|
83
|
+
(0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, 'files', opts.bundler), opts.projectRoot, templateSubstitutions);
|
|
84
|
+
// Write deps into the workspace root package.json so bare bundler bins
|
|
85
|
+
// resolve when nx invokes the generated run-commands serve target. The
|
|
86
|
+
// per-project package.json template still ships for pnpm-workspace setups.
|
|
87
|
+
const deps = (0, mf_dependencies_1.getProviderDeps)(opts.bundler);
|
|
88
|
+
const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, deps.dependencies, deps.devDependencies);
|
|
89
|
+
await (0, devkit_1.formatFiles)(tree);
|
|
90
|
+
return (0, devkit_1.runTasksInSerial)(installTask);
|
|
91
|
+
}
|
|
92
|
+
exports.default = providerGenerator;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/schema",
|
|
3
|
+
"$id": "NxReactProvider",
|
|
4
|
+
"title": "Create a Module Federation provider",
|
|
5
|
+
"description": "Scaffold a React Module Federation provider that exposes a federated component. The bundler is selected at generation time; the generated project has no Nx-wrapped bundler config.",
|
|
6
|
+
"cli": "nx",
|
|
7
|
+
"type": "object",
|
|
8
|
+
"properties": {
|
|
9
|
+
"directory": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Directory the provider is generated in, e.g. `apps/my-provider`. The project name (also used as the federation `name`, with hyphens converted to underscores) is inferred from the trailing path segment.",
|
|
12
|
+
"alias": "dir",
|
|
13
|
+
"$default": { "$source": "argv", "index": 0 },
|
|
14
|
+
"x-prompt": "Which directory do you want to create the provider in?"
|
|
15
|
+
},
|
|
16
|
+
"bundler": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Bundler used by the provider. The choice is final - the bundler config is too different to switch later.",
|
|
19
|
+
"enum": ["vite", "rsbuild", "rspack"],
|
|
20
|
+
"default": "vite",
|
|
21
|
+
"x-prompt": {
|
|
22
|
+
"message": "Which bundler should the provider use?",
|
|
23
|
+
"type": "list",
|
|
24
|
+
"items": [
|
|
25
|
+
{ "value": "vite", "label": "Vite (default)" },
|
|
26
|
+
{ "value": "rsbuild", "label": "Rsbuild" },
|
|
27
|
+
{ "value": "rspack", "label": "Rspack" }
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"port": {
|
|
32
|
+
"type": "number",
|
|
33
|
+
"description": "Dev-server port the provider listens on. Defaults to a non-5000 port to avoid the macOS AirTunes collision on Vite."
|
|
34
|
+
},
|
|
35
|
+
"exposeName": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Name under which the federated component is exposed (consumers reference `<name>/<exposeName>`).",
|
|
38
|
+
"default": "App"
|
|
39
|
+
},
|
|
40
|
+
"consumer": {
|
|
41
|
+
"type": "string",
|
|
42
|
+
"description": "Name of a consumer project whose `serve` target this provider should depend on. When set, `nx serve <provider>` also spins up the consumer (the 'serve a remote, host comes along' UX from the deprecated host/remote generators). Set automatically when the provider is generated as part of `@nx/react:consumer --providerNames=...`."
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"required": ["directory"]
|
|
46
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"redux.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/redux/redux.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"redux.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/redux/redux.ts"],"names":[],"mappings":"AACA,OAAO,EASL,IAAI,EACL,MAAM,YAAY,CAAC;AAcpB,OAAO,EAAoB,MAAM,EAAE,MAAM,UAAU,CAAC;AAIpD,wBAAsB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mDAW9D;AA0LD,eAAe,cAAc,CAAC"}
|
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.reduxGenerator = reduxGenerator;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
5
6
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
7
7
|
const js_1 = require("@nx/js");
|
|
8
|
-
const
|
|
9
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
8
|
+
const internal_2 = require("@nx/js/internal");
|
|
10
9
|
const path = tslib_1.__importStar(require("path"));
|
|
11
10
|
const ast_utils_1 = require("../../utils/ast-utils");
|
|
12
11
|
const versions_1 = require("../../utils/versions");
|
|
@@ -35,7 +34,7 @@ function addReduxPackageDependencies(host) {
|
|
|
35
34
|
}
|
|
36
35
|
function addExportsToBarrel(host, options) {
|
|
37
36
|
if (!tsModule) {
|
|
38
|
-
tsModule = (0,
|
|
37
|
+
tsModule = (0, internal_2.ensureTypescript)();
|
|
39
38
|
}
|
|
40
39
|
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourcePath, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
|
|
41
40
|
if (!host.exists(indexFilePath)) {
|
|
@@ -62,7 +61,7 @@ function addStoreConfiguration(host, options) {
|
|
|
62
61
|
}
|
|
63
62
|
function updateReducerConfiguration(host, options) {
|
|
64
63
|
if (!tsModule) {
|
|
65
|
-
tsModule = (0,
|
|
64
|
+
tsModule = (0, internal_2.ensureTypescript)();
|
|
66
65
|
}
|
|
67
66
|
if (!options.appProjectSourcePath) {
|
|
68
67
|
return;
|
|
@@ -77,7 +76,7 @@ function updateReducerConfiguration(host, options) {
|
|
|
77
76
|
host.write(options.appMainFilePath, changes);
|
|
78
77
|
}
|
|
79
78
|
async function normalizeOptions(host, options) {
|
|
80
|
-
const { artifactName: name, directory, fileName, fileExtension, fileExtensionType, project: projectName, } = await (0,
|
|
79
|
+
const { artifactName: name, directory, fileName, fileExtension, fileExtensionType, project: projectName, } = await (0, internal_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
81
80
|
path: options.path,
|
|
82
81
|
name: options.name,
|
|
83
82
|
suffix: 'slice',
|
|
@@ -95,7 +94,7 @@ async function normalizeOptions(host, options) {
|
|
|
95
94
|
const tsPaths = tsConfigJson.compilerOptions
|
|
96
95
|
? tsConfigJson.compilerOptions.paths || {}
|
|
97
96
|
: {};
|
|
98
|
-
const modulePath = (0,
|
|
97
|
+
const modulePath = (0, internal_2.getProjectType)(host, root, projectType) === 'application'
|
|
99
98
|
? options.path
|
|
100
99
|
? `./app/${options.path}/${extraNames.fileName}.slice`
|
|
101
100
|
: `./app/${extraNames.fileName}.slice`
|
|
@@ -110,7 +109,7 @@ async function normalizeOptions(host, options) {
|
|
|
110
109
|
if (appConfig.projectType !== 'application') {
|
|
111
110
|
throw new Error(`Expected ${options.appProject} to be an application but got ${appConfig.projectType}`);
|
|
112
111
|
}
|
|
113
|
-
appProjectSourcePath = (0,
|
|
112
|
+
appProjectSourcePath = (0, internal_2.getProjectSourceRoot)(appConfig, host);
|
|
114
113
|
appMainFilePath = path.join(appProjectSourcePath, options.js ? 'main.js' : 'main.tsx');
|
|
115
114
|
if (!host.exists(appMainFilePath)) {
|
|
116
115
|
throw new Error(`Could not find ${appMainFilePath} during store configuration`);
|
package/src/generators/remote/files/rspack-module-federation-ssr-ts/rspack.config.ts__tmpl__
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NxAppRspackPlugin } from '@nx/rspack/app-plugin.js';
|
|
2
2
|
import { NxReactRspackPlugin } from '@nx/rspack/react-plugin.js';
|
|
3
|
-
import { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } from '@nx/module-federation/rspack
|
|
3
|
+
import { NxModuleFederationPlugin, NxModuleFederationSSRDevServerPlugin } from '@nx/module-federation/rspack';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
|
|
6
6
|
import browserMfConfig from './module-federation.config';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NxAppRspackPlugin } from '@nx/rspack/app-plugin.js';
|
|
2
2
|
import { NxReactRspackPlugin } from '@nx/rspack/react-plugin.js';
|
|
3
|
-
import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack
|
|
3
|
+
import { NxModuleFederationPlugin, NxModuleFederationDevServerPlugin } from '@nx/module-federation/rspack';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
|
|
6
6
|
import config from './module-federation.config';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {composePlugins, withNx} from '@nx/webpack';
|
|
2
2
|
import {withReact} from '@nx/react';
|
|
3
|
-
import {withModuleFederationForSSR} from '@nx/module-federation/webpack
|
|
3
|
+
import {withModuleFederationForSSR} from '@nx/module-federation/webpack';
|
|
4
4
|
|
|
5
5
|
import baseConfig from "./module-federation.server.config";
|
|
6
6
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {composePlugins, withNx} from '@nx/webpack';
|
|
2
2
|
import {withReact} from '@nx/react';
|
|
3
|
-
import {withModuleFederation} from '@nx/module-federation/webpack
|
|
3
|
+
import {withModuleFederation} from '@nx/module-federation/webpack';
|
|
4
4
|
|
|
5
5
|
import baseConfig from './module-federation.config';
|
|
6
6
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupPackageJsonExportsForRemote = setupPackageJsonExportsForRemote;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
6
6
|
const maybe_js_1 = require("../../../utils/maybe-js");
|
|
7
7
|
function setupPackageJsonExportsForRemote(tree, options) {
|
|
8
8
|
const project = (0, devkit_1.readProjectConfiguration)(tree, options.projectName);
|
|
@@ -12,7 +12,7 @@ function setupPackageJsonExportsForRemote(tree, options) {
|
|
|
12
12
|
`TypeScript solution setup requires package.json for all projects.`);
|
|
13
13
|
}
|
|
14
14
|
const exportPath = (0, maybe_js_1.maybeJs)(options, './src/remote-entry.ts');
|
|
15
|
-
const customCondition = (0,
|
|
15
|
+
const customCondition = (0, internal_1.getDefinedCustomConditionName)(tree);
|
|
16
16
|
(0, devkit_1.updateJson)(tree, packageJsonPath, (json) => {
|
|
17
17
|
json.exports = {
|
|
18
18
|
...json.exports,
|
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.updateHostWithRemote = updateHostWithRemote;
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const
|
|
6
|
-
const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
|
|
5
|
+
const internal_1 = require("@nx/js/internal");
|
|
7
6
|
const ast_utils_1 = require("../../../module-federation/ast-utils");
|
|
8
7
|
let tsModule;
|
|
9
8
|
function updateHostWithRemote(host, hostName, remoteName) {
|
|
10
9
|
if (!tsModule) {
|
|
11
|
-
tsModule = (0,
|
|
10
|
+
tsModule = (0, internal_1.ensureTypescript)();
|
|
12
11
|
}
|
|
13
12
|
const hostConfig = (0, devkit_1.readProjectConfiguration)(host, hostName);
|
|
14
13
|
let moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(hostConfig.root, 'module-federation.config.js');
|
|
15
14
|
if (!host.exists(moduleFederationConfigPath)) {
|
|
16
15
|
moduleFederationConfigPath = (0, devkit_1.joinPathFragments)(hostConfig.root, 'module-federation.config.ts');
|
|
17
16
|
}
|
|
18
|
-
const appComponentPath = findAppComponentPath(host, (0,
|
|
17
|
+
const appComponentPath = findAppComponentPath(host, (0, internal_1.getProjectSourceRoot)(hostConfig, host));
|
|
19
18
|
if (host.exists(moduleFederationConfigPath)) {
|
|
20
19
|
// find the host project path
|
|
21
20
|
// Update remotes inside ${host_path}/src/remotes.d.ts
|
|
@@ -36,7 +35,7 @@ function updateHostWithRemote(host, hostName, remoteName) {
|
|
|
36
35
|
devkit_1.logger.warn(`Could not find app component at ${appComponentPath}. Did you generate this project with "@nx/react:host" or "@nx/react:consumer"?`);
|
|
37
36
|
}
|
|
38
37
|
// Add remote as devDependency in TS solution setup
|
|
39
|
-
if ((0,
|
|
38
|
+
if ((0, internal_1.isUsingTsSolutionSetup)(host)) {
|
|
40
39
|
addRemoteAsHostDependency(host, hostName, remoteName);
|
|
41
40
|
}
|
|
42
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/remote/remote.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remote.d.ts","sourceRoot":"","sources":["../../../../../../packages/react/src/generators/remote/remote.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,iBAAiB,EAOjB,IAAI,EAGL,MAAM,YAAY,CAAC;AAoBpB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAOzD,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,gBAAgB,CAAC,MAAM,CAAC,QAmFlC;AAED,wBAAsB,eAAe,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,8BAsK/D;AAED,eAAe,eAAe,CAAC"}
|