Closure library at server side

130 views
Skip to first unread message

George Moschovitis

unread,
Aug 18, 2010, 1:21:39 PM8/18/10
to Closure Library Discuss
Is anyone actually using Closure Library in a server side context? I
am wondering if there is an implementation of goog.require() & co for
something like Rhino.

-g.

--
http://www.appenginejs.org

Nathan Naze

unread,
Aug 18, 2010, 1:41:44 PM8/18/10
to closure-lib...@googlegroups.com
The debug loader assumes the existence of the DOM and appends <script>
tags to load additional files. But if you used closurebuilder.py to
determine proper dependency order, disable debug the loader, and feed
Rhino the files in the correct order, it might work. It's also
possible to script closurebuilder with python. I'd love to know if
you have success with this.

Nathan

John Lenz

unread,
Aug 18, 2010, 7:51:33 PM8/18/10
to closure-lib...@googlegroups.com
On Wed, Aug 18, 2010 at 10:41 AM, Nathan Naze <nn...@google.com> wrote:
The debug loader assumes the existence of the DOM and appends <script>
tags to load additional files.  But if you used closurebuilder.py to
determine proper dependency order, disable debug the loader, and feed
Rhino the files in the correct order, it might work.  

Or if you simply build it use the Closure Compiler, which would strip the goog.provide and goog.require tags.

George Moschovitis

unread,
Aug 19, 2010, 1:19:27 AM8/19/10
to Closure Library Discuss
As an experiment, I 'll try to implement a rhino based version of the
debug require/provide mechanism. Have to find some time first though.

-g.

Shawn Brenneman

unread,
Aug 19, 2010, 4:45:34 PM8/19/10
to closure-lib...@googlegroups.com
Good luck! It might be easier to use the compiler to combine the
sources into a single file, even if you disable all of the renaming
passes and optimizations. On the other hand, debugging will be much
easier if you can get things working with the original, individual
files.

Shawn

Nathan Naze

unread,
Aug 19, 2010, 4:50:40 PM8/19/10
to closure-lib...@googlegroups.com
There is an output option in closurebuilder.py to just output the
files in dependency order. So on unix, you may be able to do
something like this:

./closurebuilder.py <options> | xargs <command to run rhino>

And then the warnings would match up with the source files.

Nathan

Morgan Kleene

unread,
Sep 13, 2010, 12:29:41 PM9/13/10
to Closure Library Discuss
I'm using the approach of combining all of the files into a single
file and then sending them to a browser under the control of
JsTestDriver. The dynamic loading mechanism doesn't work in this
context either for a couple of reasons but my tests run fine.

On Aug 19, 4:50 pm, Nathan Naze <nn...@google.com> wrote:
> There is an output option in closurebuilder.py to just output the
> files in dependency order.  So on unix, you may be able to do
> something like this:
>
> ./closurebuilder.py <options> | xargs <command to run rhino>
>
> And then the warnings would match up with the source files.
>
> Nathan
>

stringa

unread,
Apr 30, 2013, 10:12:08 PM4/30/13
to closure-lib...@googlegroups.com, morgan...@gmail.com
I found this link for anyone that cares.

http://gatapia.github.io/nclosure/test.html

Guido Tapia

unread,
May 1, 2013, 5:06:56 AM5/1/13
to closure-lib...@googlegroups.com
I haven't maintained nclosure for a while. It was written on node 0.2 do doubt it still even works.

thanpolas

unread,
May 17, 2013, 10:59:04 AM5/17/13
to closure-lib...@googlegroups.com
I used nclosure on node 0.6 a while ago, still in my crosshair when i'll need it again...

Nick Santos

unread,
May 17, 2013, 11:10:49 AM5/17/13
to closure-lib...@googlegroups.com

I tried nclosure on node .10 and the basic functionality worked but some options were broken (like using a custom closure-library). It worked better than some of the other solutions I've tried.

--
 
---
You received this message because you are subscribed to the Google Groups "Closure Library Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to closure-library-d...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Daniel Steigerwald

unread,
May 17, 2013, 1:58:45 PM5/17/13
to closure-lib...@googlegroups.com
You can use Closure on server side easily. Set node global in base.js 

file = file.replace('var goog = goog || {};', 'global.goog = global.goog || {};');
file = file.replace('goog.global = this;', 'goog.global = global;');

And eval deps.js

var getDeps = function(depsPath, prefix) {
  var deps = {};
  var depsFile = fs.readFileSync(depsPath, 'utf8');
  var goog = {
    addDependency: function(src, namespaces, dependencies) {
      for (var i = 0; i < namespaces.length; i++) {
        deps[namespaces[i]] = {
          src: src.replace(prefix, ''),
          dependencies: dependencies
        };
      }
    }
  };
  eval(depsFile);
  return deps;
};

Done :)


    
Reply all
Reply to author
Forward
0 new messages