Grunt - The JavaScript Task Runner

arif_iq 6,268 views 20 slides Jun 04, 2013
Slide 1
Slide 1 of 20
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20

About This Presentation

Grunt is a task-based command line build tool for JavaScript projects.


Slide Content

GRUNT THE JAVASCRIPT TASK RUNNER Mohammed Arif Manager Interactive Development @ SapientNitro www.mohammedarif.com https://twitter.com/#!/arif_iq http://in.linkedin.com/in/mohdarif

AGENDA What is grunt? Why Grunt? How Do I start? npm Node.js How Do I Install it? How Do I Use it? Demo Who have been using it? Q & A

WHAT IS GRUNT? Grunt is a task-based command line build tool for JavaScript projects.

TASK - BASED ? Unit testing JS linting Concatenating/ minifying Image optimization Replace scripts in html files SASS …

WHY GRUNT? Open Source Large Community Easy to use Hundreds of plugins Build your own (plugin)

WHY GRUNT? Ant http:// mechanics.flite.com /blog/2012/06/19/why-we-use-node-dot- js -and-grunt-to-build- javascript /

WHY GRUNT? Grunt http:// mechanics.flite.com /blog/2012/06/19/why-we-use-node-dot- js -and-grunt-to-build- javascript /

HOW DO I START GRUNT? http:// gruntjs.com /getting-started n pm n ode.js

NPM? n pm { Node Packaged Modules } manages dependencies for an application through the command line. https:// npmjs.org

NODE.JS? n ode.js is an open source command line tool built for the server side JavaScript. The JavaScript is executed by the V8 (Google's open source JavaScript engine). http:// www.ibm.com / developerworks /library/ os-nodejs /

HOW DO I INSTALL GRUNT CLI ? $ npm install -g grunt-cli This will put the grunt command in your system path , allowing it to be run from any directory. * Note that installing grunt-cli does not install the grunt task runner! You need to install Grunt's command line interface (CLI) globally.

HOW DO I INSTALL GRUNT? $ npm install grunt –-save- dev T his will install the latest version of Grunt in your project folder, adding it to your devDependencies in package.json * Same way you can install the grunt plugins i.e. npm install { module} --save- dev

HOW DO I USE GRUNT? p ackage.json GruntFile.js

p ackage.json { " name ": " my-project-name ", " version ": "0.1.0", " devDependencies ": { " grunt ": "~0.4.1", " grunt-contrib-jshint ": "~0.1.1", " grunt-contrib-nodeunit ": "~0.1.2" } }

GruntFile.js module.exports = function(grunt) { // Project configuration. grunt.initConfig ( { pkg : grunt.file.readJSON (' package.json '), uglify : { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today (" yyyy -mm- dd ") %> */\n' } , build: { src : ' src /<%= pkg.name %>. js ', dest : 'build/<%= pkg.name %>. min.js ' } } } ); // Load the plugin that provides the " uglify " task. grunt.loadNpmTasks ('grunt- contrib - uglify '); // Default task(s). grunt.registerTask ('default', [' uglify ']); } ;

DEMO $ git clone -b 1.1 [email protected]:mdarif /JavaScript- Boilerplate.git $ npm install

WHO HAVE BEEN USING IT? jQuery Yeoman Modernizr Adobe Twitter Filament Group Bocoup …

Q & A

feedback

THANK YOU