How to auto-generate externs for the Google Closur

2020-06-12 02:50发布

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?

2条回答
成全新的幸福
2楼-- · 2020-06-12 02:57

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

查看更多
倾城 Initia
3楼-- · 2020-06-12 03:00

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/

查看更多
登录 后发表回答