News for hackers. Stuff that matters.
Re:Time for Makefiles to Make a Comeback by Yaggo on Tuesday September 05, 2017 @04:52AM (#15173493)
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.
Re:Time for Makefiles to Make a Comeback by vortico on Tuesday September 05, 2017 @06:07AM (#15173800)
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.
Re:Time for Makefiles to Make a Comeback by jgrahamc on Tuesday September 05, 2017 @07:04AM (#15174026)
Do 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.
Re:Time for Makefiles to Make a Comeback by Yaggo on Tuesday September 05, 2017 @11:23AM (#15176099)
Sure, 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.

Re:Time for Makefiles to Make a Comeback by GlennS on Tuesday September 05, 2017 @12:38PM (#15176817)
I'd recommend adding:

.PHONY: watch .PHONY: clean

In the appropriate places.

Re:Time for Makefiles to Make a Comeback by akvadrako on Tuesday September 05, 2017 @05:02AM (#15173525)
The 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'.
Re:Time for Makefiles to Make a Comeback by Yaggo on Tuesday September 05, 2017 @11:38AM (#15176261)
You lose incremental builds of modern bundlers/transpilers, which makes your build time too slow for bigger projects. People nowadays expect to see changes almost in realtime using hot module replacement etc.
Re:Time for Makefiles to Make a Comeback by akvadrako on Tuesday September 05, 2017 @04:04PM (#15178644)
That's because those tools aren't designed to play well with others. It's not due to the design of make.
Re:Time for Makefiles to Make a Comeback by Yaggo on Wednesday September 06, 2017 @05:21AM (#15182240)
I would say it's partly because of the design of make.

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.

Re:Time for Makefiles to Make a Comeback by akvadrako on Wednesday September 06, 2017 @12:09PM (#15184749)
Launching a process on Linux only takes about 2ms, and make only needs to do it for parts that change. There is no reason you couldn't use a make-based system to get incremental rebuilds with under 100ms latency, which is about as good as most people get with native JS systems.
Re:Time for Makefiles to Make a Comeback by jbergens on Tuesday September 05, 2017 @11:07AM (#15175929)
For js code you often want hot module reloading which is probably very hard to get with make.
Re:Time for Makefiles to Make a Comeback by josephg on Tuesday September 05, 2017 @05:04AM (#15173535)
That sounds like a great idea. Does anything like that exist already?
Re:Time for Makefiles to Make a Comeback by oso2k on Tuesday September 05, 2017 @05:14AM (#15173581)
Easy 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
Re:Time for Makefiles to Make a Comeback by lloeki on Tuesday September 05, 2017 @05:56AM (#15173759)
If you care for it, fswatch is cross-platform:

https://github.com/emcrisostomo/fswatch

Re:Time for Makefiles to Make a Comeback by shoo on Tuesday September 05, 2017 @05:07AM (#15173551)
something along the lines of inotify:

http://man7.org/linux/man-pages/man1/inotifywait.1.html

or just use tup

http://gittup.org/tup/

Re:Time for Makefiles to Make a Comeback by petepete on Tuesday September 05, 2017 @05:11AM (#15173573)
Re:Time for Makefiles to Make a Comeback by AndrewOMartin on Tuesday September 05, 2017 @07:59AM (#15174300)
There'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".
Re:Time for Makefiles to Make a Comeback by gall0ws on Tuesday September 05, 2017 @05:09AM (#15173561)
It's trivial to roll your own: https://github.com/gall0ws/watch