Setting-Up Grunt

Create a JSON file called package.json defining the name, version, author and description fields about your project, in the format shown below

				
				{
				   "name": "ScriptVerse",
				   "version": "0.1.0",
				   "author": "Dennis Gabil",
				   "description": "Online tutorial on Web Technologies"
				}
				
			

Save it in the root directory of your project (where your index.html file is).

Create another file Gruntfile.js in the same root directory, and include the below lines of code

				
				module.exports = function(grunt) {
					grunt.initConfig({
						pkg: grunt.file.readJSON('package.json')
					});	

					grunt.registerTask('default', []);
				}
				
			

Here, module.exports is a Node.js function to which is passed the grunt object, which is exported as a whole. Tasks are configured in the grunt.initConfig method. The pkg property reads the settings of the project from the package.json file created earlier. Tasks to be performed goes inside the square brackets of grunt.registerTask('default', []);. We will learn more on this in the next chapter.

After creating the files package.json and Gruntfile.js, install the npm module grunt-cli globally

				npm install -g grunt-cli
			

In the project's root directory, install grunt locally

				npm install grunt --save-dev
			

After the installation, the package.json file will have a new field called devDependencies listing the installed plugin(s)

				
				{
				  "name": "ScriptVerse",
				  "version": "0.1.0",
				  "description": "Online tutorial on Web Technologies",
				  "devDependencies": {
				    "grunt": "^0.4.5"
				  }
				}
				
			

Also, a newly-created directory called node_modules will be found in the project directory.

Now run Grunt from the terminal typing

				grunt
			

If the installations are proper, the command will give the output "Done, without errors."

Notes