<?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 Aldo Román Nureña on Medium]]></title>
        <description><![CDATA[Stories by Aldo Román Nureña on Medium]]></description>
        <link>https://medium.com/@aldoroman?source=rss-630b4f6165b7------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*CdmIzga26Npu5EkoAZVItQ.jpeg</url>
            <title>Stories by Aldo Román Nureña on Medium</title>
            <link>https://medium.com/@aldoroman?source=rss-630b4f6165b7------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 21:18:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aldoroman/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[Deploy Angular apps with ES2015, today]]></title>
            <link>https://medium.com/@aldoroman/no-more-es5-only-angular-apps-on-prod-b56422de324e?source=rss-630b4f6165b7------2</link>
            <guid isPermaLink="false">https://medium.com/p/b56422de324e</guid>
            <category><![CDATA[angular]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Aldo Román Nureña]]></dc:creator>
            <pubDate>Tue, 14 Nov 2017 20:00:08 GMT</pubDate>
            <atom:updated>2017-11-17T03:09:32.525Z</atom:updated>
            <content:encoded><![CDATA[<p>Every decent browser now supports ES2015.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*edOs8t916euOqjdPkOFNhw.png" /><figcaption>ES2015 browser support</figcaption></figure><p>A few months ago, we ran into <a href="https://kangax.github.io/compat-table/es6/">this fact</a> and wondered why we were still publishing ES5-only production apps. We noticed we were <a href="https://philipwalton.com/articles/deploying-es2015-code-in-production-today/">not the first</a>. We noticed it was worth the energy. We noticed our customers deserved it. So we went onto the challenge of <strong>publishing an ES2015 Angular app</strong>.</p><p>Not until recently, the biggest problem was that Angular CLI was not able to bundle ES2015 for production targets (<a href="https://github.com/angular/angular-cli/issues/2907">and community was involved</a>). But this finally arrived with <strong>Angular 5</strong> and <strong>Angular CLI 1.5</strong>.</p><h4>The easy part, bundling ES2015</h4><p>Compiling the app to ES2015 was as easy as <strong>telling Typescript to do so</strong>. If your app supports only modern browsers, then you are done with this:</p><pre><em>tsconfig.app.json (extract)</em></pre><pre>{<br>  &quot;extends&quot;: &quot;../tsconfig.json&quot;,<br>  &quot;compilerOptions&quot;: {<br><strong>    &quot;module&quot;: &quot;es2015&quot;,<br>    &quot;target&quot;: &quot;es2015&quot;</strong><br>  }<br>}</pre><h4>Support for IE</h4><p>Sadly, our app must run on IE11 as well, so we cannot delete every trace of ES5 just yet. Our approach is to <strong>generate “two apps” from the same source code</strong>, given the Angular CLI kindly supports it. Have a look:</p><pre><em>.angular-cli.json (extract)</em></pre><pre>{<br>  &quot;project&quot;: {<br>    &quot;name&quot;: &quot;angular-es2015-prod-app&quot;<br>  },<br>  &quot;apps&quot;: [<br>    {<br>      &quot;root&quot;: &quot;src&quot;,<br>      &quot;outDir&quot;: &quot;dist&quot;,<br>      <strong>&quot;index&quot;: &quot;index.html&quot;,</strong><br>      &quot;main&quot;: &quot;main.ts&quot;,<br>      <strong>&quot;polyfills&quot;: &quot;polyfills.ts&quot;,</strong><br>      <strong>&quot;tsconfig&quot;: &quot;tsconfig.app.json&quot;</strong><br>    },<br>    {<br>      &quot;root&quot;: &quot;src&quot;,<br>      &quot;outDir&quot;: &quot;dist&quot;,<br>      <strong>&quot;index&quot;: &quot;index.legacy.html&quot;,</strong><br>      &quot;main&quot;: &quot;main.ts&quot;,<br>      <strong>&quot;polyfills&quot;: &quot;polyfills.legacy.ts&quot;,</strong><br>      <strong>&quot;tsconfig&quot;: &quot;tsconfig.app.legacy.json&quot;</strong><br>    }<br>  ]<br>}</pre><p>To summarize, <strong>we have a default app with ES2015 and a “legacy” app with ES5</strong>. We use separate tsconfig, polyfills and index.html for each app.</p><p>The building step generates both apps within the same directory:</p><pre><em>package.json (extract)</em></pre><pre>{<br>  &quot;name&quot;: &quot;angular-es2015-prod-app&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;ng serve <strong>--app=0</strong>&quot;,<br>    &quot;start:legacy&quot;: &quot;ng serve <strong>--app=1</strong> --port=4300&quot;,<br>    <strong>&quot;build:prod:modern&quot;</strong>: &quot;ng build --prod <strong>--app=0</strong>&quot;,<br>    <strong>&quot;build:prod:legacy&quot;</strong>: &quot;ng build --prod <strong>--app=1</strong>&quot;,<br>    <strong>&quot;build:prod&quot;</strong>: &quot;npm run build:prod:modern &amp;&amp; npm run build:prod:legacy -- --no-delete-output-path&quot;,<br>  },<br>}</pre><h4>Deployment</h4><p>How do we load each on the correct browser? The ideal case would be to have only one index.html file and make use of <a href="https://jakearchibald.com/2017/es-modules-in-browsers/">ECMAScript modules on the browser</a>. That would require no more tricks. We couldn’t find a way to get there yet with the CLI.</p><p>As we couldn’t wait for it, we decided to have <strong>two separate </strong><strong>index.html files</strong>, one for each app. We serve the browser the correct one <strong>depending on the User-Agent</strong> string. Say, this is a config for an <strong>Apache web server</strong>:</p><pre><em>.htaccess (</em><a href="https://angular.io/guide/deployment#routed-apps-must-fallback-to-indexhtml"><em>Based on Angular docs</em></a><em>)</em></pre><pre>RewriteEngine On<br><em># If an existing asset or directory is requested go to it as it is<br></em>RewriteCond %{REQUEST_URI} !^/index.html$<br>RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]<br>RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d<br>RewriteRule ^ - [L]<br><em># If the requested resource doesn&#39;t exist, use index.html</em><br>RewriteRule ^ /index.html<br><br><strong><em># If IE is detected, serve legacy version</em></strong><em><br></em><strong>RewriteCond %{HTTP_USER_AGENT} Trident<br>RewriteRule ^ /index.legacy.html</strong></pre><p>And… that’s it!</p><h4>Results</h4><p>We tested an app with on ~80 components and ~20K LOC. On the <strong>main.js</strong> file, we got <strong>~10% downsize (parsed)</strong> and <strong>~6% downsize (gzipped)</strong>, almost for free.</p><h4>One caveat… the unit testing</h4><p>There is only one issue right now. The default CLI + Karma setup cannot run ES2015 testing.</p><p>For now, the <strong>workaround</strong> is to run unit tests only over the ES5 app:</p><pre><em>package.json (extract)</em></pre><pre>{<br>  // ...<br>  &quot;scripts&quot;: {<br>    &quot;test&quot;: &quot;ng test <strong>--app=1</strong>&quot;<br>  }<br>}</pre><h4>Let’s make it happen!</h4><p>Get the sources for an Angular ES2015 prod app <a href="https://github.com/aldo-roman/angular-es2015-prod-app">here</a> <em>(coming soon… sorry!)</em>.</p><p>So! Give it a try and tell us…</p><p><strong>What are your results?</strong></p><p><strong>What would you improve on this approach?</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b56422de324e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>