Creating React Remote Microfrontend Component
Rany ElHousieny, PhD???
Generative AI ENGINEERING MANAGER | ex-Microsoft | AI Solutions Architect | Generative AI & NLP Expert | Proven Leader in AI-Driven Innovation | Former Microsoft Research & Azure AI | Software Engineering Manager
In this article, I will break down the process of creating a React button component and configuring it as a Module Federation remote.
Project Setup
Create a new React project:
npx create-mf-app
Install dependencies:
cd react-remote
npm install
Component Creation
Create the button component:
Make a new file named Button.jsx in the src directory:
import React from 'react';
const Button = () => (
<button>MFE1 Button</button>
);
export default Button;
Add the Button to App.jsx
import Button from './Button';
function App() {
return (
<div ....
....
<Button />
</div>
);
}
export default App;
When you start the app, you should see the following:
Module Federation Configuration
Create a webpack configuration file:
exposes: {'./Button':'./src/Button',},
Understanding the Webpack Configuration
Build and Serve
Build your React remote:
npm run build
Start a development server:
npm start
Frontend developer
1 个月But why do you add in remotes link to react app button , if you use loadRemoteModule it works even without adding link to react app in webpack ??
for this approch how we can access angular service into react