Activate your free membership today | Log-in

Monday, March 9th, 2009

JavaScript build process using Ant

Category: Utility

<>p>Johan "Spocke" Sörlin of Moxiecode has written an article on a build process that uses Ant to munge JavaScript.

The preprocessor lives in the open source js build tools project and allows you to do C-style ifdef type work:

JAVASCRIPT:
  1.  
  2. // #ifdef somedefine
  3.  
  4. someLogic();
  5.  
  6. // #endif
  7.  
  8. someOtherLogic();
  9.  

You can tie this together with Ant by using some custom rules to process and then compress:

XML:
  1.  
  2. <preprocess infile="file.js" outfile="file.processed.js" defines="somedefine,someotherdefine" />
  3.  
  4. <yuicompress infile="file.js" outfile="file.min.js" />
  5.  

Related Content:

Posted by Dion Almaer at 7:22 am
1 Comment

++---
2.9 rating from 17 votes

1 Comment »

Comments feed TrackBack URI

I guess this would be a good idea, as long as the build process is very simple. Ant gets really hairy when you try to apply conditional logic — for this reason I’m looking at Buildr (http://buildr.apache.org/) instead — because XML is useful only as a declarative, not an imperative, language.

Comment by pianoroy — March 9, 2009

Leave a comment

You must be logged in to post a comment.