How to set up Grunt on Ubuntu— Easy steps

Grunt is a JavaScript task runner which helps to perform repetitive tasks like compilation, minification, unit testing, linting, etc. It complies Sass into CSS, Compress CSS, JS, files and Combine JS files to single file.

There are couple of software dependencies to make grunt up and running.

  1. Node
  2. npm
  3. Grunt-CLI
  4. Grunt
  5. Grunt plugins

Run the following Commands on your terminal from the project directory.

  1. Installing node.js and node.js package manager (npm)
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npm

2. Installing Grunt-cli

npm install -g grunt-cli

3. Creating package.json

This file describe project name, git repository and dependencies.

npm init

It will ask for project name, version, description, entry point (core file), test command, git repo, keywords, author, license. It is not mandatory to fill all the content.

4. Installing Grunt

npm install grunt --save-dev

“--save-dev” adds grunt to the list of packages in the package.json file.

5. Creating gruntfile.js

This file configure tasks, loads plugins, and register tasks. Task is an automated command which you can create or you can choose from 4,000 Grunt plugins.

Following is a skeleton of the grunt js file.

module.exports = function(grunt) {   
// Project configuration.
pkg: grunt.file.readJSON('package.json'),
 // Load the plugins. 
// grunt.loadNpmTasks( );
// Default task(s).
// grunt.registerTask('default', [ ]);

Fill this file according to the tasks you need to do and your up and running with grunt. :)

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.