简体   繁体   English

是否可以使用闭包编译器ADVANCED_OPTIMIZATIONS与jQuery?

[英]Is it possible to use Closure Compiler ADVANCED_OPTIMIZATIONS with jQuery?

I keep getting errors that the function (renamed) does not exist for the given object. 我不断收到给定对象不存在函数(重命名)的错误。 Is there a release or setting or something to make it work? 是否有发布或设置或其他东西使它工作?

You must use an externs file for jQuery when using Closure Compiler Advanced Mode with jQuery. 在使用带有jQuery的Closure Compiler Advanced Mode时,必须使用externs文件来实现jQuery。 Extern file will tell compiler these are reserved methods and accept these argument and argument data types should be like that, so do not minify method names and check argument data types in that way. 外部文件将告诉编译器这些是保留方法并接受这些参数和参数数据类型应该是这样的,所以不要缩小方法名称并以这种方式检查参数数据类型。

You can get externs file which is created by Google Developers here . 您可以在此处获取由Google Developers创建的外部文件。 This file generated for jQuery-1.4.3. 此文件是为jQuery-1.4.3生成的。 But currently probably will work any version of jQuery. 但目前可能会使用任何版本的jQuery。 Newly added methods may not include in that file, so you should add it to externs file, syntax and synonyms are so simple. 新添加的方法可能不包含在该文件中,因此您应将其添加到externs文件,语法和同义词非常简单。

Also you can say location of externs file to compiler by using an extra compier flag. 您还可以使用额外的compier标志将externs文件的位置说给编译器。 Syntax should be like this 语法应该是这样的

--compiler_flags= "--externs=path/to/jquery.externs.js"

Also you can use this tool which is an online externs extractor for Closure Library. 您也可以使用此工具 ,它是Closure Library的在线外部提取器。

You have to declare jQuery as an extern to the compiler ...however I'm not sure if anyone's made one, there was an extern file for 1.3.2 , but I haven't seen any 1.4+ versions. 你必须将jQuery声明为编译器的外部 ...但是我不确定是否有人创建了一个, 有1.3.2的extern文件 ,但我还没有看到任何1.4+版本。

Edit: this issue thread here has the community building a 1.4 version . 编辑: 此问题线程在这里有社区构建1.4版本

jQuery is not compatible (yet) with the Closure Compiler in advanced mode. jQuery与高级模式下的Closure Compiler不兼容。 I agree it would be a very good thing to make it compatible, because its method-chaining syntax lends very readily to prototype virtualization for much improved execution speed. 我同意将它兼容是一件非常好的事情,因为它的方法链式语法很容易为虚拟化原型提供大大提高的执行速度。

In fact, among the popular JavaScript libraries (other than Closure Library, that is), only the Dojo Toolkit is compatible with Closure Advanced mode. 事实上,在流行的JavaScript库(除了Closure Library之外)中,只有Dojo Toolkit与Closure Advanced模式兼容。

http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t http://dojo-toolkit.33424.n3.nabble.com/file/n2636749/Using_the_Dojo_Toolkit_with_the_Closure_Compiler.pdf?by-user=t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM