Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google closure compile jQuery Plugin

I'm testing google closure-compiler and wanting to compile facebox Plugin with the option "Advanced" , an error occurs the function trying to find "a.H".

Has anyone tried to compile with this option jQuery plugins with a good result.

Thank you.

EDIT: Clearly this re-naming the jQuery methods, but is it possible to include jQuery and re-name all methods equally?.

EDIT

example of code with the option "externs_url":

with closure-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);
like image 976
andres descalzo Avatar asked Dec 08 '22 05:12

andres descalzo


1 Answers

The jQuery library itself can't be compiled with ADVANCED_OPTIMIZATIONS, but you can compile your own code with advanced optimizations by using a Closure Compiler externs file that specifies the entire jQuery API. Download the externs file relevant to your jQuery version from the Closure Compiler repository. In the example, I'll use version 1.4.3

The following assumes that your application's code is in application.js and compiler.jar is the Google Closure Compiler jar 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 Closure Compiler which jQuery methods exist so it knows not to rename them.

like image 194
mndrix Avatar answered Dec 29 '22 18:12

mndrix