skip to content
blog.metters.dev
Table of Contents

Prerequisites

  1. A running web server, e.g., Caddy or nginx
  2. A way to open a connection to the server via ssh. How to set up authentication via ssh keys is documented here.
  3. Ownership of the directories into which the artefact is deployed or the permission to do so. Editing ownership of directories is described here.

Optional: Configure your ssh config, see here.

Deploying an artefact manually via terminal

First, build your artefact. If you use npm the command is as follows: npm run build. Usually, the artefact can be found in a directory named dist/, public/, or build/.

After that, copy the contents of that directory into the folder on you server via rsync, e.g., rsync -avzr --delete ./dist/ <USERNAME>@<IP_ADDRESS>:<path/to/your/deployed/artefact>

I’m using pnpm and have configured my ssh config, so for me, the two commands look like this:

Terminal window
pnpm build
rsync -avzr --delete ./dist/ metters.dev:/var/www/html/metters.dev

Add script to package.json

This can be improved! Instead of memorizing the command or even typing both of them every time, they can be combined and added as script in your package.json. Adding this, lets you deploy your site with just npm run deploySite or pnpm deploySite.

package.json
{
"scripts": {
"deploySite": "echo 'Deploying artefact - please confirm!' && read && pnpm build && rsync -avzr --delete ./dist/ metters.dev:/var/www/html/metters.dev"
}
}