Google Closure Compiler Includes

穿精又带淫゛_ 提交于 2019-12-11 03:04:55

问题


I've been using google closure compiler for a little bit with my projects, it's awesome!

I've been trying to find out whether or not you can do "includes" in a javascript file that includes other javascript files. I'm trying to have 1 javascript file that "includes" all the files I need then compiles, much like you can do with a LESS import statement, ("@import "../less/bootstrap") for example.

Is this possible? - Or do you have to provide the list of source files at time of compilation in the command line?

Many thanks!


回答1:


When Using Closure-Library

"Includes" are handled via goog.require calls. See https://developers.google.com/closure/library/docs/tutorial#zippy

In un-compiled code, the included scripts are dynamically inserted. During compilation, the compiler will include all the necessary scripts and dead-code elimination will remove the unused methods and symbols.

Other Options

The most popular option for handling JavaScript includes/dependencies is RequireJS. RequireJS does dynamic script insertion. Closure-compiler has a Common JS pass which translates RequireJS require calls to goog.require calls so that the compiler can then include them directly during compilation.



来源:https://stackoverflow.com/questions/18114201/google-closure-compiler-includes

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