Heroku Build Script for Laravel and Vue

So if you have a Laravel + Vue app that you deploy to Heroku, and you want Heroku to run the NPM and Webpack build scripts, here is what you do.

Make sure you have Node.js bundle in your instance.

You can do this through the CLI or manually in the settings page

heroku buildpacks:set heroku/php

Add build scripts in your package.json under scripts.

And these two scripts. We install dev dependencies so that we have the tools to run prod at the end.

"scripts": {
  "heroku-prebuild": "npm install --dev",
  "heroku-postbuild": "npm run prod"
}

You also may have to set a production environment key.

NODE_ENV=production

You can also skip the prebuild script and add the env key which will run dev dependencies on a production env.

NPM_CONFIG_PRODUCTION=true

There’s also a script that you can run for cleanup under package.json script

"heroku-cleanup": "your cleanup routine"

Read more in the Heroku Node Documentation.

Leave a Comment