SlideShare une entreprise Scribd logo
1  sur  7
Télécharger pour lire hors ligne
How to Build a Micro-Application
using Single-Spa
By,
Shwetha Thomas, Senior Software Engineer
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 2
How to Create a Micro-Application using Single-Spa
Following are the steps to create a micro-application:
● Create an angular application with a unique prefix.
ng new --prefix app1
● Enter the command ng add single-spa-angular in our project which in turn will do the
following:
- Install single-spa-angular
- Generates a main.single-spa.ts in our project src/.
- Generates single-spa-props.ts in src/single-spa/
- Generates asset-url.ts in src/single-spa/
- Generates an EmptyRouteComponent in src/app/empty-route/, to be used in app-
routing.module.ts.
- Add an npm script npm run build:single-spa.
- Add an npm script npm run serve:single-spa.
● Install custom-webpack as dev dependency(npm install -D @angular-builders/custom-
webpack@9.1.0)
● Add providers: [{provide: APP_BASE_HREF, useValue: '/'}] to app-routing.module.ts
● Add {path: '**', component: EmptyRouteComponent} to our app-routing.module.ts routes.
● Add a declaration for EmptyRouteComponent in app.module.ts
● Register the micro-app in the index.html file and call single-spa.start() function.
For example,
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 3
Figure 1: Import single-spa
Here, we are using import maps to set the path for our micro-app. student is the micro app here
which we are registering. Since we are running locally, the localhosturl is given. Once we deploy
the micro app, we can replace local url by giving the deployed url. main.js is a javascript file with the
webpack which is created while running the app. While building the app, main-es2015.js file is
created in the dist folder with the webpack.
Figure 2: Register application
This script tag is given inside the body. Here we are registering the micro-app and then calling the
singleSpa.start(). In this example, the function returns true, which means the app will be loaded by
default. We can also specify a route, so the micro-app will be mounted only on calling the specific
route.
If the function returns, location.pathname.startsWith(‘/student’); student micro-app will be
loaded only on calling /student.
There are some script tags, which is needed on loading micro-apps which are given below:
<script src='https://unpkg.com/core-js-bundle@3.1.4/minified.js'></script>
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 4
<script src="https://unpkg.com/zone.js"></script>
<script src="https://unpkg.com/import-map-overrides@1.6.0/dist/import-map-overrides.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/system.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/amd.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/named-exports.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/named-
register.min.js"></script>
Make sure each micro-app runs in a different port locally.
Serving a Micro-Application
To serve a micro-application, run the following command:
npm run serve:single-spa
For angular version greater than 9, app name will be appended to this command. Check the
package.json to know the exact command.
For example,
npm run serve:single-spa:app
Building a Micro-Application
.To build a micro-application, run the following command:
npm run build:single-spa
For angular version greater than 9, app name will be appended to this command. Check the
package.json to know the exact command.
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 5
For example,
npm run build:single-spa:app
This will create a dist folder.
How to Register the Micro-Apps into the Portal
We can load any number of micro-apps in a single application which is the portal. To create a portal application, we
need an HTML file where we can register our micro-apps and call singleSpa.start().
To register a micro-app into the portal,
● We must specify the main.js path of the micro-app in the portal
● Add the required scripts
● Register the micro-application
● Call singleSpa.start()
Take a look at the images given below for a better understanding.
Figure 1: Specify main.js path
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 6
Figure 2: Register micro-app and call start method
This part is the same as registering a micro-app to itself.
Following the above-mentioned steps ensures that the process of building and registering micro-applications in the
portal is as seamless as possible.
How to Build a Micro-Application using Single-Spa
© RapidValue Solutions 7
About RapidValue
RapidValue is a global leader in providing digital product engineering solutions including Mobility, Cloud,
Omni-channel, IoT and RPA to enterprises worldwide. RapidValue offers its digital services to the world’s
top brands, Fortune 1000 companies, and innovative emerging start-ups. With offices in the United
States, the United Kingdom, Germany, and India and operations spread across the Middle-East, Europe,
and Canada, RapidValue delivers enterprise service and solutions across various industry verticals.
Disclaimer:
This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used,
circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are
hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful.
© RapidValue Solutions
www.rapidvaluesolutions.com/blog
www.rapidvaluesolutions.com
+1 877.643.1850 contactus@rapidvaluesolutions.com

Contenu connexe

Tendances

DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon
 

Tendances (20)

TDD for Microservices
TDD for MicroservicesTDD for Microservices
TDD for Microservices
 
TUTTO SU VISUAL STUDIO ALM 2015
TUTTO SU VISUAL STUDIO ALM 2015TUTTO SU VISUAL STUDIO ALM 2015
TUTTO SU VISUAL STUDIO ALM 2015
 
Extending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud FoundryExtending the Platform with Spring Boot and Cloud Foundry
Extending the Platform with Spring Boot and Cloud Foundry
 
Running Spring Boot in Kubernetes and Intro to Helm
Running Spring Boot in Kubernetes and Intro to HelmRunning Spring Boot in Kubernetes and Intro to Helm
Running Spring Boot in Kubernetes and Intro to Helm
 
Bootiful Azure Spring Cloud
Bootiful Azure Spring CloudBootiful Azure Spring Cloud
Bootiful Azure Spring Cloud
 
Adapt or Die: A Microservices Story at Google
Adapt or Die: A Microservices Story at GoogleAdapt or Die: A Microservices Story at Google
Adapt or Die: A Microservices Story at Google
 
Introduction To Micro Frontends
Introduction To Micro Frontends Introduction To Micro Frontends
Introduction To Micro Frontends
 
Make Spring Home (Spring Customization and Extensibility)
Make Spring Home (Spring Customization and Extensibility)Make Spring Home (Spring Customization and Extensibility)
Make Spring Home (Spring Customization and Extensibility)
 
Santosh Shukla-microservices-java-spring boot
Santosh Shukla-microservices-java-spring bootSantosh Shukla-microservices-java-spring boot
Santosh Shukla-microservices-java-spring boot
 
Firebase
FirebaseFirebase
Firebase
 
BENEFIT OF FLUTTER APP DEVELOPMENT - INFOGRAPHICS
BENEFIT OF FLUTTER APP DEVELOPMENT - INFOGRAPHICSBENEFIT OF FLUTTER APP DEVELOPMENT - INFOGRAPHICS
BENEFIT OF FLUTTER APP DEVELOPMENT - INFOGRAPHICS
 
Pivotal Cloud Foundry et Microsoft: Pourquoi? ... Et pourquoi pas?
 Pivotal Cloud Foundry et Microsoft: Pourquoi? ... Et pourquoi pas? Pivotal Cloud Foundry et Microsoft: Pourquoi? ... Et pourquoi pas?
Pivotal Cloud Foundry et Microsoft: Pourquoi? ... Et pourquoi pas?
 
Breaking Down the Monolith - Peter Marton, RisingStack
Breaking Down the Monolith - Peter Marton, RisingStackBreaking Down the Monolith - Peter Marton, RisingStack
Breaking Down the Monolith - Peter Marton, RisingStack
 
A Starters Guide to Building APIs with Javascript
A Starters Guide to Building APIs with JavascriptA Starters Guide to Building APIs with Javascript
A Starters Guide to Building APIs with Javascript
 
Back your app with MySQL and Redis on Cloud Foundry
Back your app with MySQL and Redis on Cloud FoundryBack your app with MySQL and Redis on Cloud Foundry
Back your app with MySQL and Redis on Cloud Foundry
 
Test Automation Workshop with BDD Approach
Test Automation Workshop with BDD ApproachTest Automation Workshop with BDD Approach
Test Automation Workshop with BDD Approach
 
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
DevSecCon London 2019: Workshop: Cloud Agnostic Security Testing with Scout S...
 
Scaling with Microservices
Scaling with MicroservicesScaling with Microservices
Scaling with Microservices
 
[APIdays INTERFACE 2021] Now that we have K8s, can we stop re-inventing API p...
[APIdays INTERFACE 2021] Now that we have K8s, can we stop re-inventing API p...[APIdays INTERFACE 2021] Now that we have K8s, can we stop re-inventing API p...
[APIdays INTERFACE 2021] Now that we have K8s, can we stop re-inventing API p...
 
Integrate Machine Learning into Your Spring Application in Less than an Hour
Integrate Machine Learning into Your Spring Application in Less than an HourIntegrate Machine Learning into Your Spring Application in Less than an Hour
Integrate Machine Learning into Your Spring Application in Less than an Hour
 

Similaire à How to Build a Micro-Application using Single-Spa

Similaire à How to Build a Micro-Application using Single-Spa (20)

Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
How to implement Micro-frontends using Qiankun
How to implement Micro-frontends using QiankunHow to implement Micro-frontends using Qiankun
How to implement Micro-frontends using Qiankun
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Kraken.js Lab Primer
Kraken.js Lab PrimerKraken.js Lab Primer
Kraken.js Lab Primer
 
How React Native has changed Web and Mobile Application Development, Engineer...
How React Native has changed Web and Mobile Application Development, Engineer...How React Native has changed Web and Mobile Application Development, Engineer...
How React Native has changed Web and Mobile Application Development, Engineer...
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
The web - What it has, what it lacks and where it must go - Bulgaria Web Summ...
 
Mean stack Magics
Mean stack MagicsMean stack Magics
Mean stack Magics
 
The web - What it has, what it lacks and where it must go - Istanbul
The web - What it has, what it lacks and where it must go - IstanbulThe web - What it has, what it lacks and where it must go - Istanbul
The web - What it has, what it lacks and where it must go - Istanbul
 
Meteor
MeteorMeteor
Meteor
 
Web worker in your angular application
Web worker in your angular applicationWeb worker in your angular application
Web worker in your angular application
 
Sam segal resume
Sam segal resumeSam segal resume
Sam segal resume
 
How create react app help in creating a new react applications
How create react app help in creating a new react applications How create react app help in creating a new react applications
How create react app help in creating a new react applications
 
WordCamp Bucharest 2017
WordCamp Bucharest 2017WordCamp Bucharest 2017
WordCamp Bucharest 2017
 
Business Utility Application
Business Utility ApplicationBusiness Utility Application
Business Utility Application
 
Fastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS AppsFastlane - Automation and Continuous Delivery for iOS Apps
Fastlane - Automation and Continuous Delivery for iOS Apps
 
Codename one
Codename oneCodename one
Codename one
 
Django simplified : by weever mbakaya
Django simplified : by weever mbakayaDjango simplified : by weever mbakaya
Django simplified : by weever mbakaya
 
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST FrameworkEasy Step-by-Step Guide to Develop REST APIs with Django REST Framework
Easy Step-by-Step Guide to Develop REST APIs with Django REST Framework
 
The web - What it has, what it lacks and where it must go - keynote at Riga D...
The web - What it has, what it lacks and where it must go - keynote at Riga D...The web - What it has, what it lacks and where it must go - keynote at Riga D...
The web - What it has, what it lacks and where it must go - keynote at Riga D...
 

Plus de RapidValue

The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QA
RapidValue
 

Plus de RapidValue (20)

Play with Jenkins Pipeline
Play with Jenkins PipelinePlay with Jenkins Pipeline
Play with Jenkins Pipeline
 
Accessibility Testing using Axe
Accessibility Testing using AxeAccessibility Testing using Axe
Accessibility Testing using Axe
 
Guide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in KotlinGuide to Generate Extent Report in Kotlin
Guide to Generate Extent Report in Kotlin
 
Automation in Digital Cloud Labs
Automation in Digital Cloud LabsAutomation in Digital Cloud Labs
Automation in Digital Cloud Labs
 
Microservices Architecture - Top Trends & Key Business Benefits
Microservices Architecture -  Top Trends & Key Business BenefitsMicroservices Architecture -  Top Trends & Key Business Benefits
Microservices Architecture - Top Trends & Key Business Benefits
 
Uploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADIUploading Data Using Oracle Web ADI
Uploading Data Using Oracle Web ADI
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Build UI of the Future with React 360
Build UI of the Future with React 360Build UI of the Future with React 360
Build UI of the Future with React 360
 
Python Google Cloud Function with CORS
Python Google Cloud Function with CORSPython Google Cloud Function with CORS
Python Google Cloud Function with CORS
 
Real-time Automation Result in Slack Channel
Real-time Automation Result in Slack ChannelReal-time Automation Result in Slack Channel
Real-time Automation Result in Slack Channel
 
Automation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDDAutomation Testing with KATALON Cucumber BDD
Automation Testing with KATALON Cucumber BDD
 
How to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular FrameworkHow to Implement Micro Frontend Architecture using Angular Framework
How to Implement Micro Frontend Architecture using Angular Framework
 
Video Recording of Selenium Automation Flows
Video Recording of Selenium Automation FlowsVideo Recording of Selenium Automation Flows
Video Recording of Selenium Automation Flows
 
JMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeterJMeter JMX Script Creation via BlazeMeter
JMeter JMX Script Creation via BlazeMeter
 
Migration to Extent Report 4
Migration to Extent Report 4Migration to Extent Report 4
Migration to Extent Report 4
 
The Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QAThe Definitive Guide to Implementing Shift Left Testing in QA
The Definitive Guide to Implementing Shift Left Testing in QA
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
Test Case Creation in Katalon Studio
Test Case Creation in Katalon StudioTest Case Creation in Katalon Studio
Test Case Creation in Katalon Studio
 
How to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using ValgrindHow to Perform Memory Leak Test Using Valgrind
How to Perform Memory Leak Test Using Valgrind
 
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValueDevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
DevOps Continuous Integration & Delivery - A Whitepaper by RapidValue
 

Dernier

The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
shinachiaurasa2
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 

How to Build a Micro-Application using Single-Spa

  • 1. How to Build a Micro-Application using Single-Spa By, Shwetha Thomas, Senior Software Engineer
  • 2. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 2 How to Create a Micro-Application using Single-Spa Following are the steps to create a micro-application: ● Create an angular application with a unique prefix. ng new --prefix app1 ● Enter the command ng add single-spa-angular in our project which in turn will do the following: - Install single-spa-angular - Generates a main.single-spa.ts in our project src/. - Generates single-spa-props.ts in src/single-spa/ - Generates asset-url.ts in src/single-spa/ - Generates an EmptyRouteComponent in src/app/empty-route/, to be used in app- routing.module.ts. - Add an npm script npm run build:single-spa. - Add an npm script npm run serve:single-spa. ● Install custom-webpack as dev dependency(npm install -D @angular-builders/custom- webpack@9.1.0) ● Add providers: [{provide: APP_BASE_HREF, useValue: '/'}] to app-routing.module.ts ● Add {path: '**', component: EmptyRouteComponent} to our app-routing.module.ts routes. ● Add a declaration for EmptyRouteComponent in app.module.ts ● Register the micro-app in the index.html file and call single-spa.start() function. For example,
  • 3. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 3 Figure 1: Import single-spa Here, we are using import maps to set the path for our micro-app. student is the micro app here which we are registering. Since we are running locally, the localhosturl is given. Once we deploy the micro app, we can replace local url by giving the deployed url. main.js is a javascript file with the webpack which is created while running the app. While building the app, main-es2015.js file is created in the dist folder with the webpack. Figure 2: Register application This script tag is given inside the body. Here we are registering the micro-app and then calling the singleSpa.start(). In this example, the function returns true, which means the app will be loaded by default. We can also specify a route, so the micro-app will be mounted only on calling the specific route. If the function returns, location.pathname.startsWith(‘/student’); student micro-app will be loaded only on calling /student. There are some script tags, which is needed on loading micro-apps which are given below: <script src='https://unpkg.com/core-js-bundle@3.1.4/minified.js'></script>
  • 4. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 4 <script src="https://unpkg.com/zone.js"></script> <script src="https://unpkg.com/import-map-overrides@1.6.0/dist/import-map-overrides.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/system.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/amd.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/named-exports.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/4.0.0/extras/named- register.min.js"></script> Make sure each micro-app runs in a different port locally. Serving a Micro-Application To serve a micro-application, run the following command: npm run serve:single-spa For angular version greater than 9, app name will be appended to this command. Check the package.json to know the exact command. For example, npm run serve:single-spa:app Building a Micro-Application .To build a micro-application, run the following command: npm run build:single-spa For angular version greater than 9, app name will be appended to this command. Check the package.json to know the exact command.
  • 5. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 5 For example, npm run build:single-spa:app This will create a dist folder. How to Register the Micro-Apps into the Portal We can load any number of micro-apps in a single application which is the portal. To create a portal application, we need an HTML file where we can register our micro-apps and call singleSpa.start(). To register a micro-app into the portal, ● We must specify the main.js path of the micro-app in the portal ● Add the required scripts ● Register the micro-application ● Call singleSpa.start() Take a look at the images given below for a better understanding. Figure 1: Specify main.js path
  • 6. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 6 Figure 2: Register micro-app and call start method This part is the same as registering a micro-app to itself. Following the above-mentioned steps ensures that the process of building and registering micro-applications in the portal is as seamless as possible.
  • 7. How to Build a Micro-Application using Single-Spa © RapidValue Solutions 7 About RapidValue RapidValue is a global leader in providing digital product engineering solutions including Mobility, Cloud, Omni-channel, IoT and RPA to enterprises worldwide. RapidValue offers its digital services to the world’s top brands, Fortune 1000 companies, and innovative emerging start-ups. With offices in the United States, the United Kingdom, Germany, and India and operations spread across the Middle-East, Europe, and Canada, RapidValue delivers enterprise service and solutions across various industry verticals. Disclaimer: This document contains information that is confidential and proprietary to RapidValue Solutions Inc. No part of it may be used, circulated, quoted, or reproduced for distribution outside RapidValue. If you are not the intended recipient of this report, you are hereby notified that the use, circulation, quoting, or reproducing of this report is strictly prohibited and may be unlawful. © RapidValue Solutions www.rapidvaluesolutions.com/blog www.rapidvaluesolutions.com +1 877.643.1850 contactus@rapidvaluesolutions.com