SOURCES = index.pug layout.pug style.styl main.coffee privacy.md
OBJECTS = index.html style.css main.js privacy.html
all: $(OBJECTS)
watch:
http-server &
while true; do \
$(MAKE); \
inotifywait -qq $(SOURCES); \
done
%.html: %.pug
pug -P $^
%.css: %.styl
stylus $^
%.js: %.coffee
coffee -c $^
%.html: %.md
markdown $^ > $@
clean:
rm -rfv $(OBJECTS)
This could be extended to produce an out-of-source build by using `-o "$(PUBLIC)"` on the command line generators, but I didn't need it for this project. %.html: %.pug ; pug -P $^
I find it super useful for compact Makefiles: %.html: %.pug ; pug -P $^
%.css: %.styl ; stylus $^
%.js: %.coffee ; coffee -c $^
%.html: %.md ; markdown $^ > $@
clean: ; rm -rfv $(OBJECTS)
Also, worth making clean .PHONY since it's not a file.But most of us want to require() modules also in the browser, so you'll anyway need browserify or other bundler, which already have cross-platform watch mode & plugin ecosystem, and are expected to be run continously, and suddenly the Makefile feels rather redundant, especially with npm scripting.
.PHONY: watch .PHONY: clean
In the appropriate places.
A Makefile consists of separate commands¹ and is heavily file-based¹, which makes it rather slow and doesn't allow to keep state (in memory) between re-runs. Traditionally this hasn't been bottleneck, because compiling C code was relatively slow operation, but modern web development tools prefer to work with in-memory streams instead of invoking executables for tiny files on disk.
I'm not saying you cannot do things with make, but in NodeJS/web ecosystem it just doesn't feel as natural/flexible as the "native" NodeJS-based toolchain.
[1] Great for interoperability, but sometimes more tailored solution is worth it.
watch:
while ! inotifywait -e modify $(SRC) ; do time -p make all; donehttp://man7.org/linux/man-pages/man1/inotifywait.1.html
or just use tup
pip install when-changed
when-changed *.tex -c "make all && echo 'done'"
Then you can make rule in your make file called "watch" or "build-server" which calls that command, so you just need to write "make watch".