Search code examples
google-closure-compilergoogle-closure-library

How do I use the Google Closure Compiler to build one file?


The question is a little more complicated than the title suggests, so allow me to elaborate. I have a project that is split into two repositories. The both use Google Closure for dependency management and compilation. I need to deliver a compiled version of project A to project B. Project B does advanced optimizations, so project A must be whitespace only. The problem is that I can't find a way to satisfy all my requirements for compiled A, which are:

  • It must be ordered by dependency
  • There can be no goog base code, i.e., var goog=goog||{}...
  • Similarly, there can be no goog.provides or goog.requires
  • It must be whitespace-only compiled

So far I've tried:

  • Closurebuilder.py
    • pros: can be whitespace only
    • problem: Has base code; getting duplicate namespace issues
  • Compiler.jar
    • problem: whitespace-only mode keeps goog.provides and requires in
    • problem: any optimizations of project A break project B

Has anyone made a similar setup work?


Solution

  • I solved it by getting the dependencies from closurebuilder.py and simply concatenating them together, in order, into one file. It gets shipped to a built repo, where B can pick it up via npm, and it gets run through a closure script (that adv. optimizes it and splits it into modules).