最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Build process tools for JavaScript - Stack Overflow

programmeradmin5浏览0评论

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.

Some requirements

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.

Possible solutions

I've already thought of a couple of possibilities (some details are guesswork, do correct me):

Ant

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)

Ruby/Rake

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

Node (and probably something like Jake)

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.

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.

Some requirements

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.

Possible solutions

I've already thought of a couple of possibilities (some details are guesswork, do correct me):

Ant

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)

Ruby/Rake

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

Node (and probably something like Jake)

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.

Share Improve this question asked Oct 10, 2011 at 22:05 Philip RosePhilip Rose 2113 silver badges8 bronze badges 2
  • the html5 boilerplate build.xml isn't that great - you'll want to stay away from ant-contrib. it's the quickest way to get a rat's nest of unmaintainable gunk. I'd recommend you stay away from ant. If you go that way -let ant be ant, don't try to make it feel like a scripting language. – thekbb Commented Mar 7, 2013 at 22:58
  • Maybe Gradle with some plugins ex. eriwen.github.io/gradle-js-plugin ? – ljader Commented Sep 15, 2013 at 15:03
Add a comment  | 

4 Answers 4

Reset to default 5

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.)

Over a year later, but...

If r.js + RequireJS is your thing, and you want automated builds plus development aid/help like linting, minification, concatenation, asset compilation, etc, check out Mimosa. It'll do a lot of those things right out of the box with minimal configuration.

I like RequireJS for dependency management/dynamic script loading, and building a single file. For continuous integration check out TeamCity from JetBrains.

Gulp

There is a new build tool called gulp that uses node streams, so it does not have to write any temporary files between steps (like grunt). It's fast.

发布评论

评论列表(0)

  1. 暂无评论