<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: AbdelRahman Hussein Mahmoud</title>
    <description>The latest articles on Forem by AbdelRahman Hussein Mahmoud (@abdelrahman_hussein).</description>
    <link>https://forem.com/abdelrahman_hussein</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F360416%2F7ef6da6f-783e-4714-84f3-c7b6f0e76dcf.jpeg</url>
      <title>Forem: AbdelRahman Hussein Mahmoud</title>
      <link>https://forem.com/abdelrahman_hussein</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abdelrahman_hussein"/>
    <language>en</language>
    <item>
      <title>From Monolithic To Micro Frontends - Part 3</title>
      <dc:creator>AbdelRahman Hussein Mahmoud</dc:creator>
      <pubDate>Fri, 15 Jan 2021 17:35:06 +0000</pubDate>
      <link>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-part-3-4jfe</link>
      <guid>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-part-3-4jfe</guid>
      <description>&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Prerequisites&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Application Registration&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;index.html&lt;/li&gt;
&lt;li&gt;index.js&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Start The Application&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Conclusion&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This will be the last part of the series and, we will see how can we register our &lt;strong&gt;Angular&lt;/strong&gt; application inside our &lt;strong&gt;React&lt;/strong&gt; application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Inside your &lt;strong&gt;Angular&lt;/strong&gt; application open &lt;strong&gt;main.single-spa.ts&lt;/strong&gt; file, and insert this line of code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;zone.js/dist/zone.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Run your &lt;strong&gt;Angular&lt;/strong&gt; application
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run serve:single-spa:angular-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And now you should have your &lt;strong&gt;Angular&lt;/strong&gt; application running and its &lt;strong&gt;main.js&lt;/strong&gt; file serving using this URL: &lt;a href="http://localhost:4200/main.js"&gt;http://localhost:4200/main.js&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Application Registration &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;To register your &lt;strong&gt;Angular&lt;/strong&gt; application you will need to use &lt;strong&gt;systemjs&lt;/strong&gt; to load your &lt;strong&gt;Angular&lt;/strong&gt; application module from the URL&lt;/p&gt;

&lt;p&gt;Note: if you used &lt;strong&gt;systemjs&lt;/strong&gt; directly to import your module inside your &lt;strong&gt;React&lt;/strong&gt; application you might face this error&lt;br&gt;
&lt;strong&gt;'System.import' is restricted from being used. Please use import()&lt;/strong&gt;, so we will use a workaround to register the application.&lt;/p&gt;
&lt;h3&gt;
  
  
  index.html &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;strong&gt;index.html&lt;/strong&gt; inside the public folder, and add these scripts which are responsible to load &lt;strong&gt;systemjs&lt;/strong&gt; library
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/import-map-overrides@1.16.0/dist/import-map-overrides.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/systemjs@6.4.0/dist/system.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/systemjs@6.4.0/dist/extras/amd.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://cdn.jsdelivr.net/npm/systemjs@6.4.0/dist/extras/named-exports.min.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create our import map JSON object, which will contain a key value for our &lt;strong&gt;Angular&lt;/strong&gt; application the key will be a unique name and the value will be the URL of the module, and also will contain the shared dependencies, read more about it from &lt;a href="https://single-spa.js.org/docs/getting-started-overview/#add-shared-dependencies"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"systemjs-importmap"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;imports&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;single-spa&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.jsdelivr.net/npm/single-spa@5.5.5/lib/system/single-spa.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.jsdelivr.net/npm/react@16.13.1/umd/react.production.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;react-dom&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://cdn.jsdelivr.net/npm/react-dom@16.13.1/umd/react-dom.production.min.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angularApp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;http://localhost:4200/main.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create a new script tag and inside it, we will define our function which will be used to load our &lt;strong&gt;Angular&lt;/strong&gt; application module
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
   &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angularApp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angularApp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The final result for &lt;strong&gt;index.html&lt;/strong&gt; should be like this&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h3&gt;
  
  
  index.js &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Open &lt;strong&gt;index.js&lt;/strong&gt; file inside your &lt;strong&gt;React&lt;/strong&gt; application and, add this snippet to register your application before &lt;code&gt;start()&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;registerApplication&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angularApp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@angularApp&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The final result for &lt;strong&gt;index.js&lt;/strong&gt; should be like this&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;h2&gt;
  
  
  Start The Application &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Now run your &lt;strong&gt;React&lt;/strong&gt; application using the same script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and your application should be started and working fine, you can access it using this URL: &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt;.&lt;br&gt;
Now the two applications are running on the same page. you can control when to load or unload the application from the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model/Introduction"&gt;DOM&lt;/a&gt; by implementing the activity function inside &lt;code&gt;registerApplication&lt;/code&gt; for more info check the &lt;a href="https://single-spa.js.org/docs/configuration"&gt;documentation&lt;/a&gt;, in my case, I want to run the two applications on the same page, so I just returned &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;Alright, that is all for now, and I hope it was useful for you. You should now have a basic knowledge of what is &lt;strong&gt;micro frontends&lt;/strong&gt; and how &lt;strong&gt;single-spa&lt;/strong&gt; managed it. Also, I will leave below some references you can get back to it anytime.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A complete working demo in this Github [Repo]. (&lt;a href="https://github.com/Abdelrahman-H-Mahmoud/single-spa-demo"&gt;https://github.com/Abdelrahman-H-Mahmoud/single-spa-demo&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Micro frontends architecture &lt;a href="https://martinfowler.com/articles/micro-frontends.html"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;single-spa &lt;a href="https://single-spa.js.org/docs/getting-started-overview"&gt;documentation&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>From Monolithic To Micro Frontends - Part 2</title>
      <dc:creator>AbdelRahman Hussein Mahmoud</dc:creator>
      <pubDate>Fri, 08 Jan 2021 15:27:51 +0000</pubDate>
      <link>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-part-2-3oa0</link>
      <guid>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-part-2-3oa0</guid>
      <description>&lt;h2&gt;
  
  
  Table Of Contents
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Migrating React Application&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Migrate to single-spa application&lt;/li&gt;
&lt;li&gt;Configure Root Config&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Migrating Angular Application&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Migrating React Application &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;To migrate any existing &lt;strong&gt;React&lt;/strong&gt; application I followed this &lt;a href="https://single-spa.js.org/docs/4.x/migrating-react-tutorial/"&gt;documentation&lt;/a&gt; from &lt;a href="https://single-spa.js.org/"&gt;single-spa&lt;/a&gt; and also You can find a complete working solution in this GitHub &lt;a href="https://github.com/Abdelrahman-H-Mahmoud/single-spa-demo"&gt;repo&lt;/a&gt;.&lt;br&gt;
I am assuming you already have an existing React application.&lt;/p&gt;
&lt;h3&gt;
  
  
  Migrate to single-spa application &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Inside your React root folder application, install &lt;a href="https://www.npmjs.com/package/single-spa"&gt;single-spa&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/single-spa-react"&gt;single-spa-react&lt;/a&gt; using &lt;code&gt;npm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i single-spa single-spa-react
// or with yarn
yarn add single-spa single-spa-react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create a file and name it &lt;strong&gt;root.app.js&lt;/strong&gt; inside the &lt;strong&gt;src&lt;/strong&gt; folder (you can choose whatever name you want)
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;touch &lt;/span&gt;src/root.app.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;inside this file, we will establish the &lt;strong&gt;root component&lt;/strong&gt;, which is the top-level React component to be rendered. In our case, it will be &lt;strong&gt;App Component&lt;/strong&gt; inside &lt;strong&gt;App.js&lt;/strong&gt;&lt;br&gt;
the code inside &lt;strong&gt;root.app.js&lt;/strong&gt; should be looks like this&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
by the end of this point, we have now a single-spa application that we can register inside our &lt;strong&gt;root-config&lt;/strong&gt;
&lt;h3&gt;
  
  
  Configure Root Config &lt;a&gt;&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;Now let's configure our &lt;strong&gt;root-config&lt;/strong&gt;, replace the code inside your &lt;strong&gt;index.js&lt;/strong&gt; file with the code below&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;
&lt;br&gt;
by doing this we are doing several steps, telling the single-spa to register your &lt;strong&gt;React&lt;/strong&gt; application using &lt;code&gt;registerApplication&lt;/code&gt; and start the application by calling the &lt;code&gt;start()&lt;/code&gt; function.
&lt;h4&gt;
  
  
  Benefits of migration using this way
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;We are using the same &lt;code&gt;react-script&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;We don't have to configure &lt;strong&gt;webpack&lt;/strong&gt; from scratch, as we are hijacking the current entry point, &lt;strong&gt;src/index.js&lt;/strong&gt;, so there is no need to &lt;code&gt;eject&lt;/code&gt; our &lt;strong&gt;React&lt;/strong&gt; application and reconfigure the &lt;strong&gt;webpack&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can run the application using the same scripts &lt;code&gt;npm start&lt;/code&gt;.&lt;/p&gt;


&lt;h2&gt;
  
  
  Migrating Angular Application &lt;a&gt;&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;To migrate any existing &lt;strong&gt;Angular&lt;/strong&gt; application I followed this &lt;a href="https://single-spa.js.org/docs/4.x/ecosystem-angular"&gt;documentation&lt;/a&gt; from &lt;a href="https://single-spa.js.org/"&gt;single-spa&lt;/a&gt; I am assuming you already have an existing &lt;strong&gt;Angular&lt;/strong&gt; application.&lt;br&gt;
in my case, I am using &lt;strong&gt;Angular version 10&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside your root folder run the following command
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ng add single-spa-angular
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;According to &lt;code&gt;single-spa&lt;/code&gt; documentation, this command will:&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Install single-spa-angular.&lt;/li&gt;
&lt;li&gt;Generate a main.single-spa.ts in your project src/.&lt;/li&gt;
&lt;li&gt;Generate single-spa-props.ts in src/single-spa/.&lt;/li&gt;
&lt;li&gt;Generate asset-url.ts in src/single-spa/.&lt;/li&gt;
&lt;li&gt;Generate an EmptyRouteComponent in src/app/empty-route/, to be used in app-routing.module.ts.&lt;/li&gt;
&lt;li&gt;Add an npm script npm run build:single-spa.&lt;/li&gt;
&lt;li&gt;Add an npm script npm run serve:single-spa.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;and also will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add &lt;strong&gt;single-spa&lt;/strong&gt; as a dependency, you will need to install it, as it not installed by default, it will be only added to your &lt;strong&gt;package.json&lt;/strong&gt;, you can install it manually
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i single-spa
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;or in your root folder where your &lt;code&gt;package.json&lt;/code&gt; located run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which will refresh your dependencies tree and install any missing package.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Generate &lt;strong&gt;extra-webpack.config.js&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Update &lt;strong&gt;build&lt;/strong&gt; option inside &lt;strong&gt;angular.json&lt;/strong&gt; and use &lt;strong&gt;@angular-builders/custom-webpack&lt;/strong&gt; instead of &lt;strong&gt;@angular-devkit/build-angular&lt;/strong&gt;
you will need to install other dependencies by running
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i @angular-builders/custom-webpack
npm i @types/node@14.0.4 &lt;span class="nt"&gt;--saveDev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Extra Steps to complete the migration
&lt;/h4&gt;

&lt;p&gt;Some of these steps are not documented in the &lt;strong&gt;single-spa&lt;/strong&gt; documentation, and I figured it out while I was migrating the application&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Inside &lt;code&gt;app.module.ts&lt;/code&gt; file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;APP_BASE_HREF&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@angular/common&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and add this object to the &lt;code&gt;providers&lt;/code&gt; array&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;provide&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;APP_BASE_HREF&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;useValue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Inside &lt;strong&gt;tsconfig.app.json&lt;/strong&gt;, add &lt;code&gt;node&lt;/code&gt; to types array &lt;code&gt;"types": ["node"]&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In package.json, &lt;code&gt;--deploy-url&lt;/code&gt; flag should be set to the host URL, In order for the webpack public path to be correctly set for your assets, see this &lt;a href="https://stackoverflow.com/questions/47885451/angular-cli-build-using-base-href-and-deploy-url-to-access-assets-on-cdn"&gt;Stack Overflow answer&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result of this migration is a compiled JS file. After finishing the migration you can run the Angular application using this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run serve:single-spa:angular-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Which will start a dev server that is serving your js file, which will be located in &lt;code&gt;http://localhost:4200/main.js&lt;/code&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;What have been done till now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Migrated an existing &lt;strong&gt;React&lt;/strong&gt; application.&lt;/li&gt;
&lt;li&gt;Created our &lt;strong&gt;core config&lt;/strong&gt; file.&lt;/li&gt;
&lt;li&gt;Migrated an existing &lt;strong&gt;Angular&lt;/strong&gt; application.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A complete working solution can be found in this Github &lt;a href="https://github.com/Abdelrahman-H-Mahmoud/single-spa-demo"&gt;repo&lt;/a&gt;, and it will be updated accordingly with each part published.&lt;/p&gt;

&lt;p&gt;In the next part, we will talk more about how to register your &lt;strong&gt;Angular&lt;/strong&gt; application inside your &lt;strong&gt;root config&lt;/strong&gt; file.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>From Monolithic To Micro Frontends - Part 1</title>
      <dc:creator>AbdelRahman Hussein Mahmoud</dc:creator>
      <pubDate>Fri, 01 Jan 2021 16:02:03 +0000</pubDate>
      <link>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-5d5d</link>
      <guid>https://forem.com/abdelrahman_hussein/from-monolithic-to-micro-frontends-5d5d</guid>
      <description>&lt;h2&gt;
  
  
  Motivation:
&lt;/h2&gt;

&lt;p&gt;We were having two applications one of them is &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; and the other one is &lt;a href="https://angular.io/"&gt;Angular&lt;/a&gt;, the challenge here is that we want to run the Angular app inside our React app.&lt;/p&gt;

&lt;p&gt;I came across the &lt;a href="https://martinfowler.com/articles/micro-frontends.html"&gt;Micro frontends&lt;/a&gt; Architecture, and I found it may be helpful in my case and after investigations and reading in-depth about the concept and the architecture, I came up with three solutions&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Revamp the whole Angular application to React.&lt;/li&gt;
&lt;li&gt;Change all the Angular components to web components using &lt;a href="https://angular.io/guide/elements"&gt;Angular elements&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Implementing Micro frontend using &lt;a href="https://single-spa.js.org/"&gt;single SPA&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/11C9FF35M6aXu0/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/11C9FF35M6aXu0/giphy.gif" alt="Burn Them All"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just Kidding 🤓&lt;/p&gt;

&lt;p&gt;The revamp solution will take a lot of efforts and time and we don't have the luxury of time, So we decided to go for the &lt;strong&gt;third solution&lt;/strong&gt; because we were having some limitations in the Angular to split the components, and we will need to bring them back together again inside the React application, and this will take some efforts and time due to the complexity of our Angular application, as it is containing routing, lazy loading modules, and authentication.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is the single SPA?
&lt;/h2&gt;

&lt;p&gt;From single SPA &lt;a href="https://single-spa.js.org/docs/getting-started-overview"&gt;docs&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Single-spa is a framework for bringing together multiple JavaScript micro frontends in a frontend application. Architecting your frontend using single-spa enables many benefits, such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use multiple frameworks on the same page without page refreshing (React, AngularJS, Angular, Ember, or whatever you're using)&lt;/li&gt;
&lt;li&gt;Deploy your micro frontends independently.&lt;/li&gt;
&lt;li&gt;Write code using a new framework, without rewriting your existing app.&lt;/li&gt;
&lt;li&gt;Lazy load code for improved initial load time.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Single SPA main types of applications
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://single-spa.js.org/docs/configuration"&gt;Root Config Application&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://single-spa.js.org/docs/building-applications"&gt;Single-SPA Application&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Root Config
&lt;/h3&gt;

&lt;p&gt;Considered as a container and the parent for all the single SPA applications, and also as a router from your root config application, you can&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Register your single SPA application.&lt;/li&gt;
&lt;li&gt;Determine when to load or unload the single SPA.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;In the next parts, we will do some practical examples. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Migrating the React app to work as a single SPA and root application at the same time.&lt;/li&gt;
&lt;li&gt;Migrating the Angular application to a single SPA.&lt;/li&gt;
&lt;li&gt;Bring all together in one application.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>javascript</category>
      <category>react</category>
      <category>angular</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Deno Vs Node</title>
      <dc:creator>AbdelRahman Hussein Mahmoud</dc:creator>
      <pubDate>Sat, 30 May 2020 12:34:16 +0000</pubDate>
      <link>https://forem.com/abdelrahman_hussein/deno-vs-node-4mm6</link>
      <guid>https://forem.com/abdelrahman_hussein/deno-vs-node-4mm6</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Deno &amp;amp; Node&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Deno and Node both of them are a runtime environment for javascript that is developed by Ryan Dah and both of them build on V8 engine that is used by Chrome.&lt;br&gt;
Deno first introduced in 2018 as Initial release by Ryan.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;What is the difference between Deno &amp;amp; Node?&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Deno uses ES modules so there will be no usage for require() in the future.&lt;/li&gt;
&lt;li&gt;there is no NPM and package.json you can import you js modules as a file path or URL like the browser.&lt;/li&gt;
&lt;li&gt;support for typescript out of box.&lt;/li&gt;
&lt;li&gt;Deno requires explicit permissions for file, network, and environment access.&lt;/li&gt;
&lt;li&gt;Browser compatibility, you can run the same script in the browser and Deno(if you are not using the global object).&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Is Deno going to replace Node?&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;in my opinion and according to Ryan, No it will not,&lt;br&gt;
and I think in the soon future there will be a lot of frameworks that support Deno, for example, there will be express for Deno also&lt;/p&gt;

&lt;p&gt;you can find more in &lt;a href="https://deno.land/manual"&gt;Deno&lt;/a&gt; website&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>deno</category>
    </item>
    <item>
      <title>Software Architecture (introduction)</title>
      <dc:creator>AbdelRahman Hussein Mahmoud</dc:creator>
      <pubDate>Thu, 09 Apr 2020 18:21:36 +0000</pubDate>
      <link>https://forem.com/abdelrahman_hussein/software-architecture-introduction-k14</link>
      <guid>https://forem.com/abdelrahman_hussein/software-architecture-introduction-k14</guid>
      <description>&lt;p&gt;In this series, we will talk about software architecture and what should the developer know, the article will be sample and basic knowledge.&lt;br&gt;
there will be more upcoming parts related to different Software Architecture&lt;/p&gt;

&lt;p&gt;The output from this series should let you have the basic knowledge of software architecture.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: the article is boring for the developer as there will be no code 😃&lt;/p&gt;

&lt;h1&gt;
  
  
  What is architecture?
&lt;/h1&gt;

&lt;p&gt;According to &lt;a href="https://en.wikipedia.org/wiki/Architecture"&gt;Wikipedia&lt;/a&gt; Architecture is both the process and the product of planning, designing, and constructing buildings or any other structures, in our case what is the software architecture?&lt;br&gt;
it's the same actually but instead of planning and designing for building, you are designing for software.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Software architecture is the shape of the system.&lt;/li&gt;
&lt;li&gt;The higher level of the code we write.&lt;/li&gt;
&lt;li&gt;It deals with the structure of the code and how things are organized.&lt;/li&gt;
&lt;li&gt;How internal and external components will communicate with each other.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;The first concern of the architect is to make sure that the house is usable, it is not to ensure that the house is made of bricks&lt;br&gt;
-- &lt;cite&gt;uncle bob&lt;/cite&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And this means is to specify what is essential and what is details.&lt;/p&gt;

&lt;p&gt;For example, we want to build a house, then we need to think about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The space inside the house is essential because if there is no space then there will no place to put your things or to move inside the house.&lt;/li&gt;
&lt;li&gt;The usability of the house if your house contains no rooms then it's useless to live inside it and you will need it to replace it with another house.&lt;/li&gt;
&lt;li&gt;The building material of the house is a detail, as you can build a house using bricks, woods, stone, ...etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The essential here means is to support the primary needs of the house or in our case will be the domain everything else is just implementation of details.&lt;/p&gt;

&lt;p&gt;When we build software:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The domain is essential.&lt;/li&gt;
&lt;li&gt;The use cases are essential.&lt;/li&gt;
&lt;li&gt;Presentation is a detail as you can build your application using ASP, JSP, angular, react, ...etc.&lt;/li&gt;
&lt;li&gt;Data persistence is also a detail, you can use SQL or no-SQL to store your data.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When architecting software you need to think about the business and the problem it will solve.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the Domain?
&lt;/h3&gt;

&lt;p&gt;The domain is the business or the subject your project or software will serve, for example, you need to build a software for banking of financial services, so you need first to understand what is banking and the domain here will be the banking.&lt;/p&gt;

&lt;p&gt;In the next part, we will talk about,&lt;br&gt;
Database Centric vs Domain Centric architecture.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>developers</category>
    </item>
  </channel>
</rss>
