js.mk: Add JS_MINIFY_FILTER_IN

Not so great. Doesn't remove console.log(innerfunc()). Another approach would
be to use a global debug() function and set debug to null in an included
javascript file

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2018-09-03 12:29:00 +00:00
commit f17ce9570c
4 changed files with 41 additions and 15 deletions

View file

@ -1,8 +1,9 @@
JAVA ?= /usr/bin/java
JS_MINIFY_EXE ?= $(JAVA) -jar /usr/share/java/closure-compiler.jar
JS_LOCAL ?= $(wildcard *.js)
JS_SRC ?= $(filter-out %.min.js,$(JS_LOCAL))
JS_GENERATED ?= $(patsubst %.js,%.min.js,$(JS_SRC))
JAVA ?= /usr/bin/java
JS_MINIFY_EXE ?= $(JAVA) -jar /usr/share/java/closure-compiler.jar --compilation_level ADVANCED --strict_mode_input
JS_MINIFY_FILTER_IN ?= sed 's/console\.[a-z]\+([^)]\+) *;//g'
JS_LOCAL ?= $(wildcard *.js)
JS_SRC ?= $(filter-out %.min.js,$(JS_LOCAL))
JS_GENERATED ?= $(patsubst %.js,%.min.js,$(JS_SRC))
# This is not nice. It requires install-files to be included from elsewhere,
# which is not obvious. OTOH, if it isn't, SOURCE_FILES doesn't do any harm,
@ -13,8 +14,9 @@ all: $(JS_GENERATED)
clean: minify.clean
%.min.js: %.js
$(JS_MINIFY_EXE) $< > $@.tmp
cat $< | $(JS_MINIFY_FILTER_IN) > $@.filtered
$(JS_MINIFY_EXE) $@.filtered > $@.tmp
mv $@.tmp $@
minify.clean:
rm -f $(JS_GENERATED) *.tmp
rm -f $(JS_GENERATED) *.tmp *.filtered