As web de­velopers, we are not only faced with finding solutions for complex tasks, but are also forced to grapple with ever more cum­ber­some, emerging processes. Pro­ced­ures such as compiling Less and SCSS into CSS files are not only time consuming, but also un­ne­ces­sary tedious and stressful. To relieve the de­velopers of some of this stress, pro­gram­mers have developed task runners, which automate these kinds of tasks. Par­tic­u­larly for Javas­cript en­vir­on­ments, web de­velopers can benefit from a large number of ap­plic­a­tions, with Grunt and Gulp being among the most popular examples. But what makes these JavaS­cript task runners so special and how do they differ from one another?

What is a task runner?

A task runner is a program that automates one or several computer processes, which the user would otherwise have to do manually. The auto­ma­tion of these pro­ced­ures is extremely valuable, par­tic­u­larly when it comes to tasks that need to be carried out on a regular basis. By op­tim­ising workflow with a task runner, you can save valuable time, which can help you apply yourself in other areas. The different solutions mostly vary in how they are pro­grammed and how they work in­tern­ally. This means users always have control over which pro­ced­ures are carried out by the tool, and which not.

In web de­vel­op­ment, the practical tools play a par­tic­u­larly important role; front-end de­velopers are faced with the daily challenge of per­form­ing simple but re­pet­it­ive processes, such as min­im­ising JavaS­cript codes or compiling pre­pro­cessor stylesheets (Less, Sass, CSS) into finished CSS. Testing the func­tion­al­ity of the in­di­vidu­al modules often takes more time than is available – solutions for sim­pli­fy­ing the workflow are therefore in­dis­pens­able. The most es­tab­lished JavaS­cript task runners, are based on Node.js to automate the re­spect­ive processes. The auto­ma­tion options of the in­di­vidu­al programs can be extended with a number of plugins.

Grunt vs. Gulp – two JavaS­cript task runners in direct com­par­is­on

There are different kinds of task runners for JavaS­cript en­vir­on­ments that differ mainly in how the auto­ma­tion of a process is initiated. On the one hand, there are programs that have the necessary code for executing the cor­res­pond­ing processes right from the start. In this case, the user simply con­fig­ures which tasks he or she would like to submit without directly dealing with the program code. On the other hand, there are JavaS­cript task runners that focus on pro­gram­ming and offer users more freedom in creating their own auto­ma­tion scripts.

Two of the best-known ap­plic­a­tions include Broccoli.js and Brunch, as well as Gulp and Grunt. Find out more about these two leading task runners and their char­ac­ter­ist­ics below.

What is Grunt?

In 2012, JavaS­cript developer Ben Alman launched the command task runner Grunt, which he has been managing and de­vel­op­ing with a small team ever since. The program’s code, which is available under the MIT license, can be down­loaded from the official website and is also available to use for free at GitHub. As with other com­par­able tools, Grunt is based on the JavaS­cript runtime en­vir­on­ment, Node.js, and, thanks to grunt-cli, offers its own command line interface, which can be installed via the Node Package Manager like the task runner itself.

To integrate Grunt into a web project, two files must be added to the root directory of that project. The file package.json typically contains all relevant metadata about the auto­mat­able tasks, such as the name, version, licence, or related de­pend­en­cies. Located in the valid JavaS­cript (gruntfile.js) or Cof­feeScript (gruntfile.coffee), the Grunt file contains the code used to integrate and configure in­di­vidu­al task modules. The modules, also known as plugins, are installed via the npm package man­age­ments mentioned above. 

The official plugin folder counts well over 6000 Grunt tasks for various purposes, such as grunt-contrib-clean (cleans files and folders), grunt-contrib-cssmin (CSS min­im­isa­tion), and grunt-contrib-connect (starts local web servers). Many of these plugins are in principle no different to in­ter­faces to stan­dalone tools. For example, grunt-contrib-uglify, allows users to control the JavaS­cript minimiser UglifyJS from the Grunt file.

Note

The list of plugins is auto­mat­ic­ally generated by the npm module database. Grunt plugins with the ‘contrib’ label are ex­ten­sions that are of­fi­cially supported by the de­velopers. These are also marked with an asterisk.

In addition to the option to modify or extend existing tasks, ex­per­i­enced de­velopers can also create their own auto­ma­tion modules to adjust the task runner to suit their specific re­quire­ments.

What is Gulp?

Gulp is a free task runner, initially launched in July 2013 by American software company Fractal In­nov­a­tions in col­lab­or­a­tion with the GitHub community. As with Grunt, the program is available under an open source MIT license. It is based on the JavaS­cript platform Node.js and, like its com­pet­it­or, uses the npm package manager. Regarding the structure, Grunt and Gulp are re­l­at­ively similar to one another; Gulp is also a command line tool, so it has a suitable user interface with gulp-cli. The package.json con­fig­ur­a­tion file and the gulpfile (gulpfile.js), which lists possible tasks, are also usually used. If both are added to the web directory, the task runner can be used for workflow op­tim­isa­tion.

The gulpfile, which contains JavaS­cript only, combines in­di­vidu­al file op­er­a­tions so that they can be executed via the node.js module stream. Most of the in­di­vidu­al stream processes run in memory before the result is written back to the re­spect­ive files at the end. This is one of the reasons why the task runner is re­cog­nised for its excellent per­form­ance. Since the tasks are pro­grammed from the beginning, but not con­figured, pro­fi­ciency in node.js and JavaS­cript is a basic re­quire­ment to use Gulp. For pro­fes­sion­als, this means a lot of freedom, but it also increases the margin of error.

Gulp also has a number of premade tasks in plugin form. In the official directory on the gulp.js website, users can find over 3000 ex­ten­sions, such as gulp-jekyll (a com­pil­a­tion of Jekyll projects), gulp-php-minify (op­tim­isa­tion of PHP codes), and gulp-css­myicons (for con­vert­ing SVG icons into CSS).

Gulp vs. Grunt: sim­il­ar­it­ies and dif­fer­ences at a glance

At a first glance, Grunt and Gulp don’t seem to differ much from one another in their basic functions; both auto­ma­tion tools are available under the MIT license, so the source code is open and freely available. Both ap­plic­a­tions can be con­trolled from the command line and have their own interface installed along with it. The task runners also use the same package manager, npm. Thanks to their large plugin dir­ect­or­ies, Grunt and Gulp can both easily automate a huge number of tasks. If there are no ex­ten­sions for the desired process, they can be pro­grammed with both tools, although due to the complex structure, both task runners require knowledge of JavaS­cript and node.js.

However, while Gulp is primarily based on the node.js module stream, Grunt mainly uses the fs (file system) module, which high­lights one of the most important dif­fer­ences between the two tools: Grunt is strictly file-oriented and creates temporary local files during the execution of the tasks. Gulp, on the other hand, handles the processes via the memory and writes them in the target file im­me­di­ately, giving the program a speed advantage.

A second dis­tin­guish­ing feature is the re­spect­ive concept of the two solutions. Grunt’s pro­gram­ming and structure gives users some direction; completed tasks located there are already defined and must then simply be con­figured. In com­par­is­on, Gulp allows far more space for in­de­pend­ent pro­gram­ming by providing only the in­di­vidu­al modules. While on the one hand, this makes it easier to un­der­stand the back­grounds and contexts, it also demands much more from the user. The bigger a project is, the more Gulp’s strengths come into play, which is why the new task runner is now the first choice for many people. Thanks to the lower re­quire­ments, however, Grunt is still a valuable tool for smaller, man­age­able projects.

JavaS­cript task runners: Grunt vs. Gulp at a glance

  Grunt Gulp
Released 2012 2013
Website gruntjs.com gulpjs.com
Run via Command line Command line
Based on Node.js Node.js
Concept Con­fig­ur­a­tion over pro­gram­ming Pro­gram­ming over con­fig­ur­a­tion
Process execution Local (temporary files) Memory
Format of source data JavaS­cript (de­clar­a­tions mainly in JSON style) JavaS­cript
Package manager npm npm
Command linr interface grunt-cli gulp-cli
Plugins 6000+ 3000+
Go to Main Menu