<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Zaheer uddin Babar on Medium]]></title>
        <description><![CDATA[Stories by Zaheer uddin Babar on Medium]]></description>
        <link>https://medium.com/@zaheeer1?source=rss-9b44152cbf46------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*yMn5eF3qFf8CR3Qj.</url>
            <title>Stories by Zaheer uddin Babar on Medium</title>
            <link>https://medium.com/@zaheeer1?source=rss-9b44152cbf46------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:32:20 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zaheeer1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Angular 8 — Monorepo & Micro Apps Architecture]]></title>
            <link>https://medium.com/@zaheeer1/angular-8-monorepo-micro-apps-architecture-a1a96055e614?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/a1a96055e614</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[lazy-loading]]></category>
            <category><![CDATA[microapp]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[angular-workspace]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 12:08:26 GMT</pubDate>
            <atom:updated>2019-11-03T12:08:26.118Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular 8 — Mono-repositories &amp; Micro-apps Architecture</h3><p>We have been developing SPA’s in angular for a while now. Angular has been our top priority for creating enterprise level application. Because it offers scale-ability, best practices, standards, features and stability going forward.</p><h4>PROBLEM STATEMENT</h4><p>Over the passage of time, our web apps have grown big and we have been into the situations, where we have to reuse a feature-a, which was created for application x but that particular feature is later on required in the application y as well.</p><p>Secondly, what if you have a huge product. You give your potential customer a demo and he feels that its a lot costly to have him buy the whole suite. So he prefers to have only one or a limited set of features in your product. How would you be extracting that mini application/s out of the huge code base.</p><p>Well — that would require some effort. In a typical angular architecture, we would be doing it the lazy-loading module way. Although lazy loading, decouple modules in a particular way but re-using that module in another app will still require some rework.</p><h4>ISSUES</h4><p>If you are doing it in traditional way, then there would be lots of copy pasting required(which also depends on any private npm repository). Going forward, feature enhancements and bugs fixing will also be required at multiple code bases. As we know, the life cycle of any product never touches 100%. Code merging, testing, deployments all sorts of activities come into play later on with every change.</p><h4><strong>SOLUTION</strong></h4><p>To address above mentioned problems, there’s this concept of micro web apps architecture floating on the internet for a while now. Which states, try breaking down each of the modules of your SPA into multiple self-hosted or embed-able components.</p><p>Before angular team, there was <a href="https://nx.dev/">NX</a> by <em>Nrwl</em>. They provided mono-repo workspace for angular.</p><blockquote>Workspace is a single source which provides decomposition of your huge application into micro apps. This enables you to host these micro apps in a parent application or on their own. The legacy has been iframes but they have security concerns.</blockquote><p>These days, workspace is part of initial angular scaffolding. In Angular 8, lets see how can we achieve micro-apps architecture without using any third party tools. So let’s get started…</p><h3>SETTING UP MONO REPO</h3><p>Install the latest angular-cli and head into your console. Use the command parameter;</p><pre>--create-application=false </pre><p>to start with an empty workspace as mentioned in the help section of CLI.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1005/1*HoWIwvVpj5fXyPfij_aoTg.png" /></figure><p>Run below command to setup workspace.</p><pre>ng new firstMonoRepo --create-application=false</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/688/1*DXIXG1FvdOXSAaFKm54NVQ.png" /></figure><p>This will create only limited set of files in the directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/1*RT9ASYGIfJYTjhnGtkQDyA.png" /></figure><p>Open the project directory in your favorite code editor and view <strong>angular.json</strong><em> </em>file. You’ll see an empty json object for the key “projects”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/931/1*JLhQlL4Pwoqv9XehU_E2Ww.png" /></figure><p>Now go back to terminal and check how can we add an application to our workspace. Type in below command to see available options from generator.</p><pre>ng generate --help</pre><p>The generator provides <strong>application</strong> as a <strong>schematic</strong> to create an application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*BK8ATVMITKsr3JRkJzs7Jw.png" /></figure><p>Type in the command:</p><pre>ng g application microApp1 </pre><p>in terminal to create a new application with name <em>microApp1</em>.</p><p>When generator asks, add the routing &amp; styling as part of the setup and proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*F1fqrcqgG1qwvVHUGuJwvQ.png" /></figure><p>Once the setup is complete, open the <strong>angular.json</strong> file again, to view the changes. You’ll see the “<strong>project</strong>” key is updated to <em>microApp1</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/761/1*x8i-eShOpimU9l_9rNLyRw.png" /></figure><p>If you check the last line of the <strong>angular.json</strong> file, you’ll find the “<em>microApp1</em>” has also been updated in the “<strong>defaultProject</strong>” key.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/242/1*u8f8DM59kP0ZNR3x62zVMg.png" /></figure><p>Now head into the console and do:</p><pre>npm start</pre><p>This will start the default application in our workspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*-TBZCMlzmPcVJtd6gFQ09g.png" /></figure><p>Default app launches on localhost:4200. So far so good…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*YYgkZr1kRsrbqAUmGd0B9w.png" /></figure><p>Let’s add another app into our current workspace. Head over to terminal one more time and enter:</p><pre>ng g application microApp2</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*RXFZ-aBtgVLxnucrX4Y0gg.png" /></figure><p>Angular-cli adds the new application in the <strong>projects</strong> directory &amp; list it under “<strong>projects</strong>” key in the <strong>angular.json</strong> file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*ormi8D9BV-cuwfh22JQecQ.png" /></figure><p>Let’s change the “<em>defaultProject</em>” to newly created app and do</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/246/1*a2A4Z7PUdoyqZgWRpoUI3g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/1*lpw7kZBStNXLSAupL3-ELg.png" /></figure><p>As shown below, it launches the second app which we created. All good till this stage.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/926/1*V0z8WGWd3oGwkzsmJW7y_Q.png" /></figure><p>Now lets create the <em>startup</em> application which can load the two micro apps. Using the generator lets add 3rd application in the workspace as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*r_IVVU02bZOK4dU_WdZIDA.png" /></figure><p>Once <em>startup </em>app is created by cli, update the <strong>angular.json</strong> file by making “<strong>startup</strong>” as a default project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/1*C559Tb8ZeTOHhrlDpdCG6A.png" /></figure><pre>npm start </pre><p>again to view this app running in the browser;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ECgNCd1BPC12AoWgsHKCPg.png" /></figure><p>At this stage we are comfortable for adding and setting up micro applications in single workspace.</p><h3>SETTING UP MICRO APPS</h3><p>As all three apps at this point has similar named files as <em>app.component</em>, <em>app.routing.module</em> &amp; <em>app.module</em> lets refactor some code to identify them clearly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*Kx_28EPFVq5kVfcXeFZbkg.png" /></figure><p><em>microApp1</em> code has been refactored, lets see if our changes are not breaking and how can we directly run this app from cli.</p><p>If we go down into CLI help, we’ll find ng serve has an argument with <strong>project</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*FR-Amd6c6iWqDjGpDc_VDA.png" /></figure><p>So by using command;</p><pre>ng serve [<em>project-name</em>]</pre><p>we can directly launch our app. So let’s do this and run our refactored app on port 4400 by running:</p><pre>ng serve microApp1 --port 4400</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*_iVMYHK_ilbh9XdC_LOMXg.png" /></figure><p>At this point, we can run our startup app as well on port 4200, using command;</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ajr2DMs1bChC6ZoXKZwwig.png" /></figure><p>Now that our “<em>startup</em>” app and “<em>microApp1</em>” is running, Let’s add a feature module to our <em>microApp1</em>. First go into the <em>app</em> folder of <em>microApp1 </em>and enter the <em>feature-a</em> module command:</p><pre>ng g module feature-a</pre><p>Then add component to this <em>feature-a</em> module, by running below command while inside the <em>feature-a</em> directory:</p><pre>ng g component feature-a</pre><p>This will automatically update references of you <em>feature-a</em> component inside the <em>feature-a</em> module. Lets create a route for this <em>feature-a</em> component in our <em>microApp1RoutingModule</em> as shown below. FYI — You’ll have to <a href="https://angular.io/guide/feature-modules">export </a><em>feature-a</em> component.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U4KhGSHm2Cij7w4Ih9XmFg.png" /></figure><p>After updating the routes and component of feature module, try testing the route as shown below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/1*k6ZEEX_HWnxFaZ3WQYpWRQ.png" /></figure><p>At this stage we can run both of our apps independently through cli.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUSQ0LNKmrTywxc3IZU_Bw.png" /></figure><p>Our <em>microApp1 </em>is working fine till last step, now time to host this app as a lazy loading module inside of startup app. To do this, add route in the <em>app.routing.module.ts</em> in the <strong><em>startup</em></strong> app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qHTAL_65Rbq-OCRZyl02Zg.png" /></figure><p>Now if you go into the browser on route <a href="http://localhost:4200/microapp1">localhost:4200/microapp1</a>. You’ll see the error “<em>BrowserModule has already been loaded.</em>”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkNz_wceIiDwkOl5Wephuw.png" /></figure><p>To fix this issue open the <em>microApp1Module </em>and change the module to <strong>CommonModule</strong> instead of <em>BrowserModule.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*uETP_l-krcmAR_dnsr6pTA.png" /></figure><p>Now if you go to browser, it’ll give you error “<em>RouteModule.forRoot() called twice”.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9WxIcWbPCDAbgJnlnjEhtg.png" /></figure><p>Aha! to fix this open <em>microApp1RoutingModule</em> and update it to <strong>RouterModule.forChild() </strong>from <em>RouterModule.forRoot().</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/877/1*fwBcJs4BWuIdXhXygagRvw.png" /></figure><p>Save your above changes and hit the microapp1 route in the browser. You’ll see that module files are now loading successfully. Also, you can open the feature module of <em>microApp1</em> through the nested route as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/889/1*pzWVUIIWxU5lSFtr-dyJvA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*D5GcIH8xLG62auN2i3rsOw.png" /></figure><p>Our <em>microApp1</em> has successfully hosted inside of the startup app!</p><h4>RUNNING STANDALONE APP</h4><p>Lets try to run our <em>microApp1</em> as a standalone app via cmd;</p><pre>ng serve microapp1 --port 4400</pre><p>You’ll see the error below in console. “<em>Is platform module (BrowserModule) included</em>?”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/682/1*-gHiWYJc51aKGV5Bc_yZVg.png" /></figure><p>Now there’s a problem. If you change the CommonModule back to BrowserModule then our startup app will break again. To resolve above error lets inject a module, based on compile time flags from environment file. This will allow the app to work both in standalone &amp; hosted environments.</p><p>For this, add a new key <strong>standalone: true</strong> in the environment.ts file</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/230/1*86EQOlvcpoKYAN7NrnyzLA.png" /><figcaption>Location: <strong>projects\microApp1\src\environments\environment.microapp1.ts</strong></figcaption></figure><p>Make below changes to choose module type based on the flag value.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YhH-UyF6RRRX0dJiIvYWIA.png" /></figure><p>Similarly, update the RouteModule based on the condition as shown below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*qVoqL1BnoF8mi81zm0xuFg.png" /></figure><p>Once these <em>microApp1</em> changes are done, open the <strong>startup</strong> <em>app-routing.module.ts</em> and set the <strong>standalone</strong> flag as false. This will make the app pick the right modules when running as a hosted app or a standalone app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/861/1*4qk0EHz0jOROriSRcDD6_w.png" /></figure><p>Try running both the commands in two different terminals</p><pre>ng serve microapp1 --port 4400<br>npm start</pre><p>as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ajr2DMs1bChC6ZoXKZwwig.png" /></figure><p>You’ll find <em>microApp1</em> is running on both routes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*DyXWS7QKNcEQTqhPOMyk0w.png" /></figure><p>In the similar way, we can add as many apps hosted inside our main/startup app. Which can run on their own as well and can be deployed with publish command individually where required.</p><p>Thank you for making this far. Happy Reading! :)</p><p>Source Code is available @ <a href="https://github.com/zah33r/angular8-monorepo">GitHub</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a1a96055e614" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6/7 — Azure Hosting]]></title>
            <link>https://medium.com/@zaheeer1/angular-6-7-azure-hosting-64fbafa2d8ef?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/64fbafa2d8ef</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[vscode-extension]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sun, 03 Mar 2019 13:38:40 GMT</pubDate>
            <atom:updated>2019-03-05T10:54:48.448Z</atom:updated>
            <content:encoded><![CDATA[<h3><a href="https://medium.com/@zaheeer1/angular-6-7-firebase-hosting-1e02536eb431?source=your_stories_page---------------------------">Angular 6/7 — Azure Hosting</a></h3><p>In our last <a href="https://medium.com/@zaheeer1/angular-6-7-firebase-hosting-1e02536eb431">article</a>, we already covered how to deploy our application on <a href="https://medium.com/@zaheeer1/angular-6-7-firebase-hosting-1e02536eb431">firebase</a> hosting. Today, we’ll be exploring &amp; covering Microsoft’s Azure platform. What it has to offer for the same cause. This article assumes, you already have Microsoft’s Azure subscription.</p><p>For the sample application, you can refer to my <a href="https://github.com/zah33r/ng7Boilerplate">angular boilerplate</a> or feel free to do an “<strong><em>ng new”</em></strong>. So without further ado — let’s get started.</p><h3>Creating an App-Service</h3><p>Open your browser and type-in <a href="http://portal.azure.com/"><strong>portal.azure.com</strong></a><strong>. </strong>This will land you on the login page. Where you can see your already logged-in <em>Hotmail</em> account. Provide your subscription details and login into the portal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rPnO7HVbE2DOt_kfiz-P_Q.jpeg" /></figure><p>Once you login successfully, you will land on the home page. Here you can see a list of features in the left menu, which azure offers.</p><p>Here first step is, to create a Resource Group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vDKgd2uYsieX-pFoTE_YAw.jpeg" /></figure><blockquote><strong>Resource groups</strong> (RG) in <a href="http://resource.onlinetech.com/key-differences-between-aws-and-microsoft-azure/">Azure</a> is a new approach, to group a collection of assets in logical groups for easy or even automatic provisioning, monitoring, and access control, and for more effective management of their costs. One benefit of using RGs in Azure is grouping related resources that belong to an application together, as they share a unified life-cycle from creation to usage and finally, de-provisioning.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1iBMCaFMWkaHGheSd6sppQ.jpeg" /><figcaption>In the left menu, select <strong>Resource Groups</strong>, then click <strong>Add.</strong> In the <strong>Basics</strong> tab select your subscription (in case you have multiple). Input your <strong>Resource Group Name</strong> &amp; select the <strong>region</strong> in which your resources will be deployed.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mETf4OpLB5P1SxEx-Q83HA.jpeg" /><figcaption>Once you’re done with the resource group creation. Hit the <strong>REFRESH</strong> icon above grid to see your RG, in the list below.</figcaption></figure><p>Now that our <em>RG</em> is setup. Lets create a service to deploy our static assets, which will be created from angular prod build command. For this click “<strong>Create a resource”</strong> &amp; then select “<strong>Web App”</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SoqmfVFze2Y_2a-Aci-mLA.jpeg" /></figure><p>This will display a form like below. Give a unique app name, select subscription. Select our <em>RG</em> that we just created in last step. Choose the OS as <em>Windows</em> &amp; select <em>Code</em> in the publish section. After filling this form, click <strong>Create</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*gynpZULm8IGDnFEXvuZA1w.png" /></figure><p>When you select <strong>Create</strong>, you’ll see a notification in the action bar. This will keep you updated with the deployment progress of the Web App service.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iNXF-gJ_fiQ6aceHxvxCsg.jpeg" /></figure><p>Wait a few seconds, you’ll see <strong>deployment succeeded</strong> message in the notification section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*LXSHJt74nCc-Ew9hPeuYaQ.png" /><figcaption>Click on <strong>Go to resource </strong>button, to see your Web App service page.</figcaption></figure><p>On the app service page, you can see the details associated with this service. Including controls to start/stop/restart app service or delete the app service completely.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oMd0P7WXH5FgnF3kY397PQ.jpeg" /><figcaption>click on the <strong>URL</strong> to see your app running in the cloud.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NG24hGc7jJzJkfD7k-L4gQ.png" /><figcaption>You’ll be greeted by something like this.</figcaption></figure><h3>Node configuration for App-Service</h3><p>Most probably, you’ll be needing to upgrade the node version in this app service. To check for existing version, in the app-service page. Scroll down to <strong>Console</strong>. Once you select it, it’ll show you current working directory like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6Ru4wvk9Yg1Dz4eiSxZPg.jpeg" /></figure><p>here you can type;</p><pre>node -v &amp;&amp; npm -v</pre><p>These are the existing versions. In order to use our <a href="https://github.com/zah33r/ng7Boilerplate">boilerplate </a>template we need to be above node 8.x and will be getting the latest npm as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/457/1*lCYO-QvKCGAGVUqt1jpYbA.png" /><figcaption>So lets get the latest version of node &amp; npm</figcaption></figure><p>For this, scroll up in the app-service page and select <strong>Application settings</strong>. Here, add a new key in <strong>APP SETTING NAME</strong> column with</p><pre>WEBSITE_NODE_DEFAULT_VERSION</pre><p>With the value <strong>10.x</strong> &amp; hit <strong>Save</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lYTXIaTr3ZF-1lBwTYo-uw.jpeg" /><figcaption>Now, lets get back to our <strong>Console</strong> window, to check if our changes are applied.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_zxundOlAgAQjbI3k0Jitg.jpeg" /></figure><p>As node &amp; npm are updated, lets get access to the directory where we are going to deploy our assets.</p><h3>Deploy using FTP</h3><p>There are several ways to deploy build assets. Lets keep it simple and enable <strong>FTP</strong> service. Scroll up to <strong>Deployment</strong> section &amp; select <strong>Deployment Center</strong>. Now in the content pane, scroll down and select <strong>FTP.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*onjPRsVYs-xfJ1_1Xle-6Q.jpeg" /><figcaption>This will display the <strong>FTP</strong> configuration view.</figcaption></figure><p>To access the ftp directory either you can use application credentials or can setup new credentials. Here, we are setting up new user account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HGMl-Sl1diYIegOhg91aDw.jpeg" /></figure><p>Once you save the credentials. <strong>Copy</strong> the ftp path &amp; open up any FTP client. Provide the credentials we just created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*HM_7udo7AI5sScLWtOCc9g.jpeg" /><figcaption><strong>TIP:</strong> Remember to use the app-name as <strong>domain</strong>.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*e2o04bLXDZJigg20_wyWMg.jpeg" /><figcaption>In the <strong>wwwroot</strong> directory we can just paste/<strong>upload</strong> our prod build contents &amp; refresh the page for the changes</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-RqjR3NKv0tkPib1D1RwGA.png" /><figcaption><strong>TIP:</strong> Remember to take your <a href="https://stackoverflow.com/questions/12614072/how-do-i-configure-iis-for-url-rewriting-an-angularjs-application-in-html5-mode/26152011#26152011"><strong>web.config</strong></a> along for the <a href="https://angular.io/guide/deployment">url-rewrites</a>. So that you don’t face any issues with the Angular’s routing.</figcaption></figure><h3><strong>Deploy using Azure-Tools from VSCode</strong></h3><p>We just deployed our angular app from the FTP directory. This is always good to enable <strong>FTP</strong> when you might not have access to your dev machine.</p><p>But There’s a quicker way to deploy the angular apps as well, right from your VSCode. To deploy your app, inside of VSCode. Download <strong>Azure Tools </strong>extension from the extensions tab.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a4_mqKIN7A1cIeLEdrqgew.png" /><figcaption>You’ll see additional option in the left menu in VSCode. <strong>Azure</strong> &amp; <strong>Docker</strong> which are part of this extension.</figcaption></figure><p>Select Azure and you’ll see the <strong>Sign-in to Azure…</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/452/1*M6SoIBiEWapSWsXKtPlK4A.jpeg" /><figcaption>Selecting this will take you in the browser to login page.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lx2aRAwnBt4cp8d5dXgADw.png" /><figcaption>Once you provide your valid credentials. You’ll see this page. Close it and get back to VSCode.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zA4c8R57-tMKYI3_4l31uw.jpeg" /><figcaption>Now you’ll be able to see your subscriptions and the app-services inside of VSCode.</figcaption></figure><p>To deploy your angular app, create your prod build using.</p><pre>ng build --prod</pre><p>Then right click on the app-service name(<em>angular-material-7</em>). Select <strong>“Deploy to Web App…”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QM_U8_kk5RZu2RNfu6-lkA.jpeg" /></figure><p>This will prompt for the location of static assets. Click <strong>Browse… </strong>&amp; select the folder which has <em>index.html</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*z9qo0rkgz08eucNCejIEYw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*GV-V3frh8_U6PF2ICkF6WA.png" /><figcaption>This will ask you one last time to overwrite your old deployment. Select <strong>Deploy</strong>…</figcaption></figure><p>You can check for the progress in the <strong>Output</strong> tab in the VSCode for the commands which are executing in the background. Once the process is complete. You’ll see a notification like below and can view your deployment by hitting the <strong>Browse Website</strong> button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SKwAUMFgcad20IRucFHS7g.png" /></figure><p>Next time you want to deploy your builds to app-service. Its just a matter of couple of clicks inside of VSCode. I hope you’ll find this article helpful. Next we’ll be looking into azure devOps. How to deploy our apps with CI/CD Pipelines. Until then — Cheers!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64fbafa2d8ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6/7 — Firebase Hosting]]></title>
            <link>https://medium.com/@zaheeer1/angular-6-7-firebase-hosting-1e02536eb431?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e02536eb431</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[hosting]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sun, 28 Oct 2018 15:49:47 GMT</pubDate>
            <atom:updated>2018-10-28T15:49:47.600Z</atom:updated>
            <content:encoded><![CDATA[<h3>Angular 6/7 — Firebase Hosting</h3><p>If you’ve been following angular conference. You’ll come to know, apart from open source there’s a massive community working in enterprise sector. So you don’t see major front-end applications in angular publicly, as they are hosted privately on intranets.</p><p>Google mentioned in ng-conference “we upgrade around 500 internal apps before releasing new major version of angular”. This gives you an idea how stable angular is for development.</p><p>Deployment guides for different web servers can easily be seen in the <a href="https://angular.io/guide/deployment">Deployment section</a> of angular-docs. Where, it provide details for deployment in IIS, nginx, apache &amp; firebase.</p><p>Today we are going to cover a scenario, when you don’t have access to any production server. But you would like to give a quick POC to your customer by hosting your angular application.</p><p>The quickest way is, to use google’s own service <a href="https://firebase.google.com/"><strong>Firebase</strong></a>. With firebase and its command line tools. You can host your application on a live URL in a couple of minutes. So let’s get started!</p><p>First log on to <a href="https://firebase.google.com/">firebase</a> with your google account.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mb7ViHkBVD4NY_K3h88OXA.png" /><figcaption>Now hit the blue button <strong>GET STARTED</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/315/1*UCNHcgJG4oRq8DAAaXyA2A.png" /><figcaption>Once you are on console.firebase.com hit the <strong>Add Project</strong> button</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*8-0btaJcsIaS9pq1N6fjNA.png" /><figcaption>write your project name, firebase console will update you about the availability of this name.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*hSC_BMLRCaxnAwYV-Yp4gA.png" /><figcaption>Wait for your project to create. Once you are done you’ll be greeted to app-home</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c_T0NB1_PZ7v0K6RBhH7lQ.png" /><figcaption>Now we’re done with the project creation lets jump back to our code</figcaption></figure><p>Open up terminal and first install firebase-tools as a global package.</p><pre>npm install firebase-tools -g</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/1*R8EoXiApL01DFqT9zTzFKA.png" /></figure><p>Once, you are done installing tools. Go back to your root directory of the application &amp; create a prod build by using command</p><pre>ng build --prod</pre><p>This will output the distribution files in the <strong>dist</strong> directory</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*-ei2an-SOoEiE_wG7_IW1A.png" /><figcaption>Now that you see, <strong>dist</strong> folder &amp; <strong>package.json</strong> lets move on</figcaption></figure><p>Just verify your path that you’re on the root directory and hit this cmd</p><pre>firebase init</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*woWuktcxr8oVyHyW7Ef5xQ.png" /></figure><p>First time you initialize, the cli will provide you the list of projects already created. Either you can choose from them or can create new from here as well.</p><p>Let’s select <strong>ng6-poc</strong> we just created above &amp; hit enter for selection.</p><p>Cli will ask you couple of more questions, <strong>(1)</strong> What do you want to use as your public directory? type here <strong>dist (2) </strong>Configure as a single-page app? type here <strong>y (3) </strong>File dist/index.html already exists. Overwrite? type here <strong>N. </strong>Just answer these questions and your initialization will be complete in a few seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*46hRI6bZPFyO7L6_XEfT_A.png" /></figure><p>You can see the configuration files in your project; <strong>.firebaserc &amp; firebase.json</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*5E3JfZ8NWh0QmrPs1wjfEA.png" /></figure><p>Once configurations are updated, let’s hit the roads by typing our last command</p><pre>firebase deploy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*4tFwmTdGajlFkwGlplAnDQ.png" /></figure><p>Once done, you’ll see the hosting URL; <em>control + click</em> on url in terminal &amp; lets view our POC…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G4fOUmfyl5sBqIqi-xV9fQ.png" /><figcaption>Voila! it works</figcaption></figure><p>Simple isn’t it!? Next time you would like to deploy your application. Its a matter of just two steps;</p><pre>1) ng build --prod // create prod build with latest changes<br>2) firebase deploy // push latest changes to firebase hosting</pre><p>That’s all folks for this time. See you around, in the next productive article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e02536eb431" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6 — Environment, Build & Version]]></title>
            <link>https://medium.com/@zaheeer1/angular-6-environment-deploy-version-403a3ddeb8a?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/403a3ddeb8a</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[semantic-versioning]]></category>
            <category><![CDATA[version]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[versioning]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sun, 05 Aug 2018 20:18:09 GMT</pubDate>
            <atom:updated>2018-08-05T20:45:52.992Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is on top of our previous guide, where we did setup of multiple build environments. If you haven&#39;t checked that out. I’ll suggest you, give it a quick read <a href="https://medium.com/@zaheeer1/angular-6-compile-time-vs-run-time-environments-180c86c3d2e2"><strong>here</strong></a>. But if you are already familiar with angular 6 environments, skip that and come along.</p><p>Versioning your application is one of the main principles of source code management. It will not only manage the source code, But it will help you out in real world scenarios. Where you are deploying multiple versions of the application. You need to checkout an existing app, which version was published. Not from the code, deployment server or published logs. But from the app itself.</p><p>So let’s get started.</p><p>To fill this requirement, first we need to install <a href="https://www.npmjs.com/package/require"><strong><em>require</em></strong></a> package from npm.</p><blockquote>npm i require — save-dev</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XycTGMbQUwgpV7MNB0SbhQ.png" /><figcaption>install require package in your dev-dependencies</figcaption></figure><p>Then open tsconfig.json file which can be found on the root of the project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/521/1*AxR3lp2spojLAKMTRmLSIQ.png" /></figure><p>Once you open it, add new keys <strong><em>types &amp; typeRoots</em></strong><em> </em>and fill the values mentioned below.</p><blockquote><em>“types”</em>: [“node”],</blockquote><blockquote><em>“typeRoots”</em>: [</blockquote><blockquote>“../node_modules/@types”</blockquote><blockquote>]</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*n5P1P3sCppRYBdsYm3Olww.png" /><figcaption>Your tsconfig.json will look like this.</figcaption></figure><p>Now let’s get back to our good old environment file. This time we add a new key <strong>version.</strong> Using the require package that we installed a while ago. We’ll refernce version key from package.json</p><blockquote>version: require(‘../../package.json’).version</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z9rCEcGheGVZ5QvyJY_Hag.png" /><figcaption>The updated environment file will look like this.</figcaption></figure><p>Next we can reference that environment key from any class. But keeping things simple. I have created an AppConfig. Which basically provides the static data across application. So I’ll add it here.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*8aYwEjo38m9kDJ98WdY33Q.png" /></figure><p>Okay great we have, required package setup &amp; environment setup. Let’s take a look at <a href="https://docs.npmjs.com/cli/version#synopsis"><strong>npm version</strong></a> command quickly.</p><p><strong>Synopsis:</strong></p><blockquote>npm version &lt;newversion&gt; | major | minor | patch</blockquote><p><strong>Description from npm:</strong></p><blockquote>Run this in a package directory to bump the version and write the new data back to <strong>package.json</strong>, <strong>package-lock.json</strong>, and, if present, <strong>npm-shrinkwrap.json</strong>.</blockquote><p>Version semantics follow <strong>Major.Minor.Patch</strong> in npm world. So I have added <em>npm version patch</em> in our <em>qa-build</em> script. Which will increment the patch by 1 value.</p><p>e.g if we have started with 1.0.0 and in our current working directory, we enter below command</p><blockquote>npm version patch</blockquote><p>it will increment to 1.0.1 in the package.json</p><p><strong>Note </strong>— Make sure to commit your changes, if you have a git repository. As version info is also tagged with git commits. In a git directory, it’ll not allow you to bump the version, unless pending changes are committed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/874/1*ET71TQ-tZIn0OZyyuKnXYg.png" /><figcaption>So here I have created custom command bump-patch</figcaption></figure><p>Here,<strong> — allow-same-version</strong> flag will allow the script to overwrite the previous version, if you have manually updated the version from command line. Now every time we create our qa-build, the patch version will bump. Similarly we can bump prod as well with Major version.</p><p>But that part is upto you, how you follow the versioning scheme in your project.</p><p>Ok! lots of talk - lets display the version some where in our application. You can make a smart dialog box of about us or can place it in footer with copyright section. Whichever suits your style guides. For simplicity, I have placed it right on the top of our AppComponent.</p><p>Below are the AppComponent.ts &amp; AppComponent.html files.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*Z6_yPyJD7RoJl0Bp3ab5OQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/767/1*gnH8Kr07USsa-MvpX61Tog.png" /></figure><p>Now save it and load the home page. There you go! we have successfully printed our app version. Which will update with our every build.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/1*Ao73U3HZR2ec9sE82uLMMA.png" /></figure><p>The source code of the sample can be found in my <a href="https://github.com/zah33r/ng6Boilerplate">github</a>, under branch <a href="https://github.com/zah33r/ng6Boilerplate/tree/feature-versioning">feature-versioning</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=403a3ddeb8a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6 — Compile Time vs Run Time Environments]]></title>
            <link>https://medium.com/@zaheeer1/angular-6-compile-time-vs-run-time-environments-180c86c3d2e2?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/180c86c3d2e2</guid>
            <category><![CDATA[runtime]]></category>
            <category><![CDATA[environment]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[configuration]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sat, 21 Jul 2018 23:40:21 GMT</pubDate>
            <atom:updated>2018-07-21T23:40:21.321Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s world, every application either its a back-end or a front-end, ought to have different stages of a project. Unless you are working on a POC. You need a streamlined version controlling system. This starts right from Git or TFS (the most popular version controls out there in the wild).</p><p>You need to setup multiple branches for your DEV, QA, UAT and PROD environments to manage your code structure for each state. In the same essence, we need to make builds for these states as well. But how can you make sure that with minimum effort, you can prepare your builds and separate-out configurations for each of the environments?</p><p>For this in angular 6, we have <strong>environment </strong>files out of the box. This feature is coming from angular 5 but with much improvements thanks to <em>angular.json </em>file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/343/1*RQtdu7Q1foLu6ANMtOspZw.png" /><figcaption>By default angular 6 project is instantiated with environment.ts &amp; environment.prod.ts</figcaption></figure><p><strong>Compile-Time Environments</strong></p><p>By default the project is setup with two environment files. environment.ts &amp; environment.prod.ts . If we open one of the file, you can find this instruction.</p><blockquote>The file contents for the current environment will overwrite these during build. The build system defaults to the dev environment which uses `environment.ts`, but if you do</blockquote><blockquote>`ng build — configuration=prod` then `environment.prod.ts` will be used instead.</blockquote><blockquote>The list of which env maps to which file can be found in `angular.json`.</blockquote><p>This means, whichever configuration you choose from cli, eventually your environment.ts will be overridden. So first thing, declare environments in your project like below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Us-QxMingPHco3WrIEmjbQ.png" /><figcaption>Here you can see we have same json for dev and prod environments, but with different values.</figcaption></figure><p>To use this, import it like you regularly do;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*4X3tl536_1pbKu4Ght2nYQ.png" /><figcaption>after import, you can consume your static variable where required.</figcaption></figure><p>And to build your project, you’ll use below commands</p><blockquote>ng build</blockquote><blockquote>ng build — prod — aot — output-path \”.\\dist\\prod\”</blockquote><p><strong>ng build</strong> will pick, <em>environment.ts</em> whereas, <strong>ng build — prod</strong> will pick the <em>environment.prod.ts</em> respectively.</p><p>Let’s add 3rd environment in addition to “dev” and “prod”, i.e. <strong>qa</strong></p><p>For this, add a new <strong>environment.qa.ts</strong> file in <strong>environments</strong> directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*LT2uniDv_ZjbkcayGjBNDw.png" /><figcaption>we updated the appRoot to point to qa-api server</figcaption></figure><p>To add configuration for <strong>qa</strong>, open <em>angular.json</em> and add “qa” json, below “production”, like shown in the image below and save it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*9utsmx_h8A4t03aEti6ESg.png" /><figcaption>You have a new configuration with key “qa”</figcaption></figure><p>Now to make this build, use below command;</p><blockquote>ng build — configuration=qa — output-path \”.\\dist\\qa\”</blockquote><p>This will generate build in the <em>/dist/qa</em> directory. Similarly, you can make other environments to your needs.</p><p><strong>Run-Time Environments</strong></p><p>In some scenarios, you might want to update your configuration based on the json file. Which you could add in your project. And without rebuilding project each time with new parameters. You could just add/update keys in the json file and your app responds to these changes.</p><p>For this you need a mechanism to first load your configuration file and then allow your application to bootstrap. To do this lets follow steps below;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/827/1*4P6W3UrK-YBoJrpcM5UU6Q.png" /><figcaption>Add a new file appConfig.json in your assets directory</figcaption></figure><p>After adding the json file, add your desired configuration keys and their values and save it. After this, open your app.component — which is the entry level component of any angular app. Add below code snippet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/656/1*IdqJO87jhm8GqcYeyzpwUw.png" /><figcaption>A flag to check if configurations are loaded from our json file and a loading bar section, in case your app is taking time to load file.</figcaption></figure><p>Trick is to show progress-bar until our configurations are loaded. Once it’s loaded, we’ll hide the progress-bar and show our router-outlet with other header, footer components.</p><p>Let’s open our app.component.ts file and place below code;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*k2xquY8f2rkoGrGq30mBrw.png" /></figure><p>Let’s have a look at this. The above piece of code, declares a configuration flag to show/hide progress-bar and appConfig.json path.</p><p><strong>OnInit</strong> we are making an <strong>http</strong> client call to fetch data from config file. Once the file is found, we override our default values in function <strong>overrideStaticConfigurations</strong> and toggle the flag to show our app component<em>. </em>In case, we are missing the file, we handle the error gracefully by writing a warning in console and use our static configurations, which are saved in environment.ts file.</p><p>For demonstration purpose, I have added 5 seconds delay, in your production apps you should remove this.</p><p>Let’s save and run our application. You’ll be greeted by loading message and then switched to the home screen after 5 seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*YzcXRO91MWV6zGVOgZDG5A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/679/1*Q7qLuUKiv9I3p9gkicjgRQ.png" /><figcaption>environment object, overridden by run-time configuration file - printed in console</figcaption></figure><p>To check, if your compile-time settings were there already, remove/rename the json file in assets directory and save. Reload the app and check console window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*4KoRYuPQlZQwnfAPey0Trg.png" /><figcaption>rename or remove the file to load compile-time configurations</figcaption></figure><p>There you have it! Compile-time &amp; Run-Time configurations in your angular 6 app.</p><p>PS — The source-code is available at <a href="https://github.com/zah33r/ng6Boilerplate/tree/feature-runtime-configurations">github</a>.</p><p>Checkout <strong>feature-runtime-configurations</strong> branch for this change-set.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=180c86c3d2e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angular 6 Library — The CLI Way!]]></title>
            <link>https://medium.com/@zaheeer1/angular-6-library-the-cli-way-9777f1505882?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/9777f1505882</guid>
            <category><![CDATA[libraries]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[modules]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Fri, 13 Jul 2018 20:50:27 GMT</pubDate>
            <atom:updated>2018-07-14T10:48:11.864Z</atom:updated>
            <content:encoded><![CDATA[<p>Angular keeps on evolving with great stuff over the passage of time. One of the key feature in angular 6 is the inclusion of multiple projects within single work-space. This has opened options to create a modular project in much organized architecture. Less coupling &amp; re-usability to the next level.</p><p>Angular library can be a set of components, views and styles all packaged up in the single exportable unit. This has been possible thanks to <a href="https://github.com/dherges/ng-packagr"><em>ng-packagr</em></a> and great community work.</p><p>This will also allow you to enhance your application in incremental upgrades. More on this later…</p><p>So there are several benefits, will discuss them in another blog post. With this much said, lets get going and create our first angular 6 library.</p><p>In your newly created angular 6 project, try this new command to create an angular library.</p><blockquote>ng generate library material-message-box</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*5EoBNPsHPf43T8hrqieuOw.png" /></figure><p>This will set up several things in your existing project. Will make a work-space for you. (<em>which it basically does by-default, if you never bothered like me before</em>)</p><p>Once CLI completes adding new project in current work-space, your project structure will look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/416/1*TvgkQhhixGlqY41GQRpfhQ.png" /><figcaption><strong>All your existing code still lives in ‘src‘ folder, whereas the new library is added in the projects directory</strong></figcaption></figure><p>We can see that angular.json, package.json and tsconfig.json has been updated in our project. Let’s take a sneak peek into these files to see what happened here.</p><p>If we differentiate this file with the last state, there’s a new json object with our project name “material-message-box”, which reside just above the default project. So there goes all the configurations of our library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nzoh0B_VpqpOqJgZpJvvqw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W8BB9rgmpr-r0ASWMk2qMA.png" /></figure><p>Now that we know our library is setup, lets jump straight into the terminal and try building it for the first time. To build our library you’ll use command</p><blockquote>ng build material-message-box</blockquote><p>basically; ng build “project-name-here”</p><p>Luckily! if you have an angular 5 app earlier and you upgraded it to angular 6 via <strong>ng update;</strong> you’ll most probably hit by the error below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*VaC77E1trkBxu7Sk19zORw.png" /><figcaption>The error occurs because when we update our angular 5 application, it still doesn’t update tsconfig.json</figcaption></figure><p>After couple of head-bangs in google search we come up with this comment, although it talks about lazy loading but still, we have the similar route, so lets try that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/773/1*yD7GOU33KwNhOhRryzkVjQ.png" /></figure><p>To fix above issue, open the tsconfig.json at the root of the project and add key with this value</p><blockquote>“baseUrl”: “./”</blockquote><p>Your tsconfig.json will look like this now;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tg8f0RN4w5-zdZyZCCKM1g.png" /></figure><p>Once updated and saved, lets try again</p><blockquote><strong>ng build material-message-box</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3q8SBOXU4FbEm64bGbrl1g.png" /><figcaption>Voila! It works!</figcaption></figure><p>Our <em>material-message-box</em> library is built in <strong>/dist</strong> folder;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/1*jJxOavIf2VmIeWDHSbv2eQ.png" /></figure><p>Cool! now that our library is built. Lets use it in our main project. But how do you do that? Well, just like any other node package, which we install from npm. we’ll npm install ‘package-name’ but this time we’ll provide the path of the <strong>/dist</strong> folder. This will install the material-message-box library in our apps <strong>node_modules</strong> directory. so lets do that;</p><blockquote>npm install ./dist/material-message-box</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/756/1*13KwSVUN328plTiJiEUkkA.png" /></figure><p>As the npm says it successfully installed one package. Let’s confirm this;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/501/1*CZymwxAn6hAqR2Ca-LuGPA.png" /><figcaption>great! we have our dependency in node_modules</figcaption></figure><p>Now to use it in our project. Open your app.module or any module in case you are doing lazy loading and import the module of our library.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*29Z7mCuo5nuZFBMWlas3TQ.png" /></figure><p>Once you add this line, check the console, the angular-cli generates an error that module not found. This happens because it keeps on picking the module from the dist folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*rAnqFaGP3sqrD4gHrk_Fuw.png" /></figure><p>We can fix this by pointing our package to our node_modules directory. I wonder why this doesn’t work with the dist folder. But once it’s pointed to <em>node_modules</em> you’ll see the error is gone for good from the console.</p><p>Like in the image below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*JfK1fMrODjyv4P8MAqBZVg.png" /></figure><p>Next is to add our library module in the imports array, like we do for any other angular module;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/348/1*85El1a3QNxwTNotRSGzW6Q.png" /></figure><p>Lastly, open the template file in our main project, where you would like to add our library component. For the sake of simplicity, in the app.component, add the library component, i.e. lib-material-message-box; remember we saw <strong>lib </strong>as a prefix when we generated the library. You can change it to your needs;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*QDM6H9ATezWLlRrhevlArw.png" /></figure><p>Save it and reload the home page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*MiE4YlUqDDzVqZy8fAigyQ.png" /></figure><p>Magic! our library component loaded successfully.</p><p>This was how to setup an angular library. You can publish your package on npm via <strong>npm publish</strong> after passing in the login details. And who knows you’re the next thing in google search! ;)</p><p>More on angular libraries in the coming articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9777f1505882" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Upgrade Angular 5 to 6]]></title>
            <link>https://medium.com/@zaheeer1/upgrade-angular-5-to-6-20e302bae86e?source=rss-9b44152cbf46------2</link>
            <guid isPermaLink="false">https://medium.com/p/20e302bae86e</guid>
            <category><![CDATA[angular-cli]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[upgrade]]></category>
            <category><![CDATA[migration]]></category>
            <dc:creator><![CDATA[Zaheer uddin Babar]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 10:44:42 GMT</pubDate>
            <atom:updated>2018-06-30T10:56:15.178Z</atom:updated>
            <content:encoded><![CDATA[<p>Before you begin, Make sure you are using <a href="http://www.hostingadvice.com/how-to/update-node-js-latest-version/">Node 8 or later</a>.</p><p>Angular 6 comes with new cli command <strong>ng update </strong>to upgrade your current project. While the project’s root location is our current working directory.</p><p>Let’s Begin!</p><ol><li>So as an excited beginner you go straight into the terminal and try using <strong>ng-update.</strong></li></ol><blockquote>$ ng update</blockquote><p>Oops! No luck. You get below error.</p><blockquote>The specified command update is invalid. For available options, see `ng help`.</blockquote><p>This means you need to update you angular-cli to latest version, for that type below command in the terminal and hit Enter:</p><blockquote>$ npm install — save-dev @angular/cli@latest</blockquote><p>Once cli is updated to latest version try <strong>ng update</strong> again.</p><blockquote>$ ng update</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*yu6U-boM-7S_8SRJGz9rkA.png" /><figcaption>This time you’ll get feedback from the angular-cli, something like above. The list of updates depend on your existing package versions.</figcaption></figure><p>To upgrade these packages, I tried putting all packages in the single command first like <em>npm install</em>. But it generated below results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsw6zZACZaqfyS7p5i04IQ.png" /><figcaption>ng update does not update multiple package here for some reason.</figcaption></figure><p>So, nothing updated here and we got a warning as well. Depending on your typescript version, you might get warnings to fix the desired <em>@angular/compiler-cli</em> version at this stage. So lets try fixing this one first. Use below command in terminal.</p><blockquote>$ npm install @angular/compiler-cli@”&lt;2.8&quot; — save-dev</blockquote><p>and the remaining ones after compiler-cli version is fixed;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*T8O0d5T38mV1pc6WEv4seQ.png" /></figure><p>Let’s ignore the warning of <em>angular.json</em> for now and try <strong>ng update</strong> again</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/1*IOUM0t26cWnqV-QmfxbSZQ.png" /><figcaption>Cool! you have updated all of your packages at this stage</figcaption></figure><p>Lets try to run our project, jump into the terminal and hit npm start</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/1*CiDWsLd5EJ1hL7rkHVdGCw.png" /><figcaption>Errr! what’s up with angular.json now</figcaption></figure><p>At this stage, we need to upgrade our current project’s <strong>angular-cli.json</strong> file. Angular 6 has replaced the <strong>angular-cli.json </strong>with <strong>angular.json</strong> file which is responsible for managing all the configurations, environments, imports etc.</p><p>To migrate all your existing environments &amp; settings and not creating the file manually, type below command in the terminal:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*XtzfzXOc_5h8iVehgP8xSw.png" /></figure><p>Voila! you have successfully migrated your angular 5 project to angular 6! You’ll see the <em>angular.json</em> in your project’s directory with all existing configurations.</p><p>PS — In our project, we have very few third party libraries so the process was smooth to upgrade. If your project has several third party libraries, do check their git pages for the available updates. Because <strong>ng update</strong> works with the packages which are following <a href="https://blog.angular.io/schematics-an-introduction-dc1dfbc2a2b2">angular schematics</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=20e302bae86e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>