Auto-Deploy React & Vue Apps with Heroku
Tags: vue, react, heroku
Published: 2023-08-06 15:23:17

> This article assumes you have basic knowledge of React or Vue.js. All the procedures here work for both React and Vue.js applications.

Deploying Frontend Javascript applications with Heroku is a breeze, to say the least. This is mostly because Heroku takes away all of the hassles involved in the setup and just lets you deploy. Of course, this is different when you need to deploy backend applications, as you’d be required to provision a database where applicable and include the credentials in environment variables. Thankfully, we don’t have to worry about any of those when deploying frontend applications…oh, unless you’re using environment variables within your frontend app, you’d need to set them on Heroku as well.

## Getting Started

Requirements:

- Node.js set up

- [Heroku](https://heroku.com/) Account

- [Github](https://github.com/) Account

I’ll assume you already have a React or Vue project you want to deploy. For this example, I’ll use a React project I’d previously created. First, make sure you have a Github account. You’d need to make a commit and push your code to Github:

```bash
git add . && git commit "initial commit" && git push origin master
```

Next, create an account on Heroku if you don’t already have one, and add a new app:


![Add New App](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsjh4sj9eqbxljglmnk9.png)

You’ll be required to put in a name and select a region. You can give the app whatever name you want. Feel free to leave the region like that or select a region close to your primary users.


![Name App](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jvlu9r36znhcfyveye6x.png)

Once you have all the requirements set, click “Create app”. This should create your application and show you the deploy tab, where you can choose how you want to deploy your application.


![Create App](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oaerri1o88twjmmmn8w0.png)

At this point, Heroku doesn’t know the kind of application you intend to deploy, but it is smart enough to figure it out once we select a repository. Under the “Deployment Method” section, you have “Heroku Git” selected by default. Change this to “Github”. You’d need to search for the repository you pushed your code to:


![Repository find](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c8vkwxf5n9pmtr5aur4j.png)

Once Heroku finds it, click “Connect”. Heroku would link this repository to the Heroku app. In the next section, you’ll be prompted to set up automatic deploys from Github.


![Automatic deploys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kc46eimwx69l0qnv4l5n.png)


As stated, every push you make to the specified branch will trigger a new build and deployment. We’ll leave the selected branch as “master” (Change it if you want something else). Then click the “Enable Automatic Deploys” button.


![Enable deploys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lw8smva1j6eum1vsm941.png)

Finally, you trigger a manual deployment in the next section:


![Manual deployment](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/stuyuebqqltj1uk8qb02.png)

Click on “Deploy Branch”, and Heroku should handle the rest from there. Once the deployment is complete, you should see a “view” button at the bottom; click this button to view your application.


![Deploy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gvfwdka65jrfzrajhwx.png)

You should see your application on a unique URL.


![Unique URL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tzk4k8wi5jwnh1zpphjg.png)

Now every time you push a new change to your master branch, Heroku listens for updates on that branch and will automatically rebuild your application to serve the latest build.

You can test this out by updating the App.js file and pushing that update to the master branch on Github. In your Heroku dashboard, you should now see a new build is in progress.


![Heroku dashboard](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1fksd8in3zun8d5sofuu.png)

Once that’s done, you should see the updates you made on your site.


![View site updates](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/om1jhafki1yjug7pc51i.png)

---

Hopefully, this has helped someone.

Cheers ☕️

---