<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jascha Burmeister</title>
    <description>The latest articles on Forem by Jascha Burmeister (@jaschabur).</description>
    <link>https://forem.com/jaschabur</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%2F175059%2Ff3b50d33-4138-438a-a55d-e649ab909ac1.jpg</url>
      <title>Forem: Jascha Burmeister</title>
      <link>https://forem.com/jaschabur</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jaschabur"/>
    <language>en</language>
    <item>
      <title>Build and deploy static Vue/React SPA on Dokku</title>
      <dc:creator>Jascha Burmeister</dc:creator>
      <pubDate>Sun, 20 Oct 2019 07:16:31 +0000</pubDate>
      <link>https://forem.com/jaschabur/build-and-deploy-static-vue-react-spa-on-dokku-6jj</link>
      <guid>https://forem.com/jaschabur/build-and-deploy-static-vue-react-spa-on-dokku-6jj</guid>
      <description>&lt;p&gt;In this post I will show you how to build and deploy a static Vue/React Single Page Application on Dokku with the help of multiple buildpacks.&lt;/p&gt;

&lt;p&gt;I have seen several posts where people build on their local machine, commit the /dist folder changes into their repo and push the changes to their dokku instance. This does work but adds unnecessary commits to your repository and I think running the build process on the server is a much cleaner solution.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up Dokku
&lt;/h1&gt;

&lt;p&gt;I do not want to go into detail as the process of installing Dokku is well described in the official docs &lt;a href="http://dokku.viewdocs.io/dokku/getting-started/installation/"&gt;http://dokku.viewdocs.io/dokku/getting-started/installation/&lt;/a&gt; and can even be simpler when using 1-click Dokku setup on DigitalOcean.&lt;/p&gt;

&lt;p&gt;Create a new app&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dokku apps:create my-awesome-app
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Buildpacks
&lt;/h1&gt;

&lt;p&gt;Add a .buildpacks file to the root of your project. As you can see, we are using two buildpacks. The first one is to build our production code (dist folder output) and the second one is for our static hosting. The version numbers can be found on the releases page on Github and are recommended to add.&lt;/p&gt;

&lt;p&gt;.buildpacks&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;https://github.com/heroku/heroku-buildpack-nodejs.git#v164
https://github.com/heroku/heroku-buildpack-static.git#v3
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Build config
&lt;/h1&gt;

&lt;p&gt;To build our application on the server we have to add this command to the scripts section of our package.json file.&lt;/p&gt;

&lt;p&gt;package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "scripts": {
    "heroku-postbuild": "npm run build"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Static config
&lt;/h1&gt;

&lt;p&gt;Our static buildpack does allow us to add some configurations described &lt;a href="https://github.com/heroku/heroku-buildpack-static"&gt;here&lt;/a&gt;. As we want to serve our /dist folder, we add it to the static.json file alongside the option of serving clean urls and our default index.html.&lt;/p&gt;

&lt;p&gt;static.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "root": "dist/",
  "clean_urls": true,
  "routes": {
    "/**": "index.html"
  }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Deploy our app
&lt;/h1&gt;

&lt;p&gt;As we do not want to track any dist folder changes, we add it to our .gitignore file.&lt;/p&gt;

&lt;p&gt;.gitignore&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# ...
/dist
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Commit all changes and run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add dokku dokku@your-server-ip:my-awesome-app
git push dokku master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h1&gt;
  
  
  Done
&lt;/h1&gt;

&lt;p&gt;Voilà, your static app is built and served by Dokku.&lt;/p&gt;

</description>
      <category>dokku</category>
      <category>javascript</category>
      <category>vue</category>
      <category>react</category>
    </item>
  </channel>
</rss>
