11

[Bash] Online Concatenate and Compress JavaScript Files

 2 years ago
source link: http://siongui.github.io/2016/12/25/bash-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

[Bash] Online Concatenate and Compress JavaScript Files

December 25, 2016

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

minjs.sh | repository | view raw

#!/bin/bash

TMPJS=/tmp/tmp.js

# $1 is the directory in which js files to be processed
# $2 is the minified js from online Google Closure Compiler
cat $(find $1 -type f -name "*.js") > ${TMPJS}
curl \
  -d compilation_level=SIMPLE_OPTIMIZATIONS \
  -d language=ECMASCRIPT5 \
  -d output_format=text \
  -d output_info=compiled_code \
  --data-urlencode "js_code@${TMPJS}" \
  https://closure-compiler.appspot.com/compile \
  > $2
rm ${TMPJS}

Tested on: Ubuntu Linux 16.10.


References:

[2]see tag of Minify HTML/CSS/JavaScript


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK