Skip to content

Instantly share code, notes, and snippets.

@matijs
Last active October 1, 2021 12:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save matijs/3707f7208198f578d2c0 to your computer and use it in GitHub Desktop.
Save matijs/3707f7208198f578d2c0 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