3 ms·
I don't see what's difficult here.
by dozzie 11y ago
I don't see what's difficult here.
- foldr 11y agoHow would you write a Makefile to do this? (So that you could add additional directories without having to modify the Makefile.)
- dozzie 11y agoI don't know, I would use wildcards, I guess? And maybe some path substitution. SOURCES := $(shell find foo -type f -name '*.js') TARGETS := $(patsubst foo/%,bar/%,$(SOURCES)) .PHONY: all all: $(TARGETS) bar/%.js: foo/%.js mkdir -p $(dir $@) minify $< > $@
- foldr 11y agoOk, fair enough, that’s how far I got when I tried replacing my Gulpfile with a Makefile. However, things become more difficult if the output files have a different extension. E.g. converting jsx files to js files. I didn’t find a way of handling that case that wasn’t way more complex than the corresponding code in Gulp.
- dozzie 11y agoOoh, a tricky one. It may be much more difficult. SOURCES := $(shell find foo -type f -name '*.jsx') TARGETS := $(patsubst foo/%.jsx,bar/%.js,$(SOURCES)) .PHONY: all all: $(TARGETS) bar/%.js: foo/%.jsx mkdir -p $(dir $@) minify $< > $@
- foldr 11y agoI admit, this is easy enough with 'patsubst' and 'dir'. I had not discovered those, and doing the same job with sed got too messy to be worth the trouble. I haven’t seen example code for this particular pattern before, so thanks, it’s useful. I'll switch over to make now.
- dozzie 11y agoI'm glad you like this solution. Indeed, the $(patsubt) function is one of the most useful, along with $(wildcard) and $(foreach).