9

[Makefile] Online Concatenate and Compress JavaScript Files

 2 years ago
source link: http://siongui.github.io/2016/12/26/makefile-online-concatenate-and-minify-js-files/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[Makefile] Online Concatenate and Compress JavaScript Files

December 26, 2016

Concatenate and minify/compress JavaScript files via Makefile, curl, and online Google Closure Compiler.

Put this Makefile and js files in the same directory and then type make. After finish, the minified/compressed js file will be named app.min.js in the same directory.

Makefile | repository | view raw

SOURCE_JS_FILES=$(filter-out %.min.js, $(wildcard *.js))
CONCAT_JS=/tmp/tmp.js
MINIFIED_JS=app.min.js

minjs: concat
	curl \
	-d compilation_level=SIMPLE_OPTIMIZATIONS \
	-d language=ECMASCRIPT5 \
	-d output_format=text \
	-d output_info=compiled_code \
	--data-urlencode "js_code@$(CONCAT_JS)" \
	https://closure-compiler.appspot.com/compile \
	> $(MINIFIED_JS)

concat:
	@cat $(SOURCE_JS_FILES) > $(CONCAT_JS)

Tested on: Ubuntu Linux 16.10.


References:

[1][Bash] Online Concatenate and Compress JavaScript Files

[2][Makefile] Concetenate and Minify CSS via sed and tr Command


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK