Micro-frontend architectures decompose a front-end app into individual, semi-independent “microapps” working loosely together. This can help make large projects more manageable, e.g. when transitioning from legacy codebases.
in the root
- run
npm install
which will be installing all project dependencies - run
npm start
which will be starting all projects - open browser and browse
http://localhost:9000
orhttp://localhost:9900
( There are two different root projectsroot-config
which is EJS template androot-config-html
which is pure js and html )
- backend: [NestJs] : Serving backend for all projects, in reality there should be micro-services
- root-config [EJS Template] : Serving as shell to host all micro-frontend apps
- root-config-html [JS and Html] : Serving as shell to host all micro-frontend apps
- home [React] : A home page, that doesn't need any authentication and is the default app
- nav-bar [React] : Display Navbar on top of the app
- auth [Angular] : Angular app for login (and create new user, forget password in future)
- product [React] : Show the list and details of products
- sales [Angular] : Show the list and details of sales
- run
npx create-single-spa
(or you can installcreate-single-spa
globally) - follow the prompts (for apps choose application/parcel)
- apply below changes based on the framework you chose
- in the react app update
start
script and add--port 9xxx
to it - in the root-config project update
pc-root-config.ts
file and add the new app there - in the root-config project update
microfrontend-layout.html
file and add the new app there
- make sure you add below code to your app-routing.module.ts
providers: [
{ provide: APP_BASE_HREF, useValue: '/REPLACE-WITH-YOUR-ROUTE' }
]
- find and replace all
app-root
toxxx-app-root
which xxx is name of your app
- update package.json file and change
prepare
to"prepare": "cd .. && husky install",
npm i devextreme devextreme-react react-router-dom
npm i @types/react-router-dom typescript@4.7 -D
- update
webpack.config.js
and add below code to it
module: {
rules: [
{
test: /\.(png|gif|woff|woff2|eot|ttf|svg)$/,
loader: 'url-loader',
},
],
},
npm i url-loader
- add
AuthGuardedRoute
(like product app)
npm i devextreme devextreme-angular @ngneat/until-destroy
- update
body
in theindex.html
to<body class="dx-viewport">
- add
"node_modules/devextreme/dist/css/dx.material.orange.light.css",
to bothstyles
sections inangular.json
- add a new script in
package.json
as"serve": "ng serve",
and update your existing start command to"start": "npm run serve:single-spa:xxx",
which xxx is name of your app - comment out
import 'zone.js';
in thepolyfills.ts
- add session service and auth guard (like sales app)
- deploy to production
- creating in-browser utility modules for style guide
https://medium.com/swlh/developing-and-deploying-micro-frontends-with-single-spa-c8b49f2a1b1d https://blog.bitsrc.io/building-microfrontends-using-single-spa-framework-94019ca2fb4d
https://github.com/joeldenning/coexisting-angular-microfrontends