【问题标题】:How to use Google Closure compiler如何使用 Google Closure 编译器
【发布时间】:2014-12-04 18:10:19
【问题描述】:

由于这条消息,我正在尝试从closurebuilder.py 脚本迁移到Closure compiler

../../closure-library/closure/bin/build/closurebuilder.py: Closure Compiler now natively understands and orders Closure dependencies and

优于使用此脚本执行 JavaScript 编译

由于我使用Google Closure LibraryOpenLayers 3,我如何调用编译器(compiler.jar)来

  • 构建一个 myapp-deps.js 依赖文件
  • 构建一个缩小版 myapp.js,其中仅包含使用过的 OL3 和 CL 类
  • 使用预先计算好的 OL3 和 CL 依赖文件(例如 ol3-deps.js)进行构建

让我们进一步说一切都位于以下结构中。这几乎相当于我自己的项目,但它太大而复杂,直接在这里发布。

project/
    src/
        js/
            <some other js "required" in myapp.js>
            myapp.js
            myapp-deps.js                 # This should be the dependency file
        lib/
            closure/goog/...
            third_party/closure/goog/...  
            myapp.js                      # This should be the minified version
    ol3/

感谢每一个提示。

【问题讨论】:

    标签: javascript google-closure-compiler google-closure google-closure-library


    【解决方案1】:

    Closure Compile 现在可以管理 Closure 依赖项,即在 JavaScript 代码中使用 goog.providegoog.require 定义的依赖项。所以你不再需要使用closurebuilder.py 脚本了。这就是它被弃用的原因。

    请参阅 wiki 页面 https://github.com/google/closure-compiler/wiki/Manage-Closure-Dependencies 以了解 Closure Compiler 为此提供的选项/标志。

    关于deps文件的生成,这可能是为了调试/开发目的而一个一个加载js文件所必需的,你仍然需要闭包库的depswriter.py脚本。 Closure Compiler 没有用于此的工具或标志。阅读 https://github.com/google/closure-library/issues/382 depswriter.py 在 Google 中不再使用,但看起来该脚本仍在维护中。

    【讨论】:

      猜你喜欢
      • 2011-01-14
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 2010-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      相关资源
      最近更新 更多