My Favourite Static Site Deploy Method
There are many ways to deploy an application to a server, and often that depends on the technologies in play, access management and application setup. That said, even for a simple static site I think it’s common to folks to over complicate things. On Reddit I often see folks advising newbies to look into CI or git-hook based deployments as initial places to look, or even worse they start talking about kubernetes.
Personally I’m a fan of simplicity, and for simple personal static sites I have found the following to be my favourite:
// package.json
{
//...
"scripts": {
"deploy": "<build-cmd> && rsync -avx --delete dist/ server-a:/var/www/site/"
}
//...
}
I’m almost always using npm in some way in static-site projects, so typically use npm scripts for convenience. As above, I just add a deploy
script that first runs my build command (Commonly another npm script) before running rsync to copy up the project to the target server, with the --delete
option to get rid of anything on the server location that’s not in the local folder being deployed.
Good old trusty rsync makes this nice and fast, by only transferring changes.
With this set, I can simply run npm run deploy
and everything is deployed in an efficient manner with an easy-to-remember command.
Some may scoff at how manual this is to kick-start, compared to their auto-triggered deployment process, but tbh I like the manual control of this in addition to the lack of external systems involved.
I use this for pretty much anything static, including this blog. A slightly more complex example can be seen within the BookStack website repo.