简体   繁体   中英

Google Closure external dependencies

I want to load one single, minified javascript file per page instead of dozens. I'd like to use Closure Compiler to create these so called modules. But I have dependencies like jQuery or Codemirror for example.

Can I make the Compiler automatically include these for all output, without having to wrap these libraries into Closure specific code to provide a namespace recognized by Closure?

Yes - if you use the SIMPLE_OPTIMIZATIONS level of the compiler you can feed all your dependencies into the compiler and it will output a single JS file. SIMPLE_OPTIMIZATIONS will work correctly with most code libraries.

java -jar compiler.jar -O SIMPLE --js jquery.s --js otherlib.js --js myfile.js
    --js_output_file mycombinedfile.js

However, Closure-compiler will need some method of determining the source files if you don't want to list them manually. The compiler can be used with the closure-library dependency management or with Common JS dependency management.

If you don't want to use either of those, you would need a method (like a script) to determine all of the applicable source files and feed those to the compiler . 将它们提供给编译器。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM