How to auto-generate externs for the Google Closure Compiler

﹥>﹥吖頭↗ 提交于 2020-01-01 04:30:08

问题


Suppose you are working in a javascript project with several external library dependencies, and want to compile your sources using the Google Closure Compiler in ADVANCED_OPTIMIZATIONS mode.

Since in this mode the compiler will rename your code calls to the external libraries objects and functions, you must provide externs, to prevent this renaming from happening.

But, it is a lot of work to produce the externs by hand, so, what is the best way to auto-generate the appropriate extern from a given javascript lib?


回答1:


See the following URL as a starting point. I would also recommend adding type information to your externs to maximize compiler benefit.

http://www.dotnetwise.com/Code/Externs/




回答2:


you can export your function by: window['myFunc'] = myFunc;

bit more detail here: http://code.google.com/closure/compiler/docs/api-tutorial3.html#no

if you actually want externs for libs you import from elsewhere (ie service wrappers, jquery, etc) then thats where you need to pass the extern in If you are using teh jar compiler, you specify using --externs, more detail in link above



来源:https://stackoverflow.com/questions/4267413/how-to-auto-generate-externs-for-the-google-closure-compiler

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