04
Aug

Using Grunt JS with Apache Sling

This weekend I’ve given a try to see how difficult would it be to extract from Maven everything that has to do with the compilation of client-side files ( CofeeScript, JS, CSS, etc ), while keeping the rest of the build in Maven.

Goal

  • Live-reload client-side source files in Apache Sling w/o Maven, as soon as source files change.
  • Compile CoffeeScript files with GruntJS, b/c it’s faster than compiling with Maven, and then deploy the compiled files into JCR.

Solution

  1. First Step: configure a Grunt JS script that watches for CoffeeScript files, compiling them in the same target folder with Maven.  In my case that was ${project.build.directory}/coffee/js.
  2. Once compiled, deploy JS files in Apache Sling, in the right JCR path.
  3. Use grunt-contrib-watch plugin to update the page in Sling automatically.
  4. Integrate Grunt JS back into the Maven build

 Implementation

Source code from Gist.

 

3 Comments

Sorry, the comment form is closed at this time.

Comments RSS Feed