What is grunt
In one word: automation. The less work you have to do when performing repetitive tasks like minification, compilation, unit testing, linting, etc, the easier your job becomes. After you've configured it through a Grunt file, a task runner can do most of that mundane work for you—and your team—with basically zero effort.
Grunt and Grunt plugins are installed and managed via npm, the Node.js package manager.
Install Grunt
For windows machine open the cmmand windows in Administrator permission and run
npm install -g grunt-cli
command.
For Linus machine oen terminal and run sudo npm install -g grunt-cli
.
How to use Grunt
Now we can see how to use grunt in our project. In our project we have to do lot of thing such that minification, compilation, unit testing etc. let see how to use one simple thing run using grunt
Crate a folder as “GruntTutorial” using following command mkdir
GruntTutorial
.
Move to GruntTutorial folder using cd GruntTutorial
.
Just run following command.
grunt
It show following error Fatal error: Unable to find Gruntfile
Now let see how to solve the error
Run the following command
npm install grunt
Create a java script file and name it as Gruntfile.js
and save it in “GruntTutorial”.
Run the following command
grunt
It show the warning The task default not found. Use --force to continue
.
Now see how to create simple grunt task
Open the Gruntfile.js in any one editor and type following code and save it.
module.exports = function(grunt){
grunt.registerTask("default",function(){
grunt.log.writeln("Hello World");
})
}
Run the following command
grunt
You got following result
Running "default" task
Hello World
Done, without errors.
No comments:
Post a Comment