使用指令处理JS、CSS、PNG文件

阅读更多
使用yui的压缩工具压缩JS和CSS
http://developer.yahoo.com/yui/compressor/
yuicompressor.jar这个文件要和ymin这个文件放在一个目录下。
ymin的代码如下
#!/bin/sh
#filename=ymin
basedir=$(dirname $0)
jsmin="java -jar $basedir/yuicompressor.jar --type js" 
cssmin="java -jar $basedir/yuicompressor.jar --type css" 
for f in $*; do
	case $f in
		*.source.js)
			n=`echo $f | sed s/.source.js$//`
			$jsmin $f -o $n.js ;;
		*.js)
			n=`echo $f | sed s/.js$//`
			$jsmin $f -o $n-min.js ;;
		*.source.css)
			n=`echo $f | sed s/.source.css$//`
			$cmd;$cssmin $f -o $n.css ;;
		*.css)
			n=`echo $f | sed s/.css$//`
			$cssmin $f -o $n-min.css ;;
		*)
			find $f -exec ymin {} ';';;
	esac
done


使用示例
ymin a.js
#生成 a-min.js
ymin a.source.js
#生成 a.js
ymin *.js
#依上两个规则批量处理find *.js查找到文件

压缩CSS就 不举例了


使用javascript lint检查js文件
http://www.javascriptlint.com/
mac用户可使用brew install jsl安装
#!/bin/sh 
#filename=jslt
option="-nologo"
for f in $*; do
	case $f in
		*.js)
			jsl $option -process $f;;
		-*)
			option="$option $f";;
		*)
			find $f -exec jsl $option {} ';';;
	esac
done


使用示例
jslt a.js
jslt *.js
jslt -nocontext *.js


使用PNGOUT压缩文件
http://advsys.net/ken/utils.htm
这个只列下帮助吧,我没有用SHELL再包了

$ pngout --help
Warning: unrecognized option: --help
Must specify a source or target image
PNGOUT [In:{PNG,JPG,GIF,TGA,PCX,BMP}] (Out:PNG) (options...)        Jul 22 2011
by Ken Silverman (http://advsys.net/ken)
Mac port assistance by Jonathon Fowler (http://www.jonof.id.au/pngout)
PNGOUT optimizes PNG size losslessly using my own deflate algorithm (not Zlib)
With the right options, it can often beat other programs by 5-10%. Options:
   -c# PNG output color: 0=Gray, 2=RGB, 3=Pal, 4=Gray+Alpha, 6=RGB+Alpha
   -f# PNG output filter: 0=none, 1=x, 2=y, 3=x&y, 4=Paeth, 5=mixed, 6=reuse
   -d# Override default bitdepth: 0(min),1,2,4,8 (valid only in /c0,/c3 modes)
   -s# Select strategy. 0:Xtreme(default), 1:Intense, 2:Longest Match,
       3:Huffman Only, 4:Uncompressed
   -b# Block split threshold (lower=more blocks, 0=1 block/file, default=256)
       Use trial&error! Suggested values to try are: 0,128,192,256,512,1024,..
   -n# Exact number of Huffman blocks (overrides /b#)
   -r  Randomized initial tables (good for many trials with same options)
   -k? 0=Remove optional chunks (default), 1=Keep all
       p=Keep palette indices, s=Keep settings for /c,f,d,b
   -k(Chunk,Chunk,..) Preserve only named chunk(s). Example: -kgAMA,bKGD,tEXt
   -v,q,l Verbose,Quiet,List mode (use '-' as filename to specify stdin/stdout)
   -y  Assume Yes at the 'overwrite file?' prompt
   -force  Write file even if bigger.
   -mincodes#  Workaround for buggy decoders. 1:Zlib 1.2.1 bug, 2:buggy mobiles
The 1st filename is the input. If you omit the output
filename, PNGOUT will use the same filename with a .PNG extension. Examples:
   $ pngout inlarge.bmp outsmall.png           <- writes outsmall.png
   $ pngout duke3d.png -c2 -f3 -b128 -kbKGD -v <- writes duke3d.png if smaller

你可能感兴趣的:(css,js,png)