Frage

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!

War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top