using jQueryUI with closure compiler

依然范特西╮ 提交于 2019-12-22 08:24:07

问题


I am having trouble getting a js app that uses jQuery UI to work after minifying using the closure compiler.

What I did:

  1. Go here and load up the jqueryui js file
  2. Asked to extern jQuery.ui
  3. Copied the result to a file and used it as an extern file

The app broke, though. The dialogs do not show correctly anymore. The explosion effect doesn't work correctly, and there are several dialogs created. It is interesting that jQuery UI itself is working somewhat, since the dialogs were created. It is just that the app is misbehaving.

Am I missing something?


回答1:


The linked externs extractor doesn't appear to be able to extract externs from jQuery style files. This is most likely because jQuery uses the "extend" method to assign objects and that tool doesn't recognize that these properties need to be externed as well.

To address the issue, you would need to unravel the extend calls into direct assignments:

jQuery.extend(jQuery.ui, { prop1: function() {}, prop2: function() {});

Would become

jQuery.ui = jQuery.ui || {};
jQuery.ui.prop1 = function() {};
jQuery.ui.prop2 = function() {};

Also, when dealing with jQuery and using advanced optimizations, the "$" alias should be avoided completely.

This is just one of several reasons why compiling jQuery code with Closure-compiler advanced optimizations is challenging.



来源:https://stackoverflow.com/questions/6134290/using-jqueryui-with-closure-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!