<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Edvins Antonovs 🚀🦄</title>
    <description>The latest articles on DEV Community by Edvins Antonovs 🚀🦄 (@edvinsantonovs).</description>
    <link>https://dev.to/edvinsantonovs</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F7155%2F12a4e37a-d09a-4001-8d1d-4f30681e7c55.jpg</url>
      <title>DEV Community: Edvins Antonovs 🚀🦄</title>
      <link>https://dev.to/edvinsantonovs</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/edvinsantonovs"/>
    <language>en</language>
    <item>
      <title>🚀 How to deploy and build a static website to Heroku</title>
      <dc:creator>Edvins Antonovs 🚀🦄</dc:creator>
      <pubDate>Sat, 16 Sep 2017 09:25:08 +0000</pubDate>
      <link>https://dev.to/edvinsantonovs/-how-to-deploy-and-build-a-static-website-to-heroku</link>
      <guid>https://dev.to/edvinsantonovs/-how-to-deploy-and-build-a-static-website-to-heroku</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;It's not a trivial tutorial, but rather a story how I was able to build &amp;amp; deploy my static website to Heroku. &lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;Recently I was working on a side project, it was a landing page for an online hackathon platform called &lt;a href="http://www.hackerhype.com/" rel="noopener noreferrer"&gt;&lt;strong&gt;Hacker Hype&lt;/strong&gt;&lt;/a&gt;. This time I wanted to switch from &lt;strong&gt;DigitalOcean&lt;/strong&gt; and give &lt;strong&gt;Heroku&lt;/strong&gt; a try. I have previously been using Heroku to deploy my open source stuff, so I had a feeling that it should not be that hard to deploy a simple static page. Okay, maybe I spoke too soon, but it took me some time before I accomplished it.&lt;/p&gt;




&lt;p&gt;First of all, I hosted the source code on my private repository on a &lt;strong&gt;GitHub&lt;/strong&gt;. In case you haven't used Heroku, it has a dead simple feature which allows you to orchestrate a deployment directly every time you push something to the repository.&lt;/p&gt;

&lt;p&gt;In the repository I have 2 branches &lt;code&gt;master&lt;/code&gt; and &lt;code&gt;develop&lt;/code&gt;, obviously. I used &lt;code&gt;master&lt;/code&gt; branch for automatic deploys. So every time I was finishing something, all I've needed is to merge &lt;code&gt;develop&lt;/code&gt; to &lt;code&gt;master&lt;/code&gt;. Okay, at this stage I have setup everything I needed to have my development workflow going.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fedvinsantonovs.co.uk%2Fcontent%2Fimages%2F2017%2F08%2Fdeploy.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fedvinsantonovs.co.uk%2Fcontent%2Fimages%2F2017%2F08%2Fdeploy.PNG"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Next step was to actually be able to build the &lt;code&gt;scss&lt;/code&gt; and &lt;code&gt;js&lt;/code&gt; files into the production-ready project using &lt;code&gt;Gulp&lt;/code&gt;. From there I would need to configure &lt;a href="https://github.com/indexzero/http-server" rel="noopener noreferrer"&gt;&lt;code&gt;http-server&lt;/code&gt;&lt;/a&gt; in Heroku's &lt;code&gt;Procfile&lt;/code&gt; to serve my static files. This part took me a bit of the time to figure out. Configuring &lt;code&gt;Procfile&lt;/code&gt; was the actual challenge. I even posted a &lt;a href="https://stackoverflow.com/questions/44733986/how-to-run-procfile-with-multiple-commands-on-heroku/44735878#44735878" rel="noopener noreferrer"&gt;question on StackOverflow&lt;/a&gt; as I was confused how I can run multiple commands in a &lt;code&gt;Procfile&lt;/code&gt; for Heroku.&lt;/p&gt;

&lt;p&gt;So in order to build the project, I've required next commands to be executed &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;npm install&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;gulp build&lt;/code&gt; &lt;small&gt;(will generate the &lt;code&gt;/public&lt;/code&gt; folder)&lt;/small&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;http-server&lt;/code&gt; &lt;small&gt;(will serve &lt;code&gt;/public&lt;/code&gt; folder by default)&lt;/small&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've tried several ways of configuring &lt;code&gt;Procfile&lt;/code&gt;, yet nothing worked for me.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;web: npm install; gulp build; http-server&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;web: npm install &amp;amp; gulp build &amp;amp; http-server&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I've spent a bit of time researching and came up with the answer. By default, Heroku is installing all packages from the &lt;code&gt;package.json&lt;/code&gt;, so &lt;code&gt;npm install&lt;/code&gt; is no longer required. Then I needed to run &lt;code&gt;gulp build&lt;/code&gt; and &lt;code&gt;http-server&lt;/code&gt;. For that I've added &lt;code&gt;"postinstall" : "gulp build"&lt;/code&gt; to &lt;code&gt;package.json&lt;/code&gt; so my &lt;code&gt;Procfile&lt;/code&gt; was a one line file with just one command - &lt;code&gt;web: http-server&lt;/code&gt;. Simplifying things have solved the problem! Now I was able to deploy and build my static website on Heroku! 🎉🎉🎉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fedvinsantonovs.co.uk%2Fcontent%2Fimages%2F2017%2F08%2Fhackerhype.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Fedvinsantonovs.co.uk%2Fcontent%2Fimages%2F2017%2F08%2Fhackerhype.PNG"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;Let's summarise the process. I have a static website and its files are compiled via gulp. Then Heroku’s &lt;code&gt;Procfile&lt;/code&gt; is configured in order to serve static &lt;code&gt;html&lt;/code&gt;/&lt;code&gt;css&lt;/code&gt;/&lt;code&gt;js&lt;/code&gt; files using &lt;code&gt;http-server&lt;/code&gt;. This results in a nicely synchronised development and deployment flow.&lt;/p&gt;




&lt;p&gt;Originally posted on &lt;a href="http://edvinsantonovs.co.uk/how-to-deploy-and-build-a-static-website-to-heroku/" rel="noopener noreferrer"&gt;my blog&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>deployment</category>
      <category>heroku</category>
      <category>httpserver</category>
    </item>
  </channel>
</rss>
