Getting started with goBuffalo and Vue.js

This is the first part of a guide intended to assist in start a new Vue.js project ontop of Buffalo. In this first part we will integrate Vue.js into the Buffalo asset pipeline, adjust the tests and create a base to begin development upon in the next post.


  • Install Golang
  • Install Buffalo
  • Install Postgresql
  • Install Docker
  • Install Vue/cli


Generate application

# Generate a buffalo app
buffalo new myapp && cd myapp
# Generate pop config
buffalo pop g config
# Create databases with pop
buffalo pop create -a

If the pop commands fail and you have postgresql installed and running you likely have not granted the proper permissions. You will need to adjust the pg_hba.conf file to fit your scenario.

Integrating Vue.js into Buffalo asset pipeline

The Buffalo asset pipeline is just webpack. So we’re going to simply apply a manual setup of vue-loader.

# sudo yarn global add @vue/cli
yarn add vue vue-loader vue-router vue-template-compiler

Modify webpack.config.js

The resolve alias is for cleaner import statements in our application.js file later on.

// ...
const VueLoaderPlugin = require('vue-loader/lib/plugin');
// ...

const configurator = {
  // ...
  plugins() {
    var plugins = [
      // ...
      new VueLoaderPlugin(),
      // ...
    // ...
  // ...
  moduleOptions: function() {
    return {
      rules: [
        // ...
        { test: /\.vue/, loader: "vue-loader" },
        // ...
  // ...
  buildConfig: function(){
    // ...
    var config = {
      // ...
      resolve: {
        // ...
        alias: {
          vue$: `${__dirname}/node_modules/vue/dist/vue.esm.js`,
          router$: `${__dirname}/node_modules/vue-router/dist/vue-router.esm.js`
    // ...
// ...

Create Vue app placeholder

We are going to replace the generated front-end with a Vue app that has a single index route and add routes to get there.

Modify actions/app.go

Add a route to access the Vue app

// ...
func App() *buffalo.App {
  if app == nil {
    // ...
    app.GET("/", HomeHandler)

    app.ServeFiles("/", assetsBox) // serve files from the public directory
  // ...
// ...

Some tutorials recommend using app.GET("/{path:.+}", HomeHandler) to capture all requests and send them to the Vue app. Due to the way ServeFiles works (I think this was changed at some point but was unable to find the version it happened) you can’t really have a catch all route off the index. One way to get around this would be to nest your application in a path like "/app/{path:.+}". This is probably a fine solution but I care about my urls too much so for this guide we will create a more verbose routes list than we would normally have to with Buffalo.

Remove generated Buffalo templates

rm templates/_flash.plush.html
rm templates/index.plush.html

Modify templates/application.plush.html

Remove the flash partial call from this file.

<%= partial("flash.html") %>

Create templates/index.html

<div id="app">

Modify actions/home_test.go

At this point our tests are broken but we can fix them. home_test.go checks the contents of the home handler and we’ve altered it. Lets change "Welcome to Buffalo" to "<div id=\"app\">".

Create assets/js/pages/home.vue

  <h1 class="page-header">Welcome</h1>

<script charset="utf-8">
export default {
  data() {
    return { };
  created() { },
  watch: { },
  methods: { }

Modify assets/js/application.js


import Vue from "vue";
import VueRouter from "router";
import HomePage from "./pages/home.vue";

$(() => {


  const routes = [
    {path: "/", component: HomePage}

  const router = new VueRouter({
    mode: "history",

  const app = new Vue({


At this point your tests should pass with buffalo test and you can access your Vue app via buffalo dev.

Setup Vue.js testing with Jest

yarn add --dev jest vue-jest babel-core@bridge @vue/test-utils

Modify the package.json

Configure Jest.

  // ...
  "scripts": {
    // ...
    "test": "jest"
  // ...
  "jest": {
    "moduleFileExtensions": [ "js", "json", "vue" ],
    "transform": {
      "^.+\\.js$": "babel-jest",
      "^.+\\.vue$": "vue-jest"

Create assets/js/test/unit/home.spec.js

import { shallowMount } from '@vue/test-utils'
import HomePage from "../../pages/home.vue";

let wrapper = null

beforeEach(() => {
  wrapper = shallowMount(HomePage)

afterEach(() => {

describe('Home', () => {
  it('renders Welcome', () => {

Running Vue.js tests

yarn test

Exploring the Buffalo test tooling

Code coverage

# Generate a coverage profile
buffalo test -covermode=count -coverprofile=c.out ./...
# You can get a really nice visualization of tested code with the cover tool
go tool cover -html=c.out

If you’re on WSL you can use wslpath -w to convert the file path to one you can use in your windows browser.

Race condition detection

buffalo test -race ./...

Run a single test

buffalo test -m "FooMethod"

Test everything

This runs your tests and dependancy tests and is usually only done before publishing an application as it takes quite a long time.

buffalo test all

Creating and running the Docker image

Buffalo generated a docker file for us when we created our appplication. Let’s build it with:

docker build . -t myapp

Before running our Docker image we will likely need to change our postgresql configuration to allow connections from the container. This is very dependant on where and how you are running your local postgresql for development. I am running my postgres on localhost so I was able to follow these instructions.

Running the image

docker run -it -p "3000:3000" myapp

You should be able to access your app from the browser via http://localhost:3000.

Enable Travis-CI

Follow this guide to give travis permissions to your repository.

Create .travis.yml

dist: bionic

  - postgresql
  postgresql: 10

language: go
- 1.12.x
# Force-enable Go modules. This will be unnecessary when Go 1.14 lands.
env: GO111MODULE=on

# Only clone the most recent commit.
  depth: 1

  # Install buffalo
  - wget
  - tar -xvzf buffalo_0.15.1_linux_amd64.tar.gz
  - sudo mv buffalo /usr/local/bin/buffalo
  # Install goveralls to push code coverage to
  - go get

  - go vet ./...
  - buffalo test -covermode=count -coverprofile=c.out ./...
  - yarn install --no-progress
  - yarn test
  - buffalo build --static

  - $GOPATH/bin/goveralls -coverprofile=c.out -service=travis-ci
  - cat ./coverage/ | yarn run coveralls

Enable Coveralls

Give permissions to your repository.

yarn add --dev coveralls

Modify .travis.yml

# ...

  # ...
  # Install goveralls to push code coverage to
  - go get

# ...

  - $GOPATH/bin/goveralls -coverprofile=c.out -service=travis-ci
  - cat ./coverage/ | yarn run coveralls

Thank you

Your comment has been submitted and will be published once it has been approved.


Your comment has not been submitted. Please go back and try again. Thank You!

If this error persists, please open an issue by clicking here.

Say something