5 ms·
I used to be big fan of using Makefile for web development, but have since changed my mind, because make is not very good fit for watch-mode incremental buildin
by Yaggo 9y ago
I used to be big fan of using Makefile for web development, but have since changed my mind, because make is not very good fit for watch-mode incremental building.
- vortico 9y agoInterestingly 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.
- akvadrako 9y agoThe data model of makefiles is perfect for watching and rebuilding. All you need to add is something that monitors the source files for any changes and runs 'make'.
- josephg 9y agoThat sounds like a great idea. Does anything like that exist already?
- shoo 9y agosomething along the lines of inotify: http://man7.org/linux/man-pages/man1/inotifywait.1.html http://man7.org/linux/man-pages/man1/inotifywait.1.html or just use tup http://gittup.org/tup/ http://gittup.org/tup/
- gall0ws 9y agoIt's trivial to roll your own: https://github.com/gall0ws/watch https://github.com/gall0ws/watch
- petepete 9y agoAlso, entr http://entrproject.org http://entrproject.org
- oso2k 9y agoEasy enough (assuming $SRC is your list of source files and 'all' is top level target) 'make watch' could do this watch: while ! inotifywait -e modify $(SRC) ; do time -p make all; done
- lloeki 9y agoIf you care for it, fswatch is cross-platform: https://github.com/emcrisostomo/fswatch https://github.com/emcrisostomo/fswatch
- AndrewOMartin 9y agoThere's "when-changed" in pip. 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".