grunt understanding

35
“The capacity to learn is a gift; the ability to learn is a skill and the willingness to learn is a choice” Brian Herbert

Upload: khalid-khan

Post on 25-May-2015

237 views

Category:

Software


2 download

DESCRIPTION

Introduction to Grunt and tutorial on how to use Grunt

TRANSCRIPT

Page 1: Grunt understanding

“The capacity to learn is a gift; the ability to learn is a skill and the willingness to

learn is a choice”

Brian Herbert

Page 2: Grunt understanding

GRUNT.JSTHE JAVASCRIPT TASK RUNNER

byKHALID KHAN

Page 3: Grunt understanding

AGENDA● WHAT?● WHY?● HOW?● WHO?

Page 4: Grunt understanding

WHAT?GRUNT IN A NUTSHELL

● Build Tool● Task-based (Task

Runner) ● Runs on command line● Runs on NodeJS● Open source● Cross platform

Page 5: Grunt understanding

WHAT?TASK RUNNER?

● Linting JS (Enforcing JS standards, JS validations)

● Concatenation● Minification● Compilation of CSS

Preprocessors (Sass, LESS)● Image Optimization ● Automation

Page 6: Grunt understanding

WHAT?NODEJS?

Question: “Do I have to know/learn NodeJS to learn/understand/use Grunt?”

Answer: “No.”

Page 7: Grunt understanding

WHY?WHY A TASK RUNNER?

Mainly● Automation● Eliminates repetitive

tasks

Page 8: Grunt understanding

WHY?WHY A TASK RUNNER?

● One time cost● Faster Development● Everyone else uses

it● Easy to use● Larger number of

great plugins for different tasks

Page 9: Grunt understanding

HOW?

LETS START THE MAGIC…

Page 10: Grunt understanding

HOW?DEMO

Page 11: Grunt understanding

HOW?DEPENDENCIES

● NodeJS● npm (Node Package Manager)

Installing NodeJS will add npm to command line path

Page 12: Grunt understanding

HOW?INSTALLATION

npm is already in our path (due to steps in previous slide) so running this command in terminal will install grunt-cli (grunt-command line interface)

$ npm install -g grunt-cli

Page 13: Grunt understanding

HOW?CONFIGURATION FILES

● package.json● Grungfile.js

Page 14: Grunt understanding

HOW?PACKAGE.JSON

Page 15: Grunt understanding

HOW?READING PACKAGE.JSON

In terminal go to your project folder (where there is package.json file) and run this command:

$ npm install

Page 16: Grunt understanding

HOW?THE NODE_MODULES FOLDER

Page 17: Grunt understanding

HOW?CONCATENATE JS FILES

How to tell Grunt to concatenate JS files??

Page 18: Grunt understanding

HOW?CONCATENATE JS FILES

Install plugin for concatenating files

$ npm install grunt-contrib-concat --save-dev

Page 19: Grunt understanding

HOW?CONCATENATE JS FILES

I

Page 20: Grunt understanding

HOW?

Gruntfile.js

Page 21: Grunt understanding

HOW?GRUNTFILE.JS

Page 22: Grunt understanding

HOW?GRUNTFILE.JS

Page 23: Grunt understanding

HOW?CONCATENATE JS FILES

now run this command in your project folder and experience the magic

$ grunt

Page 24: Grunt understanding

HOW?MINIFY JS FILES

Same process

1. install plugin$ npm install grunt-contrib-uglify

2. Add uglify task in Gruntfile.js3. run grunt command

$ grunt

Page 25: Grunt understanding

HOW?MINIFY JS FILES

Page 26: Grunt understanding

HOW?COMPILE SASS, LESS

Same process

1. install plugin$ npm install grunt-contrib-sass

2. Add sass task in Gruntfile.js3. run grunt command

$ grunt

Page 27: Grunt understanding

HOW?MINIFY JS FILES

Page 28: Grunt understanding

HOW?Validate JS FILES

Same process

1. install plugin$ npm install grunt-contrib-jshint

2. Add jshint task in Gruntfile.js3. run grunt command

$ grunt

Page 29: Grunt understanding

HOW?

Automation

Even more interesting magic

Page 30: Grunt understanding

HOW?WATCH PLUGIN

The plugin “Watch” monitors files and as soon as it detects a change, it triggers/runs tasks (concat, uglify, etc)

Page 31: Grunt understanding

HOW?INSTALLING WATCH PLUGIN

Same process

1. install plugin$ npm install grunt-contrib-watch

2. Add watch task in Gruntfile.js3. run grunt command

$ grunt

Page 32: Grunt understanding
Page 33: Grunt understanding

HOW?

Example

Page 34: Grunt understanding

WHO?DIFFERENT COMPANIES ALREADY USE GRUNT

Page 35: Grunt understanding

Other Task Runners