Serving static vendor files with Node

Hi all, I was just wondering, what is the accepted way of serving static vendor files with node? I was doing it by using a build script to copy all of the files that would be required by the browser (i.e Bootstrap, jQuery and Font-Awesome) into a vendor directory in my public directory. The problem is that I added this directory to .gitignore, so when my app gets deployed to Heroku, the files don’t exist.

I was just wondering what is the best way that I can do this? As near as I can see I have four options:

  1. Add the front-end files to Git
  2. Add a static route to serve from `node_modules`
  3. Use bower instead of NPM for front-end assets and serve from there.
  4. Completely disregard the front-end files altogether, and instead use a CDN

What would be the best way to do this? Or is it possible to get Heroku to run my build script during the deploy? It’s listed as a script in my package.json


If possible, I would like to avoid using a CDN and my most preferred method would be to get Heroku to some scripts pre-deploy. The reason for this is that I would like to concatenate the minified vendor files so that they can all be retrieved with a single request.

I think I actually found a possible fix. Heroku checks for a heroku-prebuild script on deploy. I’m assuming that should work to run any build scripts that I want before the app is deployed. I’ll have to wait until I get home to test this but I’m hopeful!

I didn’t realize I could Travis could be used for running build scripts pre-deploy, I thought it just automatically ran all of your unit tests before deploying, to make sure there were no breaking changes. Thanks @P1xt!

I was considering using Travis, but I still have to implement unit testing first. They are both on my to-do list for this project. I just never managed to get a JS test-runner up and running. That’s probably the next issue I’m going to work on. Once I get the testing up and running I’ll probably add Travis and set Heroku to sync with master.

that sounds fantastic