Smashinglabs

Sebastian Poręba's blog

Makefile for Google Closure Compiler

I’ve been using online version of Google Closure Compiler as a minifier for my projects for some time now. I always wondered how the advanced compilation works, but never really gave it a shot. Lately I started working on a university project and as you may know, academics do not like JavaScript in general. To make it even worse for them, I decided to prepare a very complex JS setup, with fully annotated Google Closure code. Not only out of spice, but also to prove that using a proper approach, it can be fast and well-structured.

I’m not going to describe here how the Compiler works in detail. In short words, it scans your files looking for comments in a specific, JSDoc-like format and makes use of them. There is also a tool called calcdeps which is a linker – it scans files for dependencies and helps compiler to merge files in the correct order.

My project structure

To make it even more fun, I decided to write a Makefile which will be a final jaw-dropper.

PYTHON   = python
CALCDEPS = ~/closure/closure-library-read-only/closure/bin/calcdeps.py
CLOSURECOMPILER = ~/closure/compiler.jar

all:
	$(PYTHON) $(CALCDEPS) -p src -i src/init.js -o compiled -c $(CLOSURECOMPILER) > scripts/ai-bot-compiled.js

It works like charm, “make” is compiling all required files from src folder, merging them into one.
I was surprised how easy it was – calcdeps takes a path (-p) where you store all your libraries and an initial file (-i). The rest is based on goog.require(classname) and goog.provide(classname) calls from files. I barely used Google Closure Tools so far, but the Compiler is absolutely great!

Google Closure: http://code.google.com/intl/pl/closure/
Book: http://www.amazon.com/Closure-Definitive-Guide-Michael-Bolin/dp/1449381871


  • RSS
  • Facebook
  • Twitter

3D Tetris with Three

[include file="ThreejsTetrisMenu.php"] Joined or separated? Think about the way we play Tetris. ...

3D Tetris with Three

[include file="ThreejsTetrisMenu.php"] Preparation First you need to download Three.js: https://github.com/mrdoob/three.js I also use Stats ...

gMap 3.3.0 released

As always, you can download it from github. I had a ...

JavaScript performan

Trace JIT is no more I was surprised by the news that trace ...

Lecture for GTUG: Ja

My main topics were: Optimization in general DOM Reflow/repaint Garbage collector JIT Google Closure (Compiler/Tools/Library) You can ...

gMap 3.3.0 released

As always, you can download it from github. I had a ...

Lecture for GTUG: Ja

My main topics were: Optimization in general DOM Reflow/repaint Garbage collector JIT Google Closure (Compiler/Tools/Library) You can ...

Unit testing for jQu

In part 1 I described basics of unit testing in ...

Unit testing for jQu

There are few testing frameworks dedicated for frontend that are ...

What do we need for

Contents Better graphics Involve desktop game developers Easier animations Code like in C++ Fix WebGL Write ...