Google jQuery build

I am testing google clos-compiler and wants to compile facebox Plugin with the option "Advanced", an error occurs trying to find "aH".

Someone tried to compile this option using jQuery plugins with good results.

Thanks.

EDIT: Clearly, this is a reassignment of jQuery methods, but is it possible to enable jQuery and rename all methods the same way ?.

EDIT

sample code with the option "externs_url":

with closing compiler

js input code

// ==ClosureCompiler== // @output_file_name default.js // @formatting pretty_print // @compilation_level ADVANCED_OPTIMIZATIONS // @warning_level QUIET // @externs_url http://code.jquery.com/jquery-1.5.min.js // ==/ClosureCompiler== // ADD YOUR CODE HERE var test = function($, context) { var _self = this; _self.mymethod = function() { var lista = $("a", context); lista.attr("target", "_blank"); return lista.html(); }; return {"mymethod":_self.mymethod}; }.call({}, jQuery, context); 

js ouput code

 (function(b, c) { this.a = function() { var a = b("a", c); a.attr("target", "_blank"); return a.html() }; return{mymethod:this.a} }).call({}, jQuery, context); 
+4
source share
6 answers

I ran into the same problem when trying to compress the jQuery custom JS plugin library. Closing (unless you give it a reason for this) will simply rename any jQuery library calls from your plugin. And even worse, it won’t even warn you (how could he assume that the programmer knows what you are doing!) The solution should refer to an external js file (or the URL points to a library). I used the web tool: http://closure-compiler.appspot.com/home

Applying the fowlloing preamble, I was able to successfully compile the file:

 // ==ClosureCompiler== // @compilation_level ADVANCED_OPTIMIZATIONS // @warning_level QUIET // @output_file_name default.js // @formatting pretty_print // @externs_url http:// ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js // @externs_url http:// ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.js // ==/ClosureCompiler== 

The only problem that remains is that the compiler understands that the name of the plugin cannot be simplified:

 (function($) { $.fn.extend({ <name>:function(options) { } }); })(jQuery); 

Because it is a name open to the world. Any ideas?

+4
source

The jQuery library itself cannot be compiled using ADVANCED_OPTIMIZATIONS , but you can compile your own code with advanced optimizations using the Closure externs compiler file, which defines the entire jQuery API. Download the externs file for your jQuery version from the Closure Compiler repository . In this example, I will use version 1.4.3

It is further assumed that your application code is in application.js , and compiler.jar is the jar file of the Google Closure Compiler file (available in this zip file ):

 java -jar compiler.jar \ --compilation_level ADVANCED_OPTIMIZATIONS \ --externs jquery-1.4.3.externs.js \ --js_output_file output.js \ application.js 

The externs file tells the Closure Compiler which jQuery methods exist, so it cannot rename them.

+5
source

In order for the jQuery plugin to compile correctly using the advanced option, you must slightly modify your source code. All external functions should use quoted strings instead of dot syntax. This ensures that the closure compiler saves the name of the external function. For instance:

 $.fn.pluginName = function(opts) { // plugin code } 

will compile in

 $.ab=function(){}; 

which is pretty useless. But, if you change the source a little

 $.fn['pluginName'] = function(opts) { // plugin code } 

will output this

 $.a.pluginName=function(){}; 

MUCH better!

+4
source

When I tried, the Closure compiler changed the names of the functions I accessed. So when I used (as an example) $.each(// code) , the compiler changed it to $.a(// code ) . I believe that there is your problem.

+1
source

Yes, you will need to combine jquery.js and plugin.js into one file, but at the moment some parts of jQuery do not compress correctly using the Advanced Compilation option, but you can still use Simple Compilation.

I'm sure the jQuery team will soon release a version that can be compiled using the Advanced Compilation option.

If you are interested in Advanced Compilation, check out these tutorials . After you read em, you will understand why some parts need to be changed before you can compile them using Advanced Compilation without errors.

+1
source

I think you should include all the scripts in your application so that it works on all of them.

0
source

All Articles