The Closure Compiler has two modes, simple and advanced. For my tutorial I am only working with simple because there are some caveats you have to be careful of with advanced that you can find here.
Let’s work with an example of what this will do. Say you take the sample Google code:
After Minification with Simple Optimizations:
After Minification with Advanced Optimizations:
Down to business
Okay now that you got to see the sample results, let’s get down and dirty with it.
- Install Java Runtime Environment 7 on your computer and the TFS Build server.
- Add Compiler.jar to your solution and source. Or alternatively put it on a shared path that your development team and build server can access.
- In notepad, open up the project file (vbproj or csproj). I like Notepad++, but use your favorite editor.
- In the second line where it starts
, you need to add a DefaultTarget. I use AfterBuild but there are various ones you can use. Just like:
- A few lines down your PropertyGroup will start. Just before the ending PropertyGroup add a property called JavaPath like:
This step really is optional, but I’m not a fan of hard coding paths in the project file so I pass this in during the TFS build process. Either way works.
- Go to the end of the file. You now need to add your target (change paths as necessary).
Now, you will notice I add a condition that requires it to be a TFSBuild. This is a simple parameter I pass in during the build. This is optional, however it is nice to only have the minification occur during the build. Also notice how I do the quotes around the JavaPath.
- Save the project file. Now open up your Build Definition in Visual Studio.
- Go to the Process section on the left, then open “3. Advanced”.
There is a line called MSBuild Arguments. Enter the following (change paths as necessary): /p:IsTFSBuild=”True” /p:JavaPath=”C:Program Files (x86)Javajre7bin"
- Run a build.