js压缩混淆之shell脚本开发

    js脚本如果不压缩很容易让人破解你的前端逻辑,网上各式各样的压缩工具有很多,我利用uglifyjs自己编写了一个意见压缩js的shell脚本。为了不影响我们开发者调试,就把压缩的js新保存为.min的js。

    在这里要说明一下,需要在nginx中配置访问的时候注意,若不能访问到min的js就rewrite到未压缩的js。所以这里调试的时候只需要删除待min的js就可以了。话不多少,直接贴代码。

#!/bin/sh
# ex:uglifyjs  -c -m  --mangle-props true --pure-funcs console.log /data/deploy/jztz/jztz/js/bet-monitor.js 
# ex java -jar /data/soft/yuicompressor-2.4.8.jar --type js --charset utf-8 /data/deploy/jztz/jztz/js/bet-monitor.js 

folder=/data/deploy/$1
log_file=/data/scripts/run_uglifyjs.log
#CMD=uglifyjs
#OPT=" -c -m --mangle-props true --pure-funcs console.log "
#OPT=" -c --pure-funcs console.log "
CMD="java -jar /data/soft/yuicompressor-2.4.8.jar"
OPT="--type js --charset utf-8 "


echo "###################################"
echo "### folder: $folder"
echo "### cmd   : $CMD"
echo "### opt   : $OPT"
echo "###################################"



for file in `find $folder -name '*.js' ! -name "amazeui.js" ! -name "count.js"  ! -name '*min*' ! -name '*jquery*'  ! -path "*/webuploader-*"  ! -path "*/mobile1.0/*" ! -path '*/jquery/*' ! -path '*/bootstrap*'  ! -path '*/ckeditor*'  ! -path '*/assets/*' ! -path '*datatable*' ! -path '*/layer-*' ! -path '*/mobiscroll-*' ! -path '*/echarts-*'  ! -path '*/ckfinder*' ! -path '*/jquery-*' ! -path '*/ueditor/*' ! -path '*/ligerUI/*' ! -path '*/jqGrid/*' ! -path '*/layui/*'`
do
minfile=$file.min
if [ -f $minfile ];then
	#判断 时间是否超过2小时,否则跳过,不重新生成
	#time=`stat $file  | grep Modif | awk -F':' '{print $2":"$3":"$4}'`
	#timediff=`expr $now - $time`
	#if [ $timediff -lt 7200 ] ;then
		continue;
	#fi
fi
linecount=`cat $file | wc -l`
if [ $linecount -gt 10 ] ;then
	echo "`date +'%F %T'` $CMD -o $minfile $OPT ${file}" | tee -a $log_file
	$CMD -o $minfile $OPT ${file} 2>&1 | tee -a $log_file
fi
done

if [ -n "$2" ] ;then
 
echo "`date +'%F %T'` compress css files" | tee -a $log_file
CMD="java -jar /data/soft/yuicompressor-2.4.8.jar"
OPT="--type css --charset utf-8 "
for file in `find $folder -name '*.css'  ! -name '*min*' ! -name '*jquery*' ! -path "*/webuploader-*"  ! -path "*/mobile1.0/*" ! -path '*/jquery/*' ! -path '*/bootstrap*'  ! -path '*/ckeditor*'  ! -path '*/assets/*' ! -path '*datatable*' ! -path '*/layer-*' ! -path '*/mobiscroll-*' ! -path '*/echarts-*'  ! -path '*/ckfinder*' ! -path '*/jquery-*' ! -path '*/ueditor/*' ! -path '*/ligerUI/*' ! -path '*/jqGrid/*' ! -path '*/layui/*'`
do
minfile=$file.min
if [ -f $minfile ];then
	continue;
fi
linecount=`cat $file | wc -l`
if [ $linecount -gt 10 ] ;then
	echo "`date +'%F %T'` $CMD -o $minfile $OPT ${file}" | tee -a $log_file
	$CMD -o $minfile $OPT ${file} 2>&1 | tee -a $log_file
fi
done

fi

chown nobody.nobody -R $folder

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值