Advice on integrating Closure Compiler to build process

422 views Asked by At

We want to use Google Closure in our build process as follows:

  • when in development mode, include base.js and dynamically add script tags
  • when in production, use minification and all the other cools stuff

This is a Java project running on Tomcat and we are transitioning from Maven to Gradle, and have continuous integration set up using Jenkins. We use Apache Tiles as a frontend technology.

I came up with a possible solution, but I feel it painful and ugly, and would like to know if there are better (cleaner, simpler, etc...) solutions.

My stinky solution:

Use a Tomcat context parameter to identify production mode. In the JSP files, check for this variable and include Closure's base.js or the minified js file accordingly.

So... any other suggestions? Possibly with pros/cons?

1

There are 1 answers

0
Blaise On

I use Grunt for this. Grunt is a tool to automate frontend minification, compilation, unit testing, etc.

URL: http://gruntjs.com/getting-started

In Grunt, you create a Gruntfile and register a task that consists of one or more reusable configs. A config does something like: "minify all files in this directory and output to that file". So what you would do is register two tasks: one for dev and one for production, with some configs in common, and some configs specifically for that environment.

You can pass your Tomcat context parameter to Grunt as a parameter (cleanest), or alternatively read it as an environment variable inside the Gruntfile and create an if branch in the configuration.

Grunt has a lot of plugins: The plugins you need are already available: