Reputation: 8880
I have downloaded the latest closure compiler jar file and followed the instructions here to see how I can get it to preserve references to JS functions defined elsewhere.
My test script, hello.js is as follows
function hello(nom)
{
alert(nom + familyName());
}
My externs are defined in the file externs.js which contains the code
function familyName(){}
I then issue the command
java -jar closure.jar --js hello.js --externs externs.js --js_output_file hello-compiled.js --compilation_level ADVANCED_OPTIMIZATIONS
Without ADVANED_OPTIMIZATIONS
everything works correctly - effectively a spot of code minification. However, as soon as I put in the advanced flag the output hello_compiled.js
comes out as an empty 1 byte file. Clearly, I am misunderstanding something somewhere. I'd be much obliged to anyone who might be able to put me on the right track here.
Upvotes: 0
Views: 326
Reputation: 1089
I suspect your hello.js
only defines the hello function? If so, you need to add:
hello("foo");
so that something actually happens. You can try this out with the online closure compiler. The default code there is:
function hello(name) {
alert('Hello, ' + name);
}
hello('New user');
If you comment out the last line and click the "advanced" button and compile, the result is successful but it is zero bytes. This is because that code effectively does nothing, so the compiler is doing the right thing.
Upvotes: 1