帮助了解谷歌闭包编译器基础知识

发布于 2024-11-27 03:23:27 字数 741 浏览 4 评论 0原文

我无法理解使用 google 闭包编译器 API 服务的基本流程。我会抛出一些问题:

  1. 我是否应该将闭包的 base.js 包含在我发送的要编译的文件列表中?
  2. deps.js 太大,无法发送。我应该自己包含它,还是编译器服务会使用自己的副本?
  3. 据我了解,编译器的功能之一是它解析“require”语句,并在输出中包含必要的代码。例如,如果我转到他们提供的 在线 UI 工具,并在输入框中键入以下内容:

    goog.require("goog.dom");
    goog.dom.getElement(“测试”);
    

然后按“编译”,我希望得到足够的谷歌关闭代码来执行这个片段。相反,我只是得到同样的东西(减去空格)。我不明白什么?

最后,谷歌的编译器服务对您发送的文件有 200k 的大小限制。我正在使用一个名为 Minify 的 PHP 包,它可以让您发送一个文件列表,这些文件一次通过该服务发送一个,并且大概这就是 google 希望您处理 200k 限制的方式。编译器应该检查,比如说,你的私有变量没有在任何地方被作为公共访问,这似乎意味着它必须了解列表中的所有文件,以确保文件中定义的类文件B中A并没有被侵犯,是这样吗?该服务是否会以某种方式记住解析后的每个文件,将其保存在内存中并交叉检查所有内容?还是我的理解还有缺陷?

谢谢你们!

I'm having trouble understanding the basic flow of using the google closure compiler API service. I'll just fire away with some questions:

  1. Am I supposed to include closure's base.js in the list of files I send to be compiled?
  2. deps.js is too large to send. Am I supposed to include it myself, or will the compiler service use its own copy?
  3. It was my understanding that one of the features of the compiler is that it parses the "require" statements, and includes the necessary code in the output. For example, if I go to the online UI tool they provide and type the following into the input box:

    goog.require("goog.dom");
    goog.dom.getElement("test");
    

and press "compile", I would expect to get back just enough of the google closure code to execute this snippet. Instead, I just get the same thing back (minus whitespace). What am I not understanding?

And finally, google's compiler service has a 200k size restriction on the files you send in. I'm using a PHP package called Minify, that lets you send a list of files, which are sent through the service one at a time, and presumably this is how google expects you to deal with the 200k limit. The compiler is supposed to be checking, say, that none of your private variables are being accessed as public anywhere, which seems to imply that it would have to have knowledge of all the files in the list to make sure that a class defined in file A is not being violated in file B. Is this the case? Does the service somehow remember each file as its parsed, keep it in memory, and cross-check everything? Or is my understanding yet flawed?

Thanks, guys!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

娇俏 2024-12-04 03:23:27

如果您从“添加 url”的下拉列表中选择“Closure Library”,它将添加到配置中:

// @ use_closure_library=true

这将导致 Web 服务包含“goog.require”的源,该源可以由 Closure-library 本身来满足。如果您的任何 goog.requires 必须由您自己的代码满足,则您必须手动包含 URL。

在某些时候,您可能想要运行自己的编译服务,您可能会发现 Michael Bolin 的 Plovr 项目很有用:

http ://code.google.com/p/plovr/

If you select the "Closure Library" from the drop down for "add a url", to the configurations it will add:

// @ use_closure_library=true

This will cause the webservice to include the source for "goog.require" that can be satisfied by closure-library itself. If any of your goog.requires must be satisfied by your own code, you must include the URL manually.

At some point you likely want to run your own compilation service for which you might find Michael Bolin's Plovr project useful:

http://code.google.com/p/plovr/

十年不长 2024-12-04 03:23:27

我创建了一个名为 Shoreline 的 Google Closure 项目模板。它包含在本地创建、测试和编译 Closure 项目所需的一切。没有代码大小限制,也没有正常运行时间问题。

I've created a Google Closure project template called Shoreline. It contains everything needed to create, test, and compile a Closure project locally. No code size restrictions and no uptime concerns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文