Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress all file .js with Google Closure Compiler Application in one File

I would like to Compress all my file .js in a same directory in one file with Google Closure Compiler in a command line.

For one file it's :

java -jar compiler.jar --js test.js --js_output_file final.js

But I didn't find in the doc how put my other file at the end of final.js without write over the last compress file ?

I would like something like that :

java -jar compiler.jar --js --option *.js --js_output_file final.js

It's possible or must I do a programm who add all file in a file and after compress it ? Thank you if you can help me !

like image 767
j3j3 Avatar asked Oct 28 '10 13:10

j3j3


3 Answers

java -jar path/to/closure-compiler/build/compiler.jar \ 
--js input_one.js \ 
--js input_two.js \ 
... \ 
--js_output_file compiled_output.js 
like image 55
Brandon Frohbieter Avatar answered Nov 05 '22 17:11

Brandon Frohbieter


I tried Orbits' answer, but It didn't really work perhaps the version I use is a newer version. The command I use is :

java -jar compiler.jar --js file1.js file2.js file3.js  --js_output_file --js_output_file compiled_output.js. 
like image 28
Adelin Avatar answered Nov 05 '22 15:11

Adelin


Assuming that you’ve installed the Closure Compiler with Homebrew on a Mac, you can also concatenate all files and then pipe them to to Closure (this should also work the java -jar way, but I haven’t verified it):

cat $(ls scripts/*.js) | closure-compiler --js_output_file main.js
like image 6
Rafael Bugajewski Avatar answered Nov 05 '22 15:11

Rafael Bugajewski