Original author(s) | Ben Alman |
---|---|
Developer(s) | Ben Alman, Tyler Kellen, Kyle Robinson Young, Vlad Filippov, Sindre Sorhus, Isaac Durazo, Jarrod Overson, Tim Branyen, Jörn Zaefferer, James Smith, Dave Geddes |
Initial release | 4 April 2016 [1] |
Stable release | 1.4.1 / 22 April 2021 [2] |
Repository | github |
Written in | JavaScript |
Operating system | Linux, macOS, Windows |
Platform | Node.js |
Available in | English |
Type | Task Runner, Build tool |
License | MIT License [3] [4] |
Website | gruntjs |
Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node.js. It is distributed via npm. As of October 2022, there were more than 6,000 plugins available in the Grunt ecosystem. [5]
Companies and projects that use Grunt include Adobe Systems, jQuery, Twitter, Mozilla, Bootstrap, Cloudant, Opera, WordPress, Walmart, and Microsoft. [5]
Grunt was originally created by Ben Alman in 2012 as an efficient alternative to simplify writing and maintaining a suite of JavaScript build process tasks in one huge file. It was designed as a task-based command line build tool for JavaScript projects. [6]
Grunt is primarily used to automate tasks that need to be performed routinely. There are thousands of plugins that can be installed and used directly to accomplish some commonly used tasks. One of Grunt's most desirable features is that it is highly customizable—i.e., it allows developers to add, extend, and modify custom tasks to fit their personal needs; each task has a set of configuration options that the user can set. Moreover, Grunt offers the ability to define custom tasks, which can combine multiple existing tasks into a single task or add entirely new functionality. [7]
Grunt's command-line interface (CLI) can be installed globally through npm. Executing the grunt
command will load and run the version of Grunt locally installed in the current directory. Hence, we can maintain different versions of Grunt in different folders and execute each one as we wish. [5]
To use Grunt in a project, two specific files need to be created in the root directory, namely package.json and a Gruntfile.
dependencies
or the devDependencies
section.Tasks are the modules that perform a specified job. They are defined in the Gruntfile.
Developers can load predefined tasks from existing Grunt plugins and/or write custom code to define their own tasks depending on their requirements. Once defined, these tasks can be run from the command line by simply executing grunt <taskname>
. If the <taskname>
defined in the Gruntfile is 'default' then simply executing grunt
will suffice.
The following is an example of a Gruntfile written in JavaScript that shows how to load plugins, create custom tasks and configure them:
module.exports=function(grunt){// Task configurationgrunt.initConfig({taskName1:'Task1 Configuration',taskName2:'Task2 Configuration'});// Loads pluginsgrunt.loadNpmTasks('pluginName1');grunt.loadNpmTasks('pluginName2');// Custom tasksgrunt.registerTask('customTaskName1','Custom task description',function(taskParameter){// Custom statements});// Combining multiple tasks to a single taskgrunt.registerTask('customTaskName2',['taskName1','customTaskName1']);// Default task - runs if task name is not specifiedgrunt.registerTask('default',['customTaskName2']);};
In the above example, executing the grunt
command will run <customtaskName2>
which has been defined above as a combination of both <taskName1>
and <customTaskName1>
.
Plugins are reusable code that defines a set of tasks. Each plugin internally contains a tasks directory with JavaScript files that have the same syntax as a Gruntfile. Most of the Grunt plugins are published with the keyword gruntplugin
[8] in npm and prefixed with grunt
. This helps Grunt in showing all the plugins in Grunt's plugin listing. The plugins officially supported by Grunt are prefixed with grunt-contrib
[8] and are also marked with a star symbol in the plugins listing. Some popular plugins include grunt-contrib-watch, grunt-contrib-clean, grunt-contrib-uglify.
Developers can even create their own Grunt plugins by using the grunt-init
plugin and publish them to npm using the npm publish
command.
The following are some of the advantages of using Grunt:
Ant or Apache Ant is a Java-based build tool. Ant has a little over a hundred built-in tasks that are better suited to projects with a Java build structure. Writing custom code in Ant requires users to write a JAR file and reference it from XML. This would add unnecessary complexities to projects that do not require Java themselves. Ant build configurations are listed in XML rather than in JSON format. [7]
Rake allows developers to define tasks in Ruby. Rake doesn't have the concept of plugins or predefined tasks which means all the required actions must be written and then executed. This makes the developments costly when compared to Grunt which has a large set of reusable plugins. [7]
Gulp.js is a JavaScript based task runner tool similar to Grunt since both follow a modular-based architecture and are based on npm. Gulp tasks are defined by code rather than configuration. Gulp is faster than Grunt. Grunt uses temporary files to transfer output from one task to another whereas in Gulp files are piped between the tasks. [7]
JUnit is a test automation framework for the Java programming language. JUnit is often used for unit testing, and is one of the xUnit frameworks.
Apache Ant is a software tool for automating software build processes for Java applications which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implemented using the Java language and requires the Java platform. Unlike Make, which uses the Makefile format, Ant uses XML to describe the code build process and its dependencies.
Maven is a build automation tool used primarily for Java projects. Maven can also be used to build and manage projects written in C#, Ruby, Scala, and other languages. The Maven project is hosted by The Apache Software Foundation, where it was formerly part of the Jakarta Project.
.properties is a file extension for files mainly used in Java-related technologies to store the configurable parameters of an application. They can also be used for storing strings for Internationalization and localization; these are known as Property Resource Bundles.
MagicDraw is a proprietary visual UML, SysML, BPMN, and UPDM modeling tool with team collaboration support.
TypeScript is a free and open-source high-level programming language developed by Microsoft that adds static typing with optional type annotations to JavaScript. It is designed for the development of large applications and transpiles to JavaScript.
sbt is an open-source build tool which can build Java, Scala, and Kotlin projects. It aims to streamline the procedure of constructing, compiling, testing, and packaging applications, libraries, and frameworks. sbt is highly adaptable, permitting developers to customize the build process according to their project's specific needs.
Node.js is a cross-platform, open-source JavaScript runtime environment that can run on Windows, Linux, Unix, macOS, and more. Node.js runs on the V8 JavaScript engine, and executes JavaScript code outside a web browser.
Gradle is a build automation tool for multi-language software development. It controls the development process in the tasks of compilation and packaging to testing, deployment, and publishing. Supported languages include Java, C/C++, and JavaScript. Gradle builds on the concepts of Apache Ant and Apache Maven, and introduces a Groovy- and Kotlin-based domain-specific language contrasted with the XML-based project configuration used by Maven. Gradle uses a directed acyclic graph to determine the order in which tasks can be run, through providing dependency management. It runs on the Java Virtual Machine.
npm is a package manager for the JavaScript programming language maintained by npm, Inc., a subsidiary of GitHub. npm is the default package manager for the JavaScript runtime environment Node.js and is included as a recommended feature in the Node.js installer.
Amber Smalltalk, formerly named Jtalk, is an implementation of the programming language Smalltalk-80, that runs on the JavaScript runtime of a web browser. It is designed to enable client-side development using Smalltalk. The programming environment in Amber is named Helios.
Yeoman is an open source client-side scaffolding tool for web applications. Yeoman runs as a command-line interface written for Node.js and combines several functions into one place, such as generating a starter template, managing dependencies, running unit tests, providing a local development server, and optimizing production code for deployment.
Webpack is a free and open-source module bundler for JavaScript. It is made primarily for JavaScript, but it can transform front-end assets such as HTML, CSS, and images if the corresponding loaders are included. Webpack takes modules with dependencies and generates static assets representing those modules.
Caddy is an extensible, cross-platform, open-source web server written in Go.
gulp is an open-source JavaScript toolkit, used as a streaming build system in front-end web development.
PostCSS is a software development tool that uses JavaScript-based plugins to automate routine CSS operations. It was designed by Andrey Sitnik with the idea taking its origin in his front-end work for Evil Martians.
This is a list of articles related to the JavaScript programming language.
Yarn is one of the main JavaScript package managers, developed in 2016 by Sebastian McKenzie of Meta for the Node.js JavaScript runtime environment. An alternative to the npm package manager, Yarn was created as a collaboration of Facebook, Exponent, Google, and Tilde to solve consistency, security, and performance problems with large codebases.
Deno is a runtime for JavaScript, TypeScript, and WebAssembly that is based on the V8 JavaScript engine and the Rust programming language. Deno was co-created by Ryan Dahl, who also created Node.js.
{{cite book}}
: CS1 maint: location (link)