abyrd.me
Simplifying My Monorepo Management with a MakefileAug 27, 2024
2 min read

In my last post about terminal multiplexers I mentioned that my project for this personal website is a very simple monorepo. A monorepo may seem overkill, but when I say it's simple I mean it.

I have one folder with my frontend built with remix and another folder for my files-api written in Go. I've also got a folder with scripts and a single Makefile that manages everything.

Makefiles are typically file-based and used for build automation and dependency management. So the way I'm using one feels atypical, but it works well.

In order to simply run commands I use the .PHONY directive which declares targets that don't represent actual files. This way I can run npm scripts or bash scripts.

It creates for some more manual work. I need to place all of my common commands in it and typically have to cd into the correct directory and then run the command. Here's some commands for my frontend folder:

# Frontend Makefile Commands

.PHONY: web-dev
web-dev:
@echo "Starting web:dev..."
cd ./frontend && npm run dev

.PHONY: web-install
web-add:
@echo "Installing npm dependencies..."
cd ./frontend && npm install $(filter-out $@,$(MAKECMDGOALS))

As you can see I even add stuff for npm installs/removes/etc. I just really hate cd'ing in and out of folders. I want to stay at the top level and do everything there, and this Makefile let's me do that.

Been working great so far. Try it out maybe? Or don't. I don't care.