Tuesday, July 19, 2011

Intellisense for Google Closure Library in VS 2010 (MVC)

Visual Studio examines your javascript to provide intellisense, and lets you add references to other javascript files to pull info from.  To get closure classes to show up I created a plovr config and did a grep of the whole closure library to find goog.provide calls and converted them to goog.require calls.  Then I did a build to include all the code for closure, resulting in Test.7z (534kb).  It contains the following files:

  • Test\test-config.js: plovr config file, uncomment the module you want to build and run through plovr
  • Test\test.js: goog.require for entire closure library
  • Test\test2.js: missing requires for gears, crypt, test, and some others I'll never use
  • Test\test3.js: also missing goog.ui.editor
  • Test\closure_complete.js: built from test.js, 4.1mb
  • Test\closure_mostly.js: built from test2.js, 2.6mb
  • Test\closure_noeditor.js: built from test3.js, 2.4mb
The easiest way to use them would be to unpack in your Content directory and add this line to the top of your javascript files (has to be the first thing):
/// <reference path="~/Content/Test/closure_mostly.js">

Note: you don't have to add the files to your project, but it uses the same url pathing as if they were part of your web site.

You could also just build your project in WHITESPACE mode and use the generated file.  If you use SIMPLE mode, the closure compiler will shorten your parameter names.  If you use ADVANCED mode the closure compiler would shorten all the names and wouldn't even include code you didn't use.


  1. Wow! Thanks so much. That. Just. Works.

  2. Works in VS2012 also. And you can even put the references line in _references.js in the /Scripts folder.

  3. hey man, I'm kinda new to this whole free spirit java thing. I want to keep using VS, and I'm building an app with limeJS, an HTML5 framework based on closure. the post here was great, and intellisense already recognizes goog functions, so 10x for that! ;)

    however, I wanna do the same for all my lime classes. so I've done the grep part, and created both a js file with all of the goog.provide replaced to require, and did the config file. BUT... how do I compile it?? how do I use this plovr thing? the compiler needs to be compiled, comes in a jar, and I don't know what to do... kinda got lost in all of the documentation. can you give a tip?