If you are developing with closure library you should have a and phantomjs, then you might want to include some of you’re development code into the phantomjs runtime. It turns out you could hack into the goog.provide/require statements to override the IMPORT function.

The following code will make the entire goog.* namespace available to be required via goog.require().

  var fs = require('fs');

  // the relative path to the goog folder.
  CLOSURE_BASE_PATH = 'src/closure-library/closure/goog/';

  // the function to inject scripts.
  CLOSURE_IMPORT_SCRIPT = function(src) {
    return phantom.injectJs(fs.absolute(src));
  };

  // import the base.js file.
  CLOSURE_IMPORT_SCRIPT(fs.join(CLOSURE_BASE_PATH, 'base.js'));

If you also parts of your own codebase, you will need to load the relevant deps.js files.

  CLOSURE_IMPORT_SCRIPT('src/path/to/deps.js');

The following script provides this functionality:

/assets/closure-setup.js:

 1 /**
 2  * @namespace {filesystem}
 3  */
 4 var fs = require("fs");
 5 
 6 /**
 7  * @namespace {closure}
 8  */
 9 exports = exports || {};
10 
11 /**
12  * @param {string} src
13  *        The source to pull in.
14  */
15 exports.import = function(src) {
16   return phantom.injectJs(fs.absolute(src));
17 };
18 
19 
20 
21 /**
22  * @const
23  * @type {string}
24  */
25 exports.BASE = fs.join(module.dirname,
26                        '../src/closure-library/closure/goog/')
27 
28 
29 
30 /**
31  * @param {string=} opt_basepath
32  *        The basepath.
33  */
34 exports.setup = function(opt_basepath) {
35   if (!top['CLOSURE_IMPORT_SCRIPT']) {
36     var basepath = opt_basepath || exports.BASE;
37     CLOSURE_BASE_PATH = basepath;
38     CLOSURE_IMPORT_SCRIPT = exports.import;
39     CLOSURE_IMPORT_SCRIPT(fs.join(CLOSURE_BASE_PATH, 'base.js'));
40     hasBeenSetUp = true;
41   }
42 }

To use it, download and save it somewhere in you’re project, fix the paths in the script to point to the correct sources and then require it with the relative path and run setup().

  require('./assets/closure-setup.js').setup();