Front-end development has grown so much over the last decade from pure HTML and CSS design to topics such as high interactivity, accessibility, testability, and security. In order to meet these needs, most application teams have made distinctions between backend and front-end development teams.
In addition to that, the application functionality grows steadily and, at a certain point, it becomes impractical to have multiple teams collaborate on a single code base.
The term "Micro Front-ends" has been a buzzword for breaking up growing front-end code into easy-to-maintain parts. The front-end is divided into its multiple functions or parts. These parts are implemented and deployed by independent teams. This increases the testability, reusability, and offers the possibility to select different technologies for each micro front-end.
I will stop at this point and, without further ado, let's build sample micro front-ends using Angular elements.
Building Micro Front-Ends
We will build a sample travel booking system in this article. Let's spin up two Angular projects using CLI: travel-booking and flight-booking.
We will need a few dependencies to build and run Angular custom elements. Install the following dependencies inside flight-booking using following commands.
ng add @angular/elements ng add ngx-build-plus
Note: You may need to update the version for the document-register-element module to 1.8.1 in /flight-booking/package.json as described in this issue.
Let us also install the HTTP-server module inside the flight-booking project.
npm i -g http-server --save
Create a component booking in flight-booking/src/app/. Let's modify the component as follows:
flight-booking/src/app/booking/booking.component.html
flight-booking/src/app/booking/booking.component.ts
Let's define the
booking
component as custom element in flight-booking/src/app/app.module.ts.
To build the project in a single JS file, we need to tell angular to use the ngx-build-plus module. Modify flight-booking/angular.json in three places as follows:
Running the Project
Run the following command to build the project into a single JS file.
--output-hashing none
will avoid hashing the file names.--single-bundle true
will bundle all the compiled files into a single JS file.
Start the server.
Similarly, create another custom element,
train-booking
, and run the server with port 8082.Wrapping a Custom Element
Let us include
flight-booking
and train-booking
custom elements in travel-booking app. Modify /travel-booking/index.html as follows.
Here, Angular requires zones. and custom-elements-es5-adapter.js provides custom element support within the browser. We also included main.js from our custom elements.
Modify travel-booking/angular.json to override the default server port.
Running the Main Application
Run the application using
ng serve
. The final application will look like this:Wrapping Up
Using simple examples, this article demonstrates how we can build a micro front-end architecture using Angular elements. I hope you enjoyed my article. Let me know your experiences if you are working with micro front-end architecture.
4 Comments
thank you!web portal development Company
ReplyDeleteWeb Portal development Services
THANK YOU FOR THE INFORMATION
ReplyDeletePLEASE VISIT US
Website development in Bangalore
ReplyDeleteAwesome Article Keep on sharing
Full Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute
Really Nice blog. It will be helpful for those who are unaware about it.Thanks for sharing this blog. If anybody looking to develop mobile apps using latest Technology. I would recommend Webi7 for mobile apps development companies in bangalore
ReplyDelete