How to use Google Closure compiler

对着背影说爱祢 提交于 2020-01-22 16:27:08

问题


I'm trying to migrate from the closurebuilder.py script to the Closure compiler because of this message:

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

is prefererred over using this script for performing JavaScript compilation

Since I'm using Google Closure Library and the OpenLayers 3, how do I have to call the compiler (compiler.jar) to

  • Build an myapp-deps.js dependency file
  • Build an minified version myapp.js that includes only used OL3 and CL classes
  • Build both with the usage of pre-calculated dependency files of OL3 and CL (e.g. ol3-deps.js)

Let's further say everything is located in the following structure. This almost equals to my own project but it is to big and complex to be posted here directly.

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/

I'm thankful for every hint.


回答1:


Closure Compile can now manage Closure dependencies, that is dependencies defined with goog.provide and goog.require in the JavaScript code. So you do not need to use the closurebuilder.py script anymore. And this is why it's deprecated.

See the wiki page https://github.com/google/closure-compiler/wiki/Manage-Closure-Dependencies to know about the options/flags Closure Compiler provides for that.

Regarding the generation of deps files, which may be necessary for loading js files one by one for debugging/development purposes, you will still need Closure Library's depswriter.py script. Closure Compiler has no tool or flag for that. Reading https://github.com/google/closure-library/issues/382 depswriter.py is no longer used within Google, but it looks like the script is still maintained.



来源:https://stackoverflow.com/questions/27301007/how-to-use-google-closure-compiler

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