jquery - Google Closure 中的外部 jQuery 编译了 JS?

标签 jquery google-closure-compiler

Possible Duplicate:
jQuery compiled with Google Closure Compiler

我的标记:

<script src="http://somecdn.com/jquery-1.4.2.min.js"></script>
<script src="/js/mycode.closure_compiled.js"></script>

我的代码:

goog.provide("mycode");

mycode.foo = function () {
    jQuery("#ajaxSpinner").show();
    jQuery.get("/ajax/foo", function () { /* ... */ });
}

我想使用 Google Closure 编译器通过高级优化来编译我的代码。

如何实现以下目标?

  1. 编译器不应重命名“jQuery”和“jQuery.get”。
  2. 编译器不应抛出错误或警告(例如“未知类型'jQuery'”)。

最佳答案

您必须使用externs 。这些文件告诉编译器代码中的哪些符号来自外部代码,因此不应重命名。基本上,您必须使用 --externs 标志指定外部。一些third-party extern files像 jQuery 一样可以在项目源代码中找到。

关于jquery - Google Closure 中的外部 jQuery 编译了 JS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3334476/

相关文章:

javascript - 闭包编译器需要入口点 "..."从未提供

openlayers-3 - 如何在 ol3 的自定义构建中包含非 API 方法?

javascript - 有任何想法吗?鼠标进入/鼠标离开(我被卡住了)

jquery - Angular JS : temporary disable animation provided by directive so it doesn't animate when the page load?

javascript - Google Closure 是否支持多个 "packages"的 Javascript 文件?

java - 使用 Rhino 更改 javascript 字符串文字

google-closure-compiler - 如何告诉闭包编译器保留对象的属性

javascript - CKEditor 4 中的字数统计

jquery - 动态对象和AJAX调用mvc

javascript - 使用 jQuery 从按钮传递正确的 ID 号