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 !
You can use KjsCompiler: https://github.com/knyga/kjscompiler . Compiles multiple JavaScript files with Google Closure Compiler application in a right order
How to solve your problem: 1. Add annotations to js files, like this:
/** * @depends {lib/somefile.js} **/
If you do not care about compilation chain, you can ignore this step. 2.java -jar kjscompile.jar
You can look for example here: https://github.com/knyga/kjscompiler/tree/master/examples
I tried Orbits' answer, but It didn't really work perhaps the version I use is a newer version. The command I use is :
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):The github of google closure doc gives the below command.
If you have multiple scripts, you should compile them all together with one compile command.
You can also use minimatch-style globs.
Source : https://github.com/google/closure-compiler#compiling-multiple-scripts
Here are five globbing techniques for including multiple input files, with documentation extracted from the
CommandLineRunner
class:(1) This is a variation of muka's technique, removing the
--js
flag, which is not needed:From the docs:
This will include all
.js
files in/src/
, but won't include any files in subdirectories of/src/
.(2) Similar to 1, but will include all
.js
files in/src/
and all its subdirectories:(3) Similar to 2, but uses
xargs
:From the docs:
(4) The v20140625 release added support for the
**
(globstar) wildcard, which recursively matches all subdirectories.For example, this will include all
.js
files in/src/
and all its subdirectories:More info here. From the docs:
From the Java docs:
(5) The v20140625 release also added a new feature: if the input path is a directory, then all
.js
files in that directory and all subdirectories will be included.For example, this will include all
.js
files in/src/
and all its subdirectories:More info here.