How can I combine and compress multiple script and

2019-01-18 23:54发布

I want to use YUI Compressor to combine and compress my css and js file sets when I compile my project. YUI Compressor only takes as input single files. I've tried using the following (Windows) commands to append to the output files, but strange characters appear in the output where appendage occurs. How can I use windows command line or powershell to achieve this?

java -jar yuicompressor-2.4.2.jar --charset utf-8 jquery-1.3.2.js > scripts-all.min.js
java -jar yuicompressor-2.4.2.jar --charset utf-8 jquery.superfish.js >> scripts-all.min.js

3条回答
叼着烟拽天下
2楼-- · 2019-01-19 00:12

If you're developing on Windows, don't forget there's a .NET port of YUI Compressor. You can do all that as a post-build event in visual studio, as part of a TFS Build or just import the dll's into your application and use it in that (eg. compressing on the fly).

查看更多
可以哭但决不认输i
3楼-- · 2019-01-19 00:26

My simple solution (before knowing about the .NET port of YUI Compressor) was to:

copy /b jquery.js+jquery.superfish.js+jquery.qtip.js+NOTICE core.js
java -jar yuicompressor-2.4.2.jar --charset utf-8 -o core-min.js core.js

That has been working fine for me even though I can't quite understand why the /b (binary) flag was the trick that got rid of the strange characters. If anyone wants to enlighten me in a comment I'd appreciate it.

查看更多
Lonely孤独者°
4楼-- · 2019-01-19 00:30

You can try the Invoke-Expression cmdlet (iex is an alias):

PS > $cmd = 'java -jar yuicompressor-2.4.2.jar --charset utf-8 jquery-1.3.2.js > scripts-all.min.js'
PS > iex $cmd
查看更多
登录 后发表回答