help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to properly do asset versioning?


From: Glen Huang
Subject: How to properly do asset versioning?
Date: Sun, 7 Aug 2016 23:03:22 +0800

Hi,

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:

```make
.DEFAULT_GOAL = all

src=src/foo.js

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
clean:
        rm -r stage dist

stage dist:
        mkdir $@
```

where `makehashdep` is 

```bash
target=$1
src=$2
var=$3

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.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]