Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does YUI Combine multiple JS files in a specified order?

Tags:

javascript

yui

If so, what is the usage? I am trying this:

-jar yuicompressor-2.4.7 file1.js, file2.js -o combined.js

but I get an error that the 'type' option should be specified.

If I do the same with 1 file, it is minified and the contents are output to stdout. I would like to combine file1 and file2 in that order.

like image 627
Nick Avatar asked Dec 29 '11 03:12

Nick


3 Answers

If it complains that the type option should be specified, you should specify it, like this:

-jar yuicompressor-2.4.7 file1.js, file2.js --type js -o combined.js 
like image 156
Peter Olson Avatar answered Sep 22 '22 18:09

Peter Olson


I don't think the YUI Compressor combines files. You can use Ant to automate the task of minifying and combining. If you're new to Ant and making build processes, this should be a good introduction: http://addyosmani.com/blog/client-side-build-process/

like image 31
juandopazo Avatar answered Sep 23 '22 18:09

juandopazo


I know this question is old, but I just ran into this problem (or something similar). I believe the answer is that the @Nick's command syntax is incorrect for specifying multiple files. I think YUI Compessor does support processing multiple files but it only has one input file parameter, so you must use wildcards. IOW, this works:

...yui-compressor.jar -o blah.css *.css

This doesn't:

...yui-compressor.jar -o blah.css 1.css 2.css

At least this is my experience. One should be able to concatenate all the files together some other way and pipe them into the command though. For example, on Windows:

type 1.css 2.css | java -jar yui-compressor.jar --type js -o blah.css

Or on Unix/Linux:

cat 1.css 2.css | java -jar yui-compressor.jar --type js -o blah.css

(or you could probably use file redirection)

Make sure you cat or type the files in the desired order.

like image 42
Josh Avatar answered Sep 25 '22 18:09

Josh