Are there any projects that used node.js and closure-compiler (CC for short) together?
The official CC recommendation is to compile all code for an application toget
I replaced my old approach with a way simpler approach:
New approach
Funny thing is that I didn't even had to add an extern for the require() calls. The Google Closure compiler understands that automagically. I did have to add externs for nodejs modules that I use.
Old approach
As requested by OP, I will elaborated on my way of compiling node.js code with Google Closure Compiler.
I was inspired by the way bolinfest solved the problem and my solution uses the same principle. The difference is that I made one node.js script that does everything, including inlining modules (bolinfest's solution lets GCC take care of that). This makes it more automated, but also more fragile.
I just added code comments to every step I take to compile server code. See this commit: https://github.com/blaise-io/xssnake/commit/da52219567b3941f13b8d94e36f743b0cbef44a3
To summarize:
require() calls, including the assignment part.var Server = require('./lib/server.js');require() call, so I repeat step 3 and 4 recursively until all require() calls are gone and I'm left with one huge string containing all code.require calls to the compiled code.Pre-Compiled code.
All require calls are removed. All my code is flattened.
http://pastebin.com/eC2rVMiN
Post-Compiled code.
Node.js core require calls have been prepended manually.
http://pastebin.com/uB8CaejN
Why you should not do it this way:
require calls, inlining and removing module.exports. This is fragile, as it does not cover all syntax variations.Why you should: