3 ms·
Interestingly enough, I tried using Makefiles for a web project yesterday, and it was a success. SOURCES = index.pug layout.pug style.styl main.coffee priv
by vortico 9y ago
Interestingly enough, I tried using Makefiles for a web project yesterday, and it was a success.
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.
- jgrahamc 9y agoDo you know about the ; style for rules that have only one line of commands? It helps reduce the number of tabs. %.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.
- Yaggo 9y agoSure, that's the traditional way of doing things, and I like its simplicity and the fact that the 40 years old core concept is still so useful. 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.
- GlennS 9y agoI'd recommend adding: .PHONY: watch .PHONY: clean In the appropriate places.