This took me a while to go through when i was working it out and there was no straight up tutorial so I thought I'd write a quick one.
This is based on a haskell application / server built with stack and an SPA that uses npm to get the compiler / transpiler and stuff (I think that's all of them?).
Assumptions this makes:
- you know how to use npm and the build tools for whatever SPA you're using
- you know how to use stack
- you know how to use heroku
If the above are not true for you then it's ok because they are well-documented and google-able.
- make your haskell app using
stack new
maybe with a template or something. - go into your new haskell project and initialise it as a node project (in the root) using
npm init
. - now you have a package.json in the root of your haskell project - feels weird right?
- make it into a git repo -
git init
- add any deps for the SPA to the
package.json
- maybe it's an elm front end so you addelm
to it. Or maybe it's purescript so you addpurescript
andspago
to the dependencies. I trust you to know what you need. - create your front end stuff in a sub directory, we'll be calling it
client
. - get writing some code and set up your server to serve the
client/build
directory (or whatever it's called in your case), and get it to use thePORT
environment variable for the port it runs on. - create a heroku app and add the heroku buildpack for stack and the node js buildpack to the project.
heroku create --buildpack https://github.com/mfine/heroku-buildpack-stack.git
heroku buildpacks:set https://github.com/heroku/heroku-buildpack-nodejs
- add a
postinstall
script to thepackage.json
in the root that does all of the compilation jazz for your SPA. So it could be something like
{
"postinstall": "cd client && elm make Main.elm --output="./build/index.html"
}
- push your stuff up to heroku.
git push heroku master
- marvel at your deployed app.
If there's something I could / should change send a PR or and issue