Skip to content

Commit f777710

Browse files
authored
feat(rsbuild-plugin): support generate MF SSR in Rslib (#3804)
1 parent c343589 commit f777710

File tree

58 files changed

+1577
-1896
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1577
-1896
lines changed

.changeset/violet-boxes-happen.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/rsbuild-plugin': patch
3+
---
4+
5+
feat(rsbuild-plugin): support generate MF SSR in Rslib

apps/modernjs-ssr/dynamic-nested-remote/@mf-types/dynamic_remote/Image.d.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

apps/modernjs-ssr/dynamic-nested-remote/src/components/Content.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ registerRemotes([
1717
]);
1818

1919
const RemoteSSRComponent = createRemoteSSRComponent({
20-
loader: () => loadRemote('dynamic_remote/Image'),
20+
loader: () => loadRemote('dynamic_remote'),
2121
loading: 'loading...',
2222
fallback: ({ error }) => {
2323
if (error instanceof Error && error.message.includes('not exist')) {

apps/modernjs-ssr/dynamic-remote-new-version/module-federation.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { createModuleFederationConfig } from '@module-federation/modern-js';
22
export default createModuleFederationConfig({
33
name: 'dynamic_remote',
44
exposes: {
5-
'./Image': './src/components/Image.tsx',
5+
'.': './src/components/Image.tsx',
66
},
77
shared: {
88
react: { singleton: true },

apps/modernjs-ssr/dynamic-remote/.npmrc

Lines changed: 0 additions & 1 deletion
This file was deleted.

apps/modernjs-ssr/dynamic-remote/CHANGELOG.md

Lines changed: 0 additions & 159 deletions
This file was deleted.

apps/modernjs-ssr/dynamic-remote/modern.config.ts

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/modernjs-ssr/dynamic-remote/module-federation.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default createModuleFederationConfig({
33
name: 'dynamic_remote',
44
filename: 'remoteEntry.js',
55
exposes: {
6-
'./Image': './src/components/Image.tsx',
6+
'.': './src/Index.tsx',
77
},
88
shared: {
99
react: { singleton: true },
Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,23 @@
11
{
22
"name": "modernjs-ssr-dynamic-remote",
33
"private": true,
4-
"version": "0.1.34",
54
"scripts": {
6-
"reset": "npx rimraf ./**/node_modules",
7-
"dev": "modern dev",
8-
"build": "modern build",
9-
"start": "FEDERATION_DEBUG=true modern start",
10-
"serve": "modern serve",
11-
"new": "modern new",
12-
"lint": "modern lint",
13-
"upgrade": "modern upgrade"
14-
},
15-
"engines": {
16-
"node": ">=16.18.1"
17-
},
18-
"lint-staged": {
19-
"*.{js,jsx,ts,tsx,mjs,cjs}": [
20-
"node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
21-
]
22-
},
23-
"eslintIgnore": [
24-
"node_modules/",
25-
"dist/"
26-
],
27-
"dependencies": {
28-
"@babel/runtime": "7.26.0",
29-
"@modern-js/runtime": "2.67.6",
30-
"@module-federation/modern-js": "workspace:*",
31-
"antd": "4.24.15",
32-
"react": "~18.3.1",
33-
"react-dom": "~18.3.1"
5+
"build": "rslib build",
6+
"serve": "rslib mf-dev",
7+
"dev": "rslib mf-dev",
8+
"storybook": "storybook dev -p 6006"
349
},
10+
"main": "./dist/cjs/index.js",
11+
"module": "./dist/esm/index.mjs",
12+
"types": "./dist/cjs/index.d.ts",
3513
"devDependencies": {
36-
"@modern-js-app/eslint-config": "2.59.0",
37-
"@modern-js/app-tools": "2.67.6",
38-
"@modern-js/eslint-config": "2.59.0",
39-
"@modern-js/tsconfig": "2.67.6",
40-
"@types/jest": "~29.5.0",
41-
"@types/node": "~16.11.7",
42-
"@types/react": "~18.2.0",
43-
"@types/react-dom": "~18.3.0",
44-
"lint-staged": "~13.1.0",
45-
"prettier": "~3.3.3",
46-
"rimraf": "~6.0.1",
47-
"typescript": "~5.0.4"
14+
"@module-federation/enhanced": "workspace:*",
15+
"@module-federation/rsbuild-plugin": "workspace:*",
16+
"@rsbuild/plugin-react": "^1.3.1",
17+
"@rslib/core": "^0.9.0",
18+
"@types/react": "^18.3.11",
19+
"http-server": "^14.1.1",
20+
"react": "^18.3.1",
21+
"react-dom": "^18.3.1"
4822
}
4923
}

apps/modernjs-ssr/dynamic-remote/project.json

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,7 @@
88
"build": {
99
"executor": "nx:run-commands",
1010
"options": {
11-
"dependsOn": [
12-
{
13-
"target": "build",
14-
"dependencies": true
15-
}
16-
],
17-
"commands": [
18-
{
19-
"command": "cd apps/modernjs-ssr/dynamic-remote; pnpm run build",
20-
"forwardAllArgs": true
21-
}
22-
]
11+
"commands": ["cd apps/modernjs-ssr/dynamic-remote; pnpm run build"]
2312
}
2413
},
2514
"serve": {
@@ -39,6 +28,18 @@
3928
]
4029
}
4130
},
31+
"dev": {
32+
"executor": "nx:run-commands",
33+
"options": {
34+
"commands": ["cd apps/modernjs-ssr/dynamic-remote; pnpm run dev"]
35+
},
36+
"dependsOn": [
37+
{
38+
"target": "build",
39+
"dependencies": true
40+
}
41+
]
42+
},
4243
"e2e": {
4344
"executor": "@nx/cypress:cypress",
4445
"options": {
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { pluginModuleFederation } from '@module-federation/rsbuild-plugin';
2+
import { pluginReact } from '@rsbuild/plugin-react';
3+
import { defineConfig } from '@rslib/core';
4+
import mfConfig from './module-federation.config';
5+
6+
const shared = {
7+
dts: {
8+
bundle: false,
9+
},
10+
};
11+
12+
export default defineConfig({
13+
output: {
14+
cleanDistPath: true,
15+
},
16+
lib: [
17+
{
18+
...shared,
19+
format: 'esm',
20+
output: {
21+
distPath: {
22+
root: './dist/esm',
23+
},
24+
},
25+
},
26+
{
27+
...shared,
28+
format: 'cjs',
29+
output: {
30+
distPath: {
31+
root: './dist/cjs',
32+
},
33+
},
34+
},
35+
{
36+
...shared,
37+
format: 'mf',
38+
output: {
39+
distPath: {
40+
root: './dist/mf',
41+
},
42+
},
43+
},
44+
],
45+
server: {
46+
port: 3053,
47+
},
48+
plugins: [pluginReact(), pluginModuleFederation(mfConfig, { ssr: true })],
49+
});

apps/modernjs-ssr/dynamic-remote/src/.eslintrc.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

apps/modernjs-ssr/dynamic-remote/src/components/Image.tsx renamed to apps/modernjs-ssr/dynamic-remote/src/Index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import Button from 'antd/lib/button';
3-
import mfSvg from '../assets/module-federation.svg';
43
import stuff from './stuff.module.css';
54

65
export default ({ text }: { text: string }): JSX.Element => (

apps/modernjs-ssr/dynamic-remote/src/modern-app-env.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)