In a past post, I mentioned a build tool called Grunt. IT IS AWESOME!
“Grunt is a task-based command line build tool for Javascript projects.”
Here are some basic steps on how to set up Grunt for your project:
1. Install Node.js: http://nodejs.org/
2. Install Phantom.js: http://phantomjs.org/
3. Install Grunt by using: npm install -g grunt
4. Set up a project with grunt init, or you can do specific configurations. Here is one for JQuery: grunt init:jquery.
And ta-da! It sets up your directory and project files.
5. Use grunt watch and it’ll run a batch of predefined tasks whenever you make changes to your files such as:
- lint – Validate files with JSHint.
- min – Minify files with UglifyJS.
- qunit – Run QUnit unit tests in a headless PhantomJS instance.
You can even configure your grunt.js file a bit to cater to your project’s needs. If you prefer Jasmine or Mocha over QUnit, for example, you can specify your grunt.js file to use that instead. When I developed in AS3, I had to literally type a command (i.e., ant or mvn) in the command prompt or double-click an Ant icon in Flash Builder to have the build process going. But Node.js brings along this ability to “watch” your files — it’ll build whenever you hit ctrl+s — and it’ll execute all of those commands that you tell it to in your configuration. All of this sounds like a great boost to your development workflow… don’t you think?
Crazily enough, Grunt is not the only build tool out there for Javascript. There’s Yeoman, Mimosa, Gear, Jake… some people even still use Ant. I have yet to try them all out. Which build process and configurations do you prefer?