linux uglifyjs的使用


linux uglifyjs的使用
 
最近学习linux shell脚本,尝试写了个uglifyjs的批处理压缩脚本。写的不好,请各位大大们多多指教。
  www.2cto.com  
环境: ubuntu 12.10 64bit./ bash/ node 0.8.15/ uglifyjs 2
 
Shell脚本如下:
 
01
#!/bin/sh
02
#
03
# This file is used to compress js files.
04
# create by Allen Heavey. @DMDGeeker
05
# 2013/02/01
06
#
07
#
08
 
09
function compressJS() {
10
    uglifyjs $1 -c -m -o $1
11
}
12
 
13
function compress() {
14
 
15
    local par=$1
16
    local split="/"
17
    if [ -f $par ] && [ -r $par ] && [ "${par##*.}" == "js" ]; then
18
        compressJS $par
19
    elif [ -d $par ]; then
20
        for i in `ls $par`
21
        do
22
            local j=${par}${split}${i}
23
            #test -d $j && echo "dir $j " || echo "file $j"
24
            compress $j
25
            unset j
26
        done
27
        unset i
28
    fi
29
 
30
}
31
 
32
for var in $@
33
do
34
    path=${var}
35
    compress $path
36
done
使用方法:
    保存脚本(如js.sh)后, 使用类似于 bash js.sh XXXX(可以为目录或文件).
 
这样可以一次批处理多个JS文件,简化操作。

相关内容

    暂无相关文章