GulpJS, is it worth it?

If you're familiar with Javascript and NodeJS, you're probably familiar with Grunt, and with good reason. The most commonly used build tool and task runner for JS/NodeJS projects does it's job, and does it well. So if everyone uses Grunt, (practically every bower module installed will have grunt as its task runner), why  choose an alternative?

My personal answer is code style. 

There aren't that many alternatives to Grunt. At the time of this post, the only two I have heard anything remotely interesting about are GulpJS and Fez. Here, I will be explaining my choice of the former. The latter I may try in some future project, but am currently less than familiar with.

 

So GulpJS, what is it?

Like GruntJS, it's a task runner, or build tool, or whatever you wish to call it. (Automation utility?). Anyways, GulpJS has the same goal as Grunt, only it does it somewhat differently. GulpJS calls itself a streaming build system, which is one of the major differences between it and Grunt. Where Grunt focuses on files, GulpJS focuses on streams. In essence, Grunt tasks will keep reading files before a task begins and writing them back after a task finishes manipulating it. Tasks in GulpJS are pooled into an in-memory array of file streams, passed through from each task to the next in a "pipeline", writing only the finished product (files) to their intended destination.

The second difference between GruntJS and GulpJS is speed. Sadly, I don't have comparable benchmarks as of yet, but so far, it seems to me that Gulp is just a wee bit faster than Grunt, probably to do with not having to write files to disk all the time. It's not a huge difference, but it is noticeable. 

The third, and to me the most important difference between Gulp and Grunt is the code style. Grunt modules and tasks rely heavily on configuration. I like configuration, but the json for grunt configuration very quickly becomes long and cumbersome and rather unreadable. At least it does to me. Gulp tasks read like, feel like and are javascript code. 
 

A task to minify some html and create an angular template cache in my project looks like this:
 

gulp.task('htmlmin', function(){
   gulp.src('./client/index.html')
       .pipe(htmlMin({quotes:true}))
       .pipe(gulp.dest('./dist/index/'));

    gulp.src('./client/app/**/*.tpl.html')
       .pipe(htmlMin({quotes:true}))
       .pipe(ngTempCache({
            standalone:true
        }))
       .pipe(uglify())
       .pipe(gulp.dest(dist+ 'app/'));
});

 

It's easy to read, easy to modify and quite short. Gulp tasks can also have dependency tasks, much like grunt does, so that makes it even shorter.

This code style is what eventually convinced me to use Gulp in my current project, and I'm quite happy with my choice.

 

I'll also note that while the plugin library for Grunt is vastly greater (2500+) than the Gulp plugin library (430+), the latter library probably already includes most of what you'd use in most of your projects. I've also found that Gulp plugins are of higher quality than Grunt plugins, mostly due to the Gulp's strict plugin guildlines.

So is GulpJS worth it? I found the answer to be a great big YES. But don't take my word for it, try it yourself and if you still don't like it, Grunt is still a very good tool.

 

Thank you for your interest!

We will contact you as soon as possible.

Send us a message

Oops, something went wrong
Please try again or contact us by email at info@tikalk.com