# Deploying Vue.js Applications built with Webpack to Heroku

Source: https://www.ironin.it/blog/deploying-vuejs-applications-build-with-webpack-to-heroku.html

Published 17 August 2017

[web](https://www.ironin.it/blog/tags/web) [front-end development](https://www.ironin.it/blog/tags/front-end-development) [devops](https://www.ironin.it/blog/tags/devops) [vue](https://www.ironin.it/blog/tags/vue) [heroku](https://www.ironin.it/blog/tags/heroku) [javascript](https://www.ironin.it/blog/tags/javascript)

![Deploying Vue.js Applications built with Webpack to Heroku](https://www.ironin.it/api/media/file/ironin-seed-YjA1ZTYxNzgtNWMzZS00NWIwLTkyNGItYjhhNWEzMjM4M2M3_blog-img24.jpg)

Built your interactive [web application using Vue.js](https://www.ironin.it/services/vue-js-development) with Webpack and wondering how to deploy it? We explain how to deploy Vue.js Single Page Applications to Heroku.

In today’s post we will explain how to deploy [Vue.js Single Page Applications](https://v1.vuejs.org/guide/application.html) built with [Webpack](https://github.com/vuejs-templates/webpack) to [Heroku](https://www.heroku.com/). As you may remember, we already described [how we develop Single Page Applications with Vue.js](https://www.ironin.it/blog/single-page-applications-with-vue-js.html), and this post is a continuation of this subject, focusing on the deployment phase. At the time of writing, Heroku does not have an official Vue.js buildpack so we need to rely on a custom one.

First, let’s share a few choice words about Webpack and why it is so beneficial to build your Vue.js SPA with it. WebPack is a module bundler, that takes an application’s files and bundles them into static assets, which then can be served to, and displayed by the browser. It respects all the dependencies between files and has a plugin system, which allows us to extend its functionality to support new preprocessor languages, JavaScript features (through [babel](https://babeljs.io/)) and more.

## Requirements

Before we deploy the app we need to ensure that we have the following utilities:

- [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli)
- [gnu tar](https://www.gnu.org/software/tar/)
- [heroku-builds plugin](https://github.com/heroku/heroku-builds)

If you are on OS X you can install all dependencies with a single command:

```bash
brew install heroku gnu-tar && heroku plugins:install heroku-builds
```

## Configuring the application

In this article we assume the app uses [Webpack template](https://github.com/vuejs-templates/webpack) for [vue-cli](https://github.com/vuejs/vue-cli).

### Ignoring dist directory in git

Since we are going to deploy the `dist` folder directly to Heroku, we need to make sure all files in that directory, except `package.json` and `server.js`, are ignored from our git repository in order to avoid conflicts and unnecessary diffs in pull requests.

We can do this easily by creating a `dist/.gitignore` file with the following content:

```bash
*
!.gitignore
!package.json
!server.js
```

### Preparing for distribution

Because we are going to use [Express](https://expressjs.com/) to serve static files we need a minimal `package.json` manifest (in `dist/package.json` directory):

```json
{
  "name": "your-project",
  "version": "1.0.0",
  "description": "Your project description",
  "author": "Your name",
  "private": true,
  "scripts": {
    "postinstall": "npm install express"
  }
}
```

This basically instructs [Heroku Node.js buildpack](https://github.com/heroku/heroku-buildpack-nodejs) to install the `express` package as the part of the deployment.

We also need a very simple app to serve our Vue.js application’s files:

```javascript
// dist/server.js
var express = require('express');
var path = require('path');
var serveStatic = require('serve-static');
app = express();
app.use(serveStatic(__dirname));
var port = process.env.PORT || 5000;
app.listen(port);
console.log('server started '+ port);
```

### Adding Heroku git remote

We need to add Heroku as another git remote for our project repository so we are able to get the application’s name in the deployment script below.

```bash
git remote add heroku https://git.heroku.com/your-app-name.git
```

## Creating the deployment script

Since we want to automate deployment as much as possible in order to make the process easier and less error-prone, we are going to create a deployment script that will push the application to Heroku with a single command (eg. `deploy.sh`):

```bash
#!/usr/bin/env bash
app_name=$(heroku apps:info | grep === | awk '{print $2}')
version=$(git rev-parse HEAD)
npm run build
$(cd dist && heroku builds:create --version "${version}" -a ${app_name} --tar $(which gtar))
```

These few lines of code get Heroku’s application name, assign a new version (based on the current git revision), build the app and upload it to Heroku.

## Deploying the Vue app to Heroku

All we need to run is the deployment script:

```bash
./deploy.sh
```

Voila! The Vue app should be now deployed to Heroku.

## Summary

With this step-by-step process, we are able to easily deploy Vue.js apps to Heroku without an official buildpack. Should you have any problems with your current deployment process or not trust that Heroku is fit for your web apps, feel free to contact us and we we will be happy to help you find the best option to host and deploy your applications.

Share:

Author: iRonin IT Team

Need software like this built?

[Software development →](https://www.ironin.it/ai-software-engineering)

Our code is merged into 10 open-source AI-agent projects, two of them with tens of thousands of GitHub stars.

[Talk to us →](https://www.ironin.it/contact-us.html?offer=ai-software-engineering)

## Read similar articles

- [OS Time Travel When Testing Ruby on Rails Web Applications For System-Wide Time Events](https://www.ironin.it/blog/os-time-travel-when-testing-ruby-on-rails-web-applications-for-system-wide-time-events.html)
- [Preact - React-Compatible, Smaller, Faster Framework](https://www.ironin.it/blog/preact-react-compatible-smaller-faster-framework.html)
- [Sending Logs From Your Heroku App to Datadog](https://www.ironin.it/blog/sending-logs-from-your-heroku-app-to-datadog.html)
- [GraphQL Part #2 - Creating an API with Node.js Using GraphQL](https://www.ironin.it/blog/creating-an-api-with-nodejs-using-graphql.html)

## Read next

- [Is this the cryptopocalypse? Who needs to act on post-quantum cryptography now](https://www.ironin.it/blog/post-quantum-cryptography-who-must-act-now.html)
- [Which AI model is best for your own task? Our own test and a public leaderboard disagreed](https://www.ironin.it/blog/own-ai-model-evals.html)
- [What uses up a Claude plan's usage limit? What each kind of token costs against it](https://www.ironin.it/blog/claude-usage-limit-token-costs.html)
