Skip to content

Instantly share code, notes, and snippets.

@tomelam
Forked from matijs/makefile
Created October 1, 2021 12:10
Show Gist options
  • Save tomelam/f263bb3fcf839d88596f6c2017f81e3a to your computer and use it in GitHub Desktop.
Save tomelam/f263bb3fcf839d88596f6c2017f81e3a to your computer and use it in GitHub Desktop.
Minimalist makefile using PostCSS
# some variables
POSTCSS = ./node_modules/.bin/postcss
POSTCSS_FLAGS = --use autoprefixer autoprefixer.browsers "> 2%"
# wildcard expansion is performed only in targets and in prerequisites so here we need $(wildcard)
SOURCES = $(wildcard src/css/*.css)
# use $(SOURCES) to determine what we actually need using a bit of pattern substitution
TARGETS = $(patsubst src%, build%, $(SOURCES))
# our default target (see below)
all: $(TARGETS)
# as described halfway through https://www.thumbtack.com/engineering/makefiles-for-less-and-css/
# current make needs an explicit target such as "all" when there is only one build target
build/css/%.css: src/css/%.css
@echo "$< => $@"
@$(POSTCSS) $(POSTCSS_FLAGS) --output $@ $<
# simply removes $(TARGETS)
clean:
-@rm -f $(TARGETS)
# both all and clean are not actual filenames
.PHONY: all clean
{
"devDependencies": {
"autoprefixer": "^6.3.1",
"postcss-cli": "^2.5.0",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment