Skip to content

Commit

Permalink
feat: add Rsbuild module-federation-enhanced example
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan committed Apr 28, 2024
1 parent edf6027 commit a3bbb72
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 26 deletions.
1 change: 1 addition & 0 deletions rsbuild/module-federation-enhanced/consumer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@mf-types
5 changes: 4 additions & 1 deletion rsbuild/module-federation-enhanced/consumer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"devDependencies": {
"@module-federation/enhanced": "^0.1.10",
"@rsbuild/core": "^0.6.0",
"@rsbuild/plugin-react": "^0.6.0"
"@rsbuild/plugin-react": "^0.6.0",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"typescript": "^5.4.5"
}
}
26 changes: 26 additions & 0 deletions rsbuild/module-federation-enhanced/consumer/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
body {
margin: 0;
color: #fff;
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
background-image: linear-gradient(to bottom, #020917, #101725);
}

.content {
display: flex;
min-height: 100vh;
line-height: 1.1;
text-align: center;
flex-direction: column;
justify-content: center;
}

.content h1 {
font-size: 3.6rem;
font-weight: 700;
}

.content p {
font-size: 1.2rem;
font-weight: 400;
opacity: 0.5;
}
11 changes: 0 additions & 11 deletions rsbuild/module-federation-enhanced/consumer/src/bootstrap.js

This file was deleted.

14 changes: 14 additions & 0 deletions rsbuild/module-federation-enhanced/consumer/src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

const container = document.getElementById("root");

if (container) {
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
17 changes: 17 additions & 0 deletions rsbuild/module-federation-enhanced/consumer/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler",
"paths": {
"*": ["./@mf-types/*"]
}
},
"include": ["src"]
}
5 changes: 4 additions & 1 deletion rsbuild/module-federation-enhanced/provider/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"devDependencies": {
"@module-federation/enhanced": "^0.1.10",
"@rsbuild/core": "^0.6.0",
"@rsbuild/plugin-react": "^0.6.0"
"@rsbuild/plugin-react": "^0.6.0",
"@types/react": "^18.3.1",
"@types/react-dom": "^18.3.0",
"typescript": "^5.4.5"
}
}
4 changes: 2 additions & 2 deletions rsbuild/module-federation-enhanced/provider/rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
port: 3000,
},
dev: {
// It is necessary to configure assetPrefix, and in the production environment, you need to configure output.assetPrefix
// It is necessary to configure assetPrefix, and in the production build, you need to configure output.assetPrefix
assetPrefix: "http://localhost:3000",
},
tools: {
Expand All @@ -18,7 +18,7 @@ export default defineConfig({
new ModuleFederationPlugin({
name: "federation_provider",
exposes: {
"./button": "./src/button.jsx",
"./button": "./src/Button.tsx",
},
shared: ["react", "react-dom"],
}),
Expand Down
3 changes: 3 additions & 0 deletions rsbuild/module-federation-enhanced/provider/src/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function Button() {
return <div>Provider button</div>;
}
11 changes: 0 additions & 11 deletions rsbuild/module-federation-enhanced/provider/src/bootstrap.jsx

This file was deleted.

14 changes: 14 additions & 0 deletions rsbuild/module-federation-enhanced/provider/src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

const container = document.getElementById("root");

if (container) {
const root = createRoot(container);
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);
}
14 changes: 14 additions & 0 deletions rsbuild/module-federation-enhanced/provider/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"compilerOptions": {
"target": "ES2020",
"lib": ["DOM", "ES2020"],
"module": "ESNext",
"jsx": "react-jsx",
"strict": true,
"skipLibCheck": true,
"isolatedModules": true,
"resolveJsonModule": true,
"moduleResolution": "bundler"
},
"include": ["src"]
}

0 comments on commit a3bbb72

Please sign in to comment.