Grunt
&
JSHint
JavaScript Task Runner
Build Tool
Automation tool
Build Tool
Automation tool
Why Automation?
We have many steps to perform
Doing these steps manually is
painful and error prone
Automation allows us to work
smarter, not harder
Typical Grunt Tasks
-
Concatenation
-
Minification
-
Pre-processing Sass and Coffeescript
-
Image Optimization
-
Running Tests
-
Seeding the database
-
Starting a development Server
Has TWO PARTS
Global
npm -g install grunt-cli npm install grunt --save-devpackage.json
// package.json
{
"name": "example-project",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.4"
}
}
Usage
Gruntfile.js - outline of plugins
and rules to execute on the code
Plugins - existing packages with all the details about a task
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
simplemocha: {
options: { timeout: 3000 },
all: { src: ['test/**/*.js'] }
}
});
grunt.loadNpmTasks('grunt-simple-mocha');
grunt.registerTask('default','simplemocha');
};
Gruntfile.js
module.exports = function(grunt) { grunt.initConfig({ //specify configuration for different tasks //see documentation for expected values }); //task plugins to be loaded grunt.loadNpmTasks(‘package-name’); //indicate lists of tasks that can be run from //command line grunt.registerTask(‘default ’,'task-name' ); };
JSHint
JavaScript Code Linter
Highlight potentially bad practices
Keeps code consistent style
Helps teams work together
JSHint on Github
checkout the README.md for usage
Installation in your Project
npm install grunt-contrib-jshint --save-dev
JSHint
Gruntfile.js
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'server.js']
}
});
grunt.registerTask('default','jshint');
}
