All attributes of grunt.initConfig
are valid tasks, so if your Gruntfile looks like this:
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
files: ['Gruntfile.js'],
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', ['jshint']);
};
The shell command $ grunt jshint
will run the jshint
task.
Tasks can have different targets. Take this snippet of code for example:
grunt.initConfig({
jshint: {
gruntfile: {
files: ['Gruntfile.js']
},
project: {
files: 'src/**/*.js'
}
}
});
Here, jshint can target the gruntfile or all JavaScript files of your project. If we run $ grunt jshint
both targets will be used, but if we run $ grunt jshint:gruntfile
the linter will only be applied to the gruntfile.
The default tasks registered like this grunt.registerTask('default', ['jshint']);
will run with the shell command $ grunt
.
New registered tasks will run passing its name as a command line argument to grunt. For example:
grunt.registerTask('gruntfile', ['jshint:gruntfile']);
Will runt with $ grunt gruntfile
.