How to properly do asset versioning?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

How to properly do asset versioning?

Glen Huang

I'm trying to do asset versioning with make, but the solution I came up with isn't perfect.

I want to minify `src/foo.js` and then copy the minified content to `dist/foo.[hash].js`, where `[hash]` is the sha1 hash of minified content. Right now I do it like this:



stage/%: src/% | stage
        jsmin $< >$@

%.dist.d: % | stage
        makehashdep $(patsubst stage/%,dist/%,$<) $< dist
-include $(src:src/%=stage/%.dist.d)

.PHONY: all
all: $(dist)

$(dist): | dist
        cp $< $@

.PHONY: clean
        rm -r stage dist

stage dist:
        mkdir $@

where `makehashdep` is


hashed=${target%.*}.$(sha1sum $src).${target##*.}
echo $hashed: $src
echo $var += $hashed

With this config, executing `make` does what I want. But there are two issues:

1. `make clean` will try to build the files in `stage` first and then remove the directories.
2. I need to maintain a make variable in `makehashdep`, which feels out of place.

Any idea how I can do asset versioning without these issues?

Thank you.

Help-make mailing list
[hidden email]