til makefiles

I never used to know how Makefiles work, and still don’t know how they work fully. But this is just noting how I use them.

The basic anatomy of a Makefile is:

task: deps
  echo "do something"

So if I wanted to build a project, I’d have a build task that depends on node_modules and the src folder, which produces the dist/ folder:

default: dist

dist: node_modules src/**
  npm run build

node_modules: package.json
  npm install

# Other tasks
# --------------------------

format: node_modules
  npm run format
.PHONY: format

Running make will do something like this:

make
  Running 'npm install'...
  Running 'npm run build'...

# trigger a change to a dep
touch src/index.html

# notice no `npm install` as it's already installed
make
  Running 'npm run build'...

# format will always run as its PHONY
make format
  Running 'npm run format'..,