Skip to content

Commit a3e5705

Browse files
authored
feat: shared-directory (#4300)
* feat: shared-directory * Delete shared-directory/vite-remote/.__mf__temp/_mf_0_namespace_mf_1_viteViteRemote/localSharedImportMap.js * Update package.json * delete pic
1 parent 476e82a commit a3e5705

File tree

23 files changed

+7378
-6204
lines changed

23 files changed

+7378
-6204
lines changed

pnpm-lock.yaml

Lines changed: 7011 additions & 6204 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

shared-directory/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# React host and remote
2+
3+
## Getting started
4+
5+
From this directory execute:
6+
7+
- npm run install:deps
8+
- npm run dev
9+
- npm run preview
10+
11+
### host
12+
http://localhost:5172/
13+
14+
### remote
15+
http://localhost:5176/
16+
17+
Open your browser at http://localhost:5172/ to see the amazing result
18+
19+
![alt text](image.png)

shared-directory/image.png

25.3 KB
Loading

shared-directory/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "module-federation-vite-react",
3+
"version": "1.0.0",
4+
"description": "Module Federation Vite + React is now possible",
5+
"scripts": {
6+
"install:deps": "pnpm --filter shared-directory-* install",
7+
"postinstall:deps": "pnpm --filter shared-directory-* run build",
8+
"dev": "pnpm --filter shared-directory-* dev",
9+
"build": "pnpm --filter shared-directory-* build",
10+
"preview": "pnpm --filter shared-directory-* preview"
11+
},
12+
"license": "ISC"
13+
}

shared-directory/rust-host/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rsbuild Project
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
pnpm install
9+
```
10+
11+
## Get Started
12+
13+
Start the dev server:
14+
15+
```bash
16+
pnpm dev
17+
```
18+
19+
Build the app for production:
20+
21+
```bash
22+
pnpm build
23+
```
24+
25+
Preview the production build locally:
26+
27+
```bash
28+
pnpm preview
29+
```
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "shared-directory-rust-host",
3+
"version": "1.0.0",
4+
"scripts": {
5+
"dev": "rsbuild dev",
6+
"build": "rsbuild build",
7+
"preview": "npm run build && rsbuild preview"
8+
},
9+
"dependencies": {
10+
"@module-federation/enhanced": "0.2.5",
11+
"@module-federation/runtime": "^0.6.13",
12+
"antd": "^5.16.2",
13+
"react": "^18.2.0",
14+
"react-dom": "^18.2.0",
15+
"react-router-dom": "^6.22.3",
16+
"vue": "^3.4.29"
17+
},
18+
"devDependencies": {
19+
"@rsbuild/core": "0.7.10",
20+
"@rsbuild/plugin-react": "0.7.10",
21+
"@types/react": "18.3.3",
22+
"@types/react-dom": "18.3.0",
23+
"typescript": "5.5.3"
24+
}
25+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
2+
import { defineConfig } from '@rsbuild/core';
3+
import { pluginReact } from '@rsbuild/plugin-react';
4+
5+
export default defineConfig({
6+
server: {
7+
port: 5172,
8+
open: true,
9+
},
10+
dev: {
11+
// It is necessary to configure assetPrefix, and in the production environment, you need to configure output.assetPrefix
12+
assetPrefix: 'http://localhost:5172',
13+
},
14+
tools: {
15+
rspack: (config, { appendPlugins }) => {
16+
config.output!.uniqueName = 'examples_rust';
17+
appendPlugins([
18+
new ModuleFederationPlugin({
19+
name: 'examples_rust',
20+
remotes: {
21+
viteRemote: 'viteRemote@http://localhost:5176/mf-manifest.json',
22+
shared: 'shared@https://shared.js',
23+
},
24+
implementation: require.resolve('@module-federation/runtime'),
25+
runtimePlugins: ['./src/shared/plugin'],
26+
}),
27+
]);
28+
},
29+
},
30+
plugins: [
31+
pluginReact({
32+
splitChunks: {
33+
react: false,
34+
router: false,
35+
},
36+
}),
37+
],
38+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import file1Default from "shared/dir1/file1";
4+
import {A} from "shared/file2";
5+
import ViteApp from "viteRemote/App1"
6+
7+
//@ts-ignore
8+
const root = ReactDOM.createRoot(document.getElementById('root')!);
9+
root.render(
10+
<React.StrictMode>
11+
<div style={{ background: 'yellow', padding: 30 }}>
12+
host:
13+
<br />
14+
shared/{file1Default}
15+
<br />
16+
shared/file2{A}
17+
</div>
18+
<hr />
19+
<ViteApp />
20+
</React.StrictMode>
21+
);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@rsbuild/core/types" />
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import('./bootstrap');

0 commit comments

Comments
 (0)