
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
react-micro-frontend-example
Advanced tools
For those of you don’t who know what a micro frontend is – a micro frontend is an architecture in which the UI is decomposed into individual, loosely coupled components that can be built, tested, and deployed independently. A parallel is the microservices architecture, where the backend is divided into individual services.
The approach I am taking is aimed at doing what is best for the UI, and focused on productivity. What do I mean by that? Well, one of the key benefits of microservices is they can be written in any language and hosted independently. For a UI this is not necessarily a great, for two reasons.
The approach I am promoting is to divide the application into components, that are developed, tested and published independently. The components are then incorporated back into an app before the app is deployed.
When setup correctly, the approach adds little terms of overhead and has almost all the benefits of the micro frontend architecture, combined with the benefits of JavaScript.
In practical terms the approach involve creating a component for every page or content panel. For example, a typically application would have a menu bar, in which each option loads a separate page. In the approach, each of these pages would be a separate component. The menu and all general functionality would remain in the app.
The approach has the following benefits
The structure of the project would look as follows-

The structure may look like a mono repo, but that is only because the above is an example. In an actual project, the app and components would be separate repos.
When breaking out elements of a UI into separate components, there is a great deal less to think about than if they were to be hosted independently. There are still a few things to consider, and below is a list the main points.
One of the benefits of not hosting the component independently, is the ability to leverage style from the parent. In my opinion, the best way to achieve this, is to give each component its own stylesheets and to drive the stylesheets from variables. This will allow the component to be developed independently, while at the same time, allowing the look and feel to be controlled form the parent.
{
--color: white;
--backgroundColor: black;
--fontSize: small;
}
.element {
color: var(--color);
background-color: var(--backgroundColor);
font-size: var(--fontSize);
}
Tackling style like this also allows easy retheming, as the variables can be updated dynamically.
All shared dependencies should be peer and dev dependencies. By making them peer and dev dependencies, it will be easier to control the versioning and will simplify things when it comes to upgrading.
"peerDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"dependency": "^1.0.1"
},
"devDependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0",
"dependency": "^1.0.1"
}
To publishing the components, rollup is recomended. Rollup has numerous averages over webpack for component publications - simple configuration, better tree shaking and minimum size bundles.
Publishing components to visualise changes is not ideal. Apart from slowing down development, it also results in unnecessary versions. To overcome this problem, there is a handy library called relative-deps.
Relative-deps adds a link to the component in the app. Then, when it comes to building the app, relative-deps will build the component and copy the distribution files to the node_modules directory.
Just a note, when using relative-deps, the version number of the component must be incremented to see the local changes.
The components should be tested in isolation. In a multi repo approach, the tests can be run in the same pipeline that publishes the component.
The application should be considerably smaller and only consist of a frame, menu and any authentical calls. As I mentioned earlier, Relative-deps should be used in the app to load local changes before they are published.
A working example can be seen here
The code is available here
FAQs
React Micro frontend example
We found that react-micro-frontend-example demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.