<?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 Damian Bielecki on Medium]]></title>
        <description><![CDATA[Stories by Damian Bielecki on Medium]]></description>
        <link>https://medium.com/@bielik20?source=rss-43a17ec832bc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Z577RJ52Qrk-VoEU</url>
            <title>Stories by Damian Bielecki on Medium</title>
            <link>https://medium.com/@bielik20?source=rss-43a17ec832bc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:53:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bielik20/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[Tree Shaking — Ad Engineering Journey]]></title>
            <link>https://medium.com/fandom-engineering/tree-shaking-ad-engineering-journey-e4aa07cec024?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/e4aa07cec024</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[tree-shaking]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[rollup]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Fri, 24 Jan 2020 12:22:23 GMT</pubDate>
            <atom:updated>2020-01-24T12:27:42.333Z</atom:updated>
            <content:encoded><![CDATA[<h3>Tree Shaking — Ad Engineering Journey</h3><p>Our journey with tree shaking and some nuisance we had to face.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*Dq6ZUUVqBmI8PvJf.png" /></figure><h3>Our setup</h3><p>In Ad Engineering we work on AdEngine our library for managing ads, as well as on integrating that library with various sites (apps) we support. So, we have a library and multiple apps that we need to adjust for tree shaking to work.</p><p>For building library (AdEngine) we use Typescript with Rollup.</p><p>For building apps we use Typescript with Webpack.</p><h4>Legacy Build</h4><p>Before tree shaking we used to split AdEngine into separate modules to limit bundle size. That solution was hard to maintain and did not yield expected results. Every module was an autonomous unit and it usually meant including duplicates of code in each of them. Moreover, it was not clear how to split modules for the best efficiency as apps we support may need different parts of the same module.</p><h4>Solution?</h4><p>Tree shaking wasn’t obvious nor the only solution we had in mind. One thing that remained clear was that we needed to update our building process because the duplicate parts of code, in all fairness not that significant at the moment, were starting to become a burden. For some time we entertained a thought of using <a href="https://github.com/lerna/lerna">Lerna</a> for managing submodules. After lengthly discussion we came to a conclusion that we don’t really need modules in a sense of multiple packages, we only want to eliminate unused parts of our library. Tree shaking came out as an obvious candidate.</p><h3>Tree Shaking</h3><h4>What is tree shaking?</h4><p>Tree shaking is a process of removing unnecessary/unused parts of the code from the final bundle. Those parts are usually referred to as “dead code”.</p><h4>How it is done?</h4><p>Most modern bundling tools like Webpack already have a built in support for tree shaking, but it doesn’t mean it will work without any preparations on the library part.</p><h4>How to setup a Typescript to support Tree Shanking?</h4><p>The important part is for tsconfig.json to contain:</p><pre>{<br>  &quot;compilerOptions&quot;: {<br>    &quot;target&quot;: &quot;es5&quot;,<br>    &quot;module&quot;: &quot;es2015&quot;,<br>  }<br>}</pre><p>The least important of the two is target. We want our code to be compiled to es5 so this is what we choose. While it is not essential for tree shaking to work it will become important in a later section.</p><p>module is the essential setting. It needs to be targeted at at least es2015 This will make our output look somewhat like that:</p><pre>import { ... } from &#39;...&#39;;</pre><pre>...</pre><pre>export { ... };</pre><p>This makes it possible for Webpack to eliminate unused parts/exports of our code. The only thing left to do is to set the module field of a package.json to tell Webpack that we have build that supports tree shaking.</p><p>This, in theory, is everything we need to do to make our library tree shakeable.</p><h3>Problems</h3><p>It turned out that things are not as simple as we may want them to be…</p><h4>Classes</h4><p>The first problem came out of &quot;target&quot;: &quot;es5&quot;. es5 does not support classes. This means that code:</p><pre><em>class </em><strong>Context</strong> {<br>}</pre><p>gets compiled to:</p><pre><em>var </em><strong><em>Context </em></strong>= <em>/** </em><strong><em>@class </em></strong><em>*/ </em>(<em>function </em>() {<br> <em>function </em>Context() {<br> }<br> <em>return </em>Context;<br>}());</pre><p>It turns out that Webpack doesn’t understand that/** @class */ means that this fragment of code is pure (does not contain side effects). To combat that we had to write our own little plugin that would translate /** @class */ to something that Webpack can understand which is /*@__PURE__*/:</p><pre><em>export function </em>classToPure() {<br> <em>return </em>{<br>  renderChunk(code) {<br>   <em>return </em>{<br>    code: code.replace(/\/\*\* @class \*\//g, &#39;/*@__PURE__*/&#39;),<br>    map: <em>null</em>,<br>   };<br>  },<br> };<br>}</pre><p>This solves our problem and results in compiled code looking like that:</p><pre><em>var </em><strong><em>Context </em></strong>= /*@__PURE__*/<em> </em>(<em>function </em>() {<br> <em>function </em>Context() {<br> }<br> <em>return </em>Context;<br>}());</pre><h4>Instances</h4><p>The other problem was with our codebase itself. It is common for our code to contain a lot of instance exports:</p><pre><em>export const </em><strong><em>context </em></strong>= <em>new </em><strong>Context</strong>();</pre><p>This creates a similar problem. As those instantiations are all over the place almost nothing got tree shaken. To fix that we created yet another plugin to tell Webpack that this in fact is also “pure”.</p><pre><em>export function </em>instanceToPure() {<br> <em>return </em>{<br>  transform(code) {<br>   <em>return </em>{<br>    code: code.replace(/^(export const .+ = )new/gm, (match) =&gt;<br>     match.replace(&#39;new&#39;, &#39;/*@__PURE__*/ new&#39;),<br>    ),<br>    map: <em>null</em>,<br>   };<br>  },<br> };<br>}</pre><p>This plugin searches for every exported instantiation and transforms it to something like:</p><pre><em>export const </em><strong><em>context </em></strong>= /*@__PURE__*/ <em>new </em><strong>Context</strong>();</pre><p>Now this may seem dangerous at first, as we may “purify” something we don’t want to. This is a risk we accepted when writing this plugin and it allowed us to efficiently tree shake our code.</p><h3>Summary</h3><p>Today, I am happy to say that it has been over half a year without a one incident caused by tree shaking. We were able to reduce our bundle size by ranging from 25% to 45% (up to 250KB). What is more important we are free to write and structure our code in a way that makes logical sense without having to worry where to put certain parts to reduce bundle size.</p><p>What are your stories with tree shaking and reduction of bundle size. Did you have similar problems or different altogether? Share it with us, I would be interested to find out what we could do better.</p><p><em>Originally published at </em><a href="https://dev.fandom.com/wiki/User_blog:Nikodamn/How_to_start_writing_automated_tests_using_WebdriverIO"><em>https://dev.fandom.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e4aa07cec024" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fandom-engineering/tree-shaking-ad-engineering-journey-e4aa07cec024">Tree Shaking — Ad Engineering Journey</a> was originally published in <a href="https://medium.com/fandom-engineering">Fandom Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins Jobs Runner]]></title>
            <link>https://medium.com/fandom-engineering/jenkins-jobs-runner-43e8fd81a195?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/43e8fd81a195</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Fri, 30 Aug 2019 12:49:23 GMT</pubDate>
            <atom:updated>2019-08-30T12:51:12.872Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*zldnzTSKDGunqNh6Bhv8TQ.png" /></figure><p>This article is part of a <a href="https://medium.com/fandom-engineering/jenkins-cli-4dfcee951e2a">Jenkins CLI series</a> in which we describe how we built CLI application for executing a series of parallel Jenkins Jobs in a terminal.</p><p><a href="https://www.npmjs.com/package/jenkins-jobs-runner">Jenkins Jobs Runner</a> is a library powered by <a href="https://www.npmjs.com/package/jenkins-rxjs">Jenkins RxJs</a> that enables sequential execution of n batches, each of m parallel jobs. On top of that, it provides a visual interface to display the current status of jobs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*etYHy6RoxufUNIvM0cG-iA.gif" /></figure><h3>How it works?</h3><p>Jenkins Jobs Runner takes as an input array of JobBatchDescriptor object. They are expressed through an interface:</p><pre><em>import </em>{ <em>JobBuildOptions </em>} <em>from </em>&#39;jenkins&#39;;</pre><pre><em>export interface JobBatchDescriptor</em>&lt;T1 = <em>string</em>, T2 = <em>string</em>&gt; {<br>  displayName: T1;<br>  jobDescriptor: <em>JobDescriptor</em>&lt;T2&gt;[];<br>}</pre><pre><em>export interface JobDescriptor</em>&lt;T = <em>string</em>&gt; {<br>  displayName: T;<br>  opts: <em>JobBuildOptions</em>;<br>}</pre><p>Then, for each batch it follows this simple schema:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*ieCPo-fv5LNFocuz" /></figure><h4>Await Execute Batch</h4><p>This step goes as follows:</p><ol><li>For each Job in Batch create Display Stream</li><li>UI Manager updates UI for every value emitted in the stream</li><li>Combine Display Streams of all Jobs in the Batch</li><li>Convert it to a Promise</li><li>Await completion of the Combined Streams</li></ol><h4>Display Stream</h4><p>Display Stream is a combination of an original JobResponse stream from Jenkins RxJs and 1 second interval observable. 1 second is (sort of) UI refresh rate. It can be expressed using diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/0*exTlBN92IVEvZQ2a" /></figure><h4>Combined Stream</h4><p>Combined Stream is a combination of last emits (completions) of Display Streams of all jobs in the batch. It can be expressed using diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/0*Elk7SPaALOhiF5WP" /></figure><h3>How to use it?</h3><p>To use Jenkins Job Runner, first you need to install:</p><pre>npm install jenkins jenkins-rxjs jenkins-jobs-runner</pre><p>Create an instance of Job Batch Runner:</p><pre><em>import </em>{ JenkinsRxJs } <em>from </em>&#39;jenkins-rxjs&#39;;<br><em>import </em>{ JobBatchRunner} <em>from </em>&#39;jenkins-jobs-runner&#39;;</pre><pre>const jenkinsRxJs = new JenkinsRxJs(...);<br>const jobBatchRunner = new JobBatchRunner(jenkinsRxJs);</pre><p>Prepare JobBatchDescriptor array:</p><pre>const jobBatchDescriptors = [<br>  {<br>    displayName: &#39;first group display name&#39;,<br>    jobDescriptor: [<br>      {<br>        displayName: &#39;first job of first group&#39;,<br>        opts: {<br>          name: &#39;jenkins-job-name&#39;,<br>          parameters: {<br>            firstParam: &#39;value-of-param&#39;<br>          }<br>        },<br>      },<br>      {<br>        displayName: &#39;second one&#39;,<br>        opts: { ... },<br>      },<br>    ],<br>  },<br>  {<br>    displayName: &#39;second group&#39;,<br>    jobDescriptor: [<br>      {<br>        displayName: &#39;only job of a second group&#39;,<br>        opts: { ... },<br>      },<br>    ],<br>  },<br>];</pre><p>Execute jobs:</p><pre>jobBatchRunner.runBatches(builderResult)<br>  .then(() =&gt; console.log(&#39;end&#39;));</pre><p>That is it. jobBatchRunner return a promise when finished should you want to do something afterward.</p><h3>Summary</h3><p>To summarise, <a href="https://www.npmjs.com/package/jenkins-jobs-runner">Jenkins Jobs Runner</a> can be used to execute and display a status of batches of parallel jobs. It takes single array input and handles calls to Jenkins API, updates status and the UI. This makes it easy to integrate it with any workflow.</p><p>As a part of a <a href="https://github.com/Bielik20/adeng-jenkins-cli">Jenkins CLI</a>, this lib handles jobs execution and displaying progress in the UI. This was the last part and concludes this series. Code of each part is available on GitHub to provide better insight.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=43e8fd81a195" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fandom-engineering/jenkins-jobs-runner-43e8fd81a195">Jenkins Jobs Runner</a> was originally published in <a href="https://medium.com/fandom-engineering">Fandom Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins RxJs]]></title>
            <link>https://medium.com/fandom-engineering/jenkins-rxjs-19e38dda331c?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/19e38dda331c</guid>
            <category><![CDATA[continuous-integration]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Tue, 20 Aug 2019 12:41:59 GMT</pubDate>
            <atom:updated>2019-08-20T12:41:59.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*9lyzqPsZkG7W-CzuJ98UGQ.png" /></figure><p>This article is part of the <a href="https://medium.com/fandom-engineering/jenkins-cli-4dfcee951e2a">Jenkins CLI series</a> in which we describe how we built CLI application for executing a series of parallel Jenkins Jobs in a terminal</p><p><a href="https://www.npmjs.com/package/jenkins-rxjs">Jenkins RxJs</a> is a small wrapper library on top of the <a href="https://www.npmjs.com/package/jenkins">Jenkins npm package</a> that can be used in CLI, node, or browser environment. It encapsulates the whole process of starting a job and tracking it in a quiet, queue and build states. The consumer of the library simply executes run command with job options and receives a stream of JobResponse objects.</p><h3>How it works?</h3><p>This diagram describes the entire process:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/0*7CgzFFsPAAcCE20f" /></figure><p>And JobReponse can be expressed in the following interfaces:</p><pre><em>type JobStatus </em>= &#39;FAILURE&#39; | &#39;SUCCESS&#39; | &#39;PROGRESS&#39;;</pre><pre><em>type JobResponse </em>= <em>JobProgress </em>| <em>JobDone</em>;</pre><pre><em>interface JobResponseBase </em>{<br>  name: <em>string</em>;<br>  url: <em>string</em>;<br>  text: <em>string</em>;<br>  status: <em>JobStatus</em>;<br>}</pre><pre><em>interface JobProgress extends JobResponseBase </em>{<br>  started: <em>number</em>;<br>  estimatedEnd: <em>number</em>;<br>  status: &#39;PROGRESS&#39;;<br>}</pre><pre><em>interface JobDone extends JobResponseBase </em>{<br>  id: <em>number</em>;<br>  status: &#39;FAILURE&#39; | &#39;SUCCESS&#39;;<br>}</pre><p>Since Jenkins exposes no socket connection to keep track of the current state of the job Jenkins RxJs does it by executing consecutive calls to Jenkins API. It uses estimatedEnd time at first and then every 15 seconds should the original estimate be exceeded.</p><h3>How to use it?</h3><p>To use Jenkins RxJS first you need to install Jenkins RxJS and original Jenkins library:</p><pre>npm install jenkins jenkins-rxjs</pre><p>Then create a Jenkins RxJs object:</p><pre><em>import </em>* <em>as </em>createJenkins <em>from </em>&#39;jenkins&#39;;<br><em>import </em>{ JenkinsRxJs } <em>from </em>&#39;jenkins-rxjs&#39;;</pre><pre>const jenkinsPromisified = createJenkins({<br>  baseUrl: <em>myJenkinsUrl</em>,<br>  promisify: true,<br>});<br>const jenkinsRxJs = new JenkinsRxJs(jenkinsPromisified);</pre><p>Finally, simply execute a job:</p><pre>jenkinsRxJs.run(jobBuildOptions).subscribe(console.log);</pre><p>Job Build Options are the same as the one in <a href="https://www.npmjs.com/package/jenkins">Jenkins npm package</a>:</p><pre><em>interface JobBuildOptions </em>{<br>    name: <em>string</em>;<br>    parameters?: <em>any</em>;<br>    token?: <em>string</em>;<br>}</pre><h3>Summary</h3><p>To summarise, <a href="https://www.npmjs.com/package/jenkins-rxjs">Jenkins RxJs</a> can be used both in web apps as well as CLI ones. With simple API it turns multistep Jenkins build process into a stream of simple JobResponse objects.</p><p>As a part of a <a href="https://github.com/Bielik20/adeng-jenkins-cli">Jenkins CLI</a> this lib handles communication with Jenkins API. The next and the last part is about actually executing jobs and displaying their status.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19e38dda331c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fandom-engineering/jenkins-rxjs-19e38dda331c">Jenkins RxJs</a> was originally published in <a href="https://medium.com/fandom-engineering">Fandom Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jenkins CLI]]></title>
            <link>https://medium.com/fandom-engineering/jenkins-cli-4dfcee951e2a?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/4dfcee951e2a</guid>
            <category><![CDATA[rxjs]]></category>
            <category><![CDATA[workflow]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[jenkins]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Fri, 28 Jun 2019 09:15:06 GMT</pubDate>
            <atom:updated>2019-09-30T11:59:16.444Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is a part of the series on creating this tool:</p><ul><li><a href="https://medium.com/fandom-engineering/jenkins-rxjs-19e38dda331c">Jenkins RxJs</a></li><li><a href="https://medium.com/fandom-engineering/jenkins-jobs-runner-43e8fd81a195">Jenkins Jobs Runner</a></li></ul><p>At Fandom, Ad Engineering process of testing and releasing our code can be complicated. We have our main library called ad-engine, and a number of platforms that we support. Whenever we change something in the ad-engine we need to:</p><ol><li>Update a version of the ad-engine in a given platform.</li><li>Deploy a given platform on a sandbox.</li><li>Run tests on a given sandbox.</li></ol><p>The process is cumbersome because we need to wait for each step to finish before we can proceed to the next one. Moreover, arguments for those jobs can be easily inferred from the context. That’s why we have introduced Jenkins CLI to combat those problems.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*EiG4vdjiAZl5B4razhIMbw.png" /></figure><h4>Input Arguments</h4><p>The first part of the CLI handles input arguments.</p><ul><li>First, it displays a multi-select list with tasks it can execute, then a multi-select list of project (platforms) to choose.</li><li>Then, it will try to guess a branch based on the repository in which you are when running the tool.</li><li>Sandbox is a single-select list with a default value that can be set in the tool.</li><li>Url params take a cache buster equal a current timestamp as a default value.</li><li>Test tab name is inferred from the branch name and user’s initials.</li></ul><p>Of course depending on jobs and projects you selected some of those questions may not appear, and there are also some hidden behind the--extended flag for advanced usage. The bottom line is that in most cases you need only to select jobs and platforms and the rest will be inferred based on the context.</p><h4>Concurrency</h4><p>The second part of the tool is actually executing jobs and providing feedback to the user as they go on. This part is way more sophisticated programmatically and I would like to dedicate to this issue two separate articles explaining how it works.</p><p>However, for now, let’s discuss it here in less detail anyway.</p><ul><li>update, deploy, test — are “Job Batches” or simply groups of jobs. Job Batches are executed sequentially, each awaiting preceding one to begin.</li><li>app, mobile-wiki, f2 — represent actual “Jobs” within a Job Batch. They are executed in parallel and once all are done, a Job Batch is considered done.</li></ul><p>So the tool is actually capable, at least in theory, of executing n number of Job Batches with m number of Jobs in them. To do so, one needs to provide input that can be described this way:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/0*jQoHhO8xY4xKQCmo" /></figure><h3>Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*4_7QAyeLiQXniWJa_YFTLA.gif" /></figure><p>Jenkins CLI has helped us speed up our workflow, and in incoming articles I will explain how it works under the hood, and how it can be incorporated into your workflow.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4dfcee951e2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/fandom-engineering/jenkins-cli-4dfcee951e2a">Jenkins CLI</a> was originally published in <a href="https://medium.com/fandom-engineering">Fandom Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Express Application on Firebase Hosting]]></title>
            <link>https://medium.com/mean-fire/express-application-on-firebase-hosting-5baa8914835f?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/5baa8914835f</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[firebasehosting]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[firebase]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Thu, 27 Jun 2019 19:13:15 GMT</pubDate>
            <atom:updated>2019-07-07T11:03:26.633Z</atom:updated>
            <content:encoded><![CDATA[<p>This is a short followup to <a href="https://medium.com/mean-fire/nx-nrwl-firebase-functions-98f96f514055">Nx Nrwl Firebase Function</a> article. It explains how to setup Firebase Hosting and Functions to host Node Application that serves an Angular App on Firebase Hosting.</p><h4>Setting firebase.json</h4><p>Edit firebase.json:</p><pre>{<br>  ...<br>  },<br>  &quot;hosting&quot;: {<br>    &quot;public&quot;: &quot;dist/apps/web-app&quot;,<br>    &quot;ignore&quot;: [&quot;firebase.json&quot;, &quot;**/.*&quot;, &quot;**/node_modules/**&quot;],<br>    &quot;rewrites&quot;: [<br>      {<br>        &quot;source&quot;: &quot;**&quot;,<br>        &quot;function&quot;: &quot;server&quot;<br>      }<br>    ]<br>  }<br>}</pre><ul><li>public — it is a path to your compiled angular application</li><li>rewrites — it tells to redirect all request to Firebase Function called “server”</li></ul><h4>Setting package.json</h4><p>Modify package.json script:</p><pre>&quot;firebase:serve&quot;: &quot;concurrently --kill-others \&quot;yarn run build functions --watch\&quot; \&quot;firebase serve --only functions,hosting\&quot;&quot;,</pre><h4>Setting functions</h4><p>In the Firebase Functions main file ( apps/function/src/main.ts) add:</p><pre><em>import </em>* <em>as </em>express <em>from </em>&#39;express&#39;;<br><em>import </em>* <em>as </em>functions <em>from </em>&#39;firebase-functions&#39;;<br><em>import </em>* <em>as </em>path <em>from </em>&#39;path&#39;;<br><br><em>const </em>app = express();<br>app.use(express.<em>static</em>(&#39;/../web-app&#39;));<br>app.get(&#39;*&#39;, (req, res) =&gt; res.sendFile(path.join(__dirname, &#39;/../web-app/index.html&#39;)));<br><br><em>export const </em>server = functions.https.onRequest(app);</pre><h3>Summary</h3><p>This covers simple scenario of having Node application serve Angular app. David may provide a more detailed explanation in <a href="https://www.youtube.com/watch?v=LOeioOKUKI8">this video</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5baa8914835f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mean-fire/express-application-on-firebase-hosting-5baa8914835f">Express Application on Firebase Hosting</a> was originally published in <a href="https://medium.com/mean-fire">MEAN Fire</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nx Nrwl Ionic]]></title>
            <link>https://medium.com/mean-fire/nx-nrwl-ionic-1baf3a43db74?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/1baf3a43db74</guid>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[nrwl]]></category>
            <category><![CDATA[angular]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Wed, 01 May 2019 14:58:09 GMT</pubDate>
            <atom:updated>2019-05-18T10:25:30.130Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post I will explain how to setup Ionic App in Nrwl Workspace. It is easier than it may seem.</p><h3>Initialise Ionic</h3><p>Make sure you have ionic CLI installed yarn global add ionic.</p><pre>ionic init --type=angular<br><br>ng g app ionic-app --style=scss --unit-test-runner=jest --e2e-test-runner=cypress --routing --prefix=app<br><br>yarn add @ionic-native/core @ionic-native/http @ionic-native/splash-screen @ionic-native/status-bar @ionic/angular<br>yarn add @ionic/angular-toolkit -D</pre><p>This will install required dependencies and create an angular app that we will replace with ionic implementation.</p><p>Changes introduced in <a href="https://github.com/Bielik20/nx-mean-starter/commit/aacbfa66dbd6465a0e0087fe6dcccd1b805619c3">this commit</a> cover that:</p><ul><li>replaces default app generated by angular with one produced with ionic start</li><li>modifies angular.json to reflect one from ionic start</li><li>modifies tslint.json to allow components with “Page” suffix</li></ul><h3>Add Capacitor</h3><pre>yarn add @capacitor/cli @capacitor/core<br>npm run build --prod ionic-app</pre><p>Now initialise app with “app name” and “bundle id”:</p><pre>npx cap init &lt;name&gt; &lt;id&gt;</pre><p>You can read more about Bundle Identifiers in <a href="https://cocoacasts.com/what-are-app-ids-and-bundle-identifiers/">here</a>. For me it is:</p><pre>npx cap init &quot;Nx MEAN Starter&quot; bielik.nx.mean.starter</pre><p>Now edit capacitor.config.json so that value of webDir field equals dist/apps/ionic-app. It tells capacitor where to look for compiled app.</p><h4>Add iOS</h4><pre>npx cap add ios<br>npx cap sync<br>npx cap open ios</pre><p>Then in Xcode go to general -&gt; signing -&gt; team and choose team.</p><h4>Run new version of app on iOS simulator</h4><pre>npm run build --prod ionic-app<br>npx cap sync<br>npx cap open ios</pre><p>Then choose desired device and click run.</p><h3>Summary</h3><p>That is all there is to it. Source code for this can be found in <a href="https://github.com/Bielik20/nx-mean-starter">here</a>. However it is actively developed so if you want to review THIS version, checkout <a href="https://github.com/Bielik20/nx-mean-starter/tree/93850e2733c4eeeb40eb85b3921eb08e76fccf69">this commit</a>.</p><h4>Appendix: Fixing specs</h4><p>If you encounter beloved bug SyntaxError: Unexpected token import while running tests you can fix that by applying <a href="https://stackoverflow.com/a/56198039/4746094">my answer from stack-overflow</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1baf3a43db74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mean-fire/nx-nrwl-ionic-1baf3a43db74">Nx Nrwl Ionic</a> was originally published in <a href="https://medium.com/mean-fire">MEAN Fire</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Nx Nrwl Firebase Functions]]></title>
            <link>https://medium.com/mean-fire/nx-nrwl-firebase-functions-98f96f514055?source=rss-43a17ec832bc------2</link>
            <guid isPermaLink="false">https://medium.com/p/98f96f514055</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[firebase-cloud-functions]]></category>
            <category><![CDATA[nrwl-nx]]></category>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[firebase]]></category>
            <dc:creator><![CDATA[Damian Bielecki]]></dc:creator>
            <pubDate>Thu, 21 Feb 2019 17:13:10 GMT</pubDate>
            <atom:updated>2020-02-10T07:31:07.551Z</atom:updated>
            <content:encoded><![CDATA[<p>Since Nrwl released its <a href="https://blog.nrwl.io/building-full-stack-applications-using-angular-cli-and-nx-5eff205248f1">support</a> for node applications I was looking forward to similar support for Firebase Functions. I have even created an <a href="https://github.com/nrwl/nx/issues/836">issue on GitHub</a> for that. At the time of writing it is still open, that’s why I have decided to create my own solution.</p><h3>The problem</h3><p>When you initialise Firebase Functions withfirebase init it creates functions subdirectory with its own package.json and node_modules. That is not good. We want to share code with functions and manage it using Nx.</p><h3>Goal</h3><ul><li>Firebase Functions exist as a node app</li><li>There is only one package.json and node_modules</li><li>Functions can use shared code fromlibs</li></ul><h3>Prerequisites</h3><p>We assume you have a working Nrwl Project with Angular application. It is also recommended that you have Firebase account and understand what Firebase Functions are.</p><h3>Solution</h3><h4>Setup Firebase</h4><p>If you haven’t already, install firebase-tools and login:</p><pre>yarn global add firebase-tools<br>firebase login</pre><p>Also add .firebaserc in the root dir to make it a Firebase project:</p><pre>{<br>  &quot;projects&quot;: {<br>    &quot;default&quot;: &quot;your-firebase-project-name&quot;<br>  }<br>}</pre><h4>Generate node-app</h4><p>As stated in goal, Functions are to be based on node-app. To do so, create node-app named “functions”:</p><pre>ng add @nrwl/node # Adds Node capabilities<br>ng g @nrwl/node:application functions</pre><h4>Configure Firebase Functions</h4><p>Install Firebase Functions dependencies</p><pre>yarn add firebase firebase-admin firebase-functions</pre><p>Replace contents of apps/functions/src/main.ts with:</p><pre>import * as functions from &#39;firebase-functions&#39;;<br><br>// // Start writing Firebase Functions<br>// // https://firebase.google.com/docs/functions/typescript<br>//<br>export const helloWorld = functions.https.onRequest((request, response) =&gt; {<br>  response.send(&#39;Hello from Firebase!&#39;);<br>});</pre><p>Above snippet is what Firebase generates when using firebase init.</p><p>To setup Firebase Functions so that they are understood create firebase.json in the root directory:</p><pre>{<br>  &quot;functions&quot;: {<br>    &quot;predeploy&quot;: [<br>      &quot;yarn lint functions&quot;,<br>      &quot;yarn build functions --prod&quot;<br>    ],<br>    &quot;source&quot;: &quot;/&quot;<br>  }<br>}</pre><ul><li>predeploy just defines what is fired when you issue command firebase deploy --only functions. In this case it will run linter and production build for our “functions” project.</li><li>source points to the root of the project. Since we have only one package.json and it is in the root directory it needs to point there.</li></ul><p>In package.json add following:</p><pre>&quot;main&quot;: &quot;dist/apps/functions/main.js&quot;,<br>&quot;engines&quot;: {<br>  &quot;node&quot;: &quot;10&quot;<br>},</pre><ul><li>main is required so that Firebase knows what to start after deployment. I have created a feature request to move it to firebase.json but at the time of writing it needs to be there.</li><li>engine is telling Firebase on which node version it should be run. At the time of writing node v10 is the newest supported. Also you CANNOT specify yarn or npm version in here because it will conflict with firebase.</li></ul><h3>Usage</h3><p>Serving Firebase Functions is a little more complicated than typical node app. Add this dev dependancy:</p><pre>yarn add concurrently -D</pre><p>And these scripts to package.json:</p><pre>&quot;firebase:serve&quot;: &quot;concurrently --kill-others \&quot;yarn run build functions --watch\&quot; \&quot;firebase serve --only functions\&quot;&quot;,<br>&quot;firebase:shell&quot;: &quot;concurrently --kill-others \&quot;yarn run build functions --watch\&quot; \&quot;firebase functions:shell\&quot; --raw&quot;,<br>&quot;firebase:deploy&quot;: &quot;firebase deploy&quot;,</pre><ul><li>yarn firebase:serve - run functions locally</li><li>yarn firebase:shell - run functions shell locally</li><li>yarn firebase:deploy --only functions - deploy functions</li></ul><h4>Explanation</h4><p>At the time of writing firebase serve serves functions only from dist directory. To make it work we use concurrently to run build with watch flag, and serve “concurrently”.</p><h3>Summary</h3><p>This pretty much covers it. Easy and elegant way to incorporate Firebase Functions into Nx project. Source code for this can be found in <a href="https://github.com/Bielik20/nx-mean-starter">here</a>. However it is actively developed so if you want to review THIS version, checkout <a href="https://github.com/Bielik20/nx-mean-starter/tree/40d1441166f1d6203129dc81283b7c9b1b489980">this commit</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98f96f514055" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mean-fire/nx-nrwl-firebase-functions-98f96f514055">Nx Nrwl Firebase Functions</a> was originally published in <a href="https://medium.com/mean-fire">MEAN Fire</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>