I am starting a new project - a reasonably large application - that features just JavaScript code (excepting a little HTML/CSS) and have been giving some thought to a suitable build process and the tooling options available. I'd love to hear from anyone who has had similar choices to make recently.
I do have some essential requirements (I might add more bells and whistles later, but these are really necessary):
- Minification of code: I'd like the option to be really aggressive with this for staging/production builds (think Closure Compiler with advanced optimisations.)
- Code quality checking: JSLint or similar - something to throw up any glaring issues with the code.
- Unit testing: I have a very strong preference for JsTestDriver when it comes to unit testing JS - the ability to test multiple browsers simultaneously (and quickly!) and to automate easily are the main attractions. That said, I'd happily look into alternatives.
- Continuous integration-friendly: we make use of a CI server (BuildBot, for the record) and any build script(s) would have to be easily automated.
I've already thought of a couple of possibilities (some details are guesswork, do correct me):
Pros:
- Seems to involve the least work, not least because of the excellent HTML5 Boilerplate build script as a starting point
- Many tools are written (or have wrappers) in Java - including JSLint/Hint, Closure Compiler and JsTestDriver
- Ant scripts are standard fare when it comes to CI servers
- Happily cross-platform
Cons:
- Running many JAR files possibly a bit slow? (I'm thinking in terms of initialisation more than execution)
Pros:
- (Well-written) Ruby scripts are quite probably nicer to deal with than piles of XML
- There are wrappers (often gems) for many relevant tools, such as JSLint, JSTestDriver and UglifyJS
- Equally cross-platform
Cons:
- Knowledge of Ruby involved to modify the build process. While this isn't a huge deal, we're not a Ruby shop and the alternatives don't have quite the same barrier to entry
- Few of the tools actually run in Ruby and are actually wrappers around Java or JavaScript code executing - this seems like it may slow things down
Pros:
- Plenty of tools available in JavaScript (and as modules available to Node) - JSLint/Hint, UglifyJS etc.
- Presumably pretty quick (this blog post illustrates UglifyJS outpacing Closure Compiler quite comprehensively, for one)
Cons:
- Node (particularly NPM) doesn't seem quite there on Windows yet (we have some developers running Windows)
- There doesn't seem to be any existing support for using JsTestDriver from a Node app (but a wrapper could be written)
Based on that, Ant seems the favourite at present.
js Build Tools. Build tools assist JavaScript developers with task automation. For example, these tools can install code-based components automatically.
A brief follow-up now that the project is complete:
Ant was chosen to build the project, but later on I wished I'd used a Node-based solution. While you can make Ant do most things, it's often verbose or necessary to write a lot of Java code to make it do anything out of the ordinary. Node and NPM improved on Windows significantly throughout the lifetime of the project and there are now a surfeit of testing solutions (BusterJS is interesting me most) that can easily be called from a Node script.
I was intrigued to see the release of Grunt, which seems like it could have been particularly useful for a project like this. I'd be keen to hear people's experiences of this tool used with projects of reasonable size (for reference, the project I have just completed had around 120 JavaScript source files.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With