29
loading...
This website collects cookies to deliver better user experience
An architectural style where independently deliverable frontend applications are composed into a greater whole.
non-module-federation
mode.site.json
for dependency management in each Fronts app, support for nested micro frontends.micro-frontends
app and non-micro-frontends
app.site.json
to define a micro frontend, similar to a package.json
in Node.js.{
"name": "app1",
"exports": ["./src/bootstrap"],
"dependencies": {
// If version control is enabled,
// here it looks like: `"app2": "1.0.0"`
"app2": "http://localhost:3002/remoteEntry.js"
},
"shared": {
"react": { "singleton": true },
"react-dom": { "singleton": true }
}
}
useApp()
, useWebComponents()
and useIframe()
. It also provides an micro frontend launcher boot()
and a Webpack configuration generator createWebpackConfig()
. With these APIs, you will be able to do micro frontends development quickly and efficiently.app1
is the main entry point and it will depend on app2
.You can follow this article(React without create-react-app Webpack 5) to quickly create app1
and app2
React projects.
fronts-react
and fronts-bundler
in the projects.
# with NPM
npm install fronts-react fronts-bundler
# or with Yarn
yarn add fronts-react fronts-bundler
site.json
and webpack.config.js
in the projectsapp1
as a parent micro frontend and it depends on app2
.app1/site.json
:{
"name": "app1",
"exports": [],
"dependencies": {
"app2": "http://localhost:3002/remoteEntry.js"
}
}
app2
doesn't have any dependencies, it acts as a micro frontend and we define it to export ./src/bootstrap
as a micro frontends entry, this entry of app2
end will be used by app1
.app2/site.json
:{
"name": "app2",
"exports": ["./src/bootstrap"],
"dependencies": {}
}
createWebpackConfig()
in config/webpack.config.js
in the projects.const { createWebpackConfig } = require('fronts-bundler');
module.exports = createWebpackConfig(originalWebpackConfig);
app2/src/bootstrap.jsx
and use boot()
to get it booted.
import React from 'react';
import ReactDOM from 'react-dom';
import { boot } from 'fronts-react';
import App from './App';
export default function render(element) {
ReactDOM.render(<App />, element);
return () => {
ReactDOM.unmountComponentAtNode(element);
};
}
boot(render, document.getElementById('root'));
app1/src/App.jsx
with useApp()
to import app2
.
import React from 'react';
import { useApp } from 'fronts-react';
export const App = () => {
const App2 = useApp({
name: 'app2',
loader: () => import('app2/src/bootstrap'),
});
return <App2 />;
};
yarn start
, and app2
is rendered as a micro frontend on app1
.fronts-react
, fronts-vue
and fronts-ng
, and when it comes to other frameworks not supported by the built-in packages or no framework, then please use fronts
.useApp()
, useWebComponents()
, useIframe()
. useApp()
provides loose CSS isolation, useWebComponents()
provides strict CSS isolation, and useIframe()
provides native strict CSS isolation and JS isolation.SPA=true yarn start
and switch the micro frontends development mode to the traditional SPA development mode.