Google Closure Compiler Includes

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.

链接地址: http://www.djcxy.com/p/43698.html

上一篇: ANTLR(或其他):解析与评估解耦

下一篇: Google Closure编译器包含