Google Closure编译器包括 [英] Google Closure Compiler Includes
问题描述
我在我的项目中一直使用google封闭编译器,太棒了!
我一直试图找出您是否可以在包含其他JavaScript文件的javascript文件中执行包含"操作.我正在尝试让1个javascript文件包含"我需要的所有文件,然后进行编译,就像您可以使用LESS导入语句(例如,"@ import"../less/bootstrap")一样.>
这可能吗? -还是在编译时必须在命令行中提供源文件列表?
非常感谢!
使用Closure-Library时
包含"通过goog.require调用进行处理.请参见 https://developers.google.com/closure/library/docs/tutorial# zippy
在未编译的代码中,包含的脚本是动态插入的.在编译过程中,编译器将包含所有必需的脚本,而消除死代码将删除未使用的方法和符号.
其他选项
用于处理JavaScript包含/依赖项的最流行的选项是 RequireJS . RequireJS执行动态脚本插入. Closure-compiler具有Common JS pass,可将RequireJS require
调用转换为goog.require
调用,以便编译器可以在编译期间直接包括它们.
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!
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.
这篇关于Google Closure编译器包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!