These days front-end development has become a new buzzword across the web development industry. It has progressed from pure HTML and CSS design to high interactive apps, better accessibility, testability, and security. Therefore, developers have divided the coding work into front-end and back-end development to meet the changing trend in the app development process. Moreover, the application functionality proliferates, and at some point, it becomes unfeasible when it comes to team up with multiple developers on a single code base. That’s the reason the term “Micro front ends” has become prominent, which allows you to break up the front-end code into easy-to-maintain parts.
In this Micro Frontend Angular Tutorial, we will learn about Micro frontend and how to implement it with the help of the Micro Frontend Angular example.
Table of Contents
What is Micro Frontend?
Micro Frontend can be defined as a design approach of splitting the large application into multiple small frontend applications for making the development process simpler. Projects are of different types, sizes, and requirements. If the project consists of 4-5 pages then a single team can handle the project. But that’s not the case every time. Sometimes your app can be the part of another complex and large app consisting lots of features and functionalities to be implemented by the different developer teams. Thus
various teams can work simultaneously on a complex project with the help of a single frontend codebase. Micro Frontend provides accuracy in developing and deploying enterprise-level applications without much hustle.
Moving ahead in Micro Frontend Angular Tutorial.
Advantages of Micro Frontends
Let’s see what are the advantages of Micro Frontends:
- Small and Independent applications
- Easy to implement and understand the applications
- Easy development and deployment of applications
- Easier to test the apps.
- Faster and smooth application development
- Easy CI/CD
- No codebase sharing
- Can easily modify the structure, architecture, and code of the application
How to Split Application into Micro Frontends?
Moving further in the micro frontend Angular tutorial, we will now learn how to divide large Angular app into various Angular micro frontends. There are no particular rules or approaches of splitting the app. We can divide it according to the project’s needs. Let’s discuss the possible ways.
Based on Feature
Assume your app consists of three features – Dashboard, Profile, Admin.
So, you can separate the applications based on the features. This is the most straight-forward approach. You can make an individual app separating the app by these features and manage its mounting/unmounting with the help of parent application, say Main.js.
Based on Domain
Assume your app consists of three main domains – User, Admin, and Payment. You can split the application based on User domain, Admin domain, and Payment domain which consists independent features and functionalities of respective domain. And then again you can mount/unmount with the help of parent application.
Based on Page
Assume your app consists of three pages – Page 1, Page 2, and Page 3. You can divide the application based on pages. The app would have individual pages having their respective functionalities. And just like the above approaches, you can mount/unmount these separate small apps with the help of parent application.
So, enough of the theory. It’s time to build a demo for Micro Frontend Angular.
Micro Frontend Angular Example: Steps to Build Micro Frontend
Now let’s proceed with the steps that one should use to build micro front-end for angular app development and how are micro frontends implemented. We’ll give you a brief explanation of the development process by developing two apps using micro front-ends, which are travel booking and bus booking:
Step 1– Whenever you build an app, you will require a few dependencies to develop and run the Angular custom elements. You can then install the following dependencies within bus booking by using below-mentioned commands:
These dependencies can be installed through npm. @angular/elements. This provides external support for Angular element that is the significant extension of Angular CLI.
Note: You should update the version for the document-register-element module to 1.8.1 in bus booking/ package.json.
Step 2– Now, you should also install the HTTP-server module within the bus booking example:
Step 3– All the angular app developers should now create a component, which is booking in bus booking/ src/app. Further, you can modify these components as you want, and we’ve done some changes, which are mentioned below:
As per the above-mention image, your command should be bus/src/booking/booking.component.html
Here the code used is: bus-booking/ src/app/booking/booking-components.ts
Step 4– Next move is all about defining a booking component as a custom element in bus-booking/src/app/.modules.ts
If you want to develop the app in a single JS file, you should inform the angular and ask them to use the ngx-build-plus module. Modify the code bus-booking/angular.json in three places, which are as follows:
Step 5– Running the project:
For building the app in one JS file, you need to follow the below-mentioned commands:
- With output hashing, you find no more hashes in the files name.
- On the other hand, a single bundle true will combine all the files into a single JS file.
For starting the server, below mentioned command:
In the same way, you should create another custom element, which is a train booking and then run the server with port 8082.
Step 6– Covering up a custom element
Let’s add custom elements of train booking and bus booking in the travel-booking app. You should modify this /travel-booking/index.html accordingly:
In this, Angular need zones, and custom-elements-es5-adapter.js offer support to a custom element within the browser. We also used main.js for custom elements. To dominate the default server port, modify travel-booking/angular.json, which showed in the image:
Now run the application using ng.serve, and your app is all set to launch!
As the micro frontends provide the advantage of maintainability, technology liberty, and easy deployment, here are some crucial factors that should be considered for successful implementation:
- Perform more in-depth analysis to break the application modules logically.
- The interface should be interactive, and messages contract to communication between micro applications
- All the micro applications have self-contained features
- Prepare a test strategy for each micro integration point
- Remember, communication is the key that enables teams to communicate properly on one project.
Looking To Partner With Trusted Angular App Development Company?
If you’re in search of a trusted angular app development company, then get in touch with us today. We at, Bacancy Technologies have been offering AngularJS development services, since its initial release. Hire AngularJS Developer from Bacancy Technology to get cost-effective and efficient offshore web and mobile application development services. For more, put forward your quote here or mail us your requirement at www.bacancytechnology.com.