130
Get Grulping with JavaScript Task Runners Matt Gifford @coldfumonkeh monkehworks.com

Get Grulping with JavaScript Task Runners (Matt Gifford)

Embed Size (px)

DESCRIPTION

Taken from the London Web Meet-up, this is Matt's session: Get Grulping with JavaScript Task Runners. In this session Matt will introduce the attendees to Grunt and Gulp, two incredibly powerful JavaScript task runners. It will help clarify what they are, why you need them and how you could use them in your projects, including how to introduce them into your development workflow and cycle. You will learn * What Gulp and Grunt are * Running Tasks – how they can be used * Plugins, extensions and enhancements * Building them into your workflow * The differences between the two task runners

Citation preview

Page 1: Get Grulping with JavaScript Task Runners (Matt Gifford)

Get Grulping with JavaScript Task Runners

Matt Gifford

coldfumonkeh

monkehworkscom

OBLIGATORY QUOTEFROM HISTORICAL FIGURECOMING UP

ldquolife is really simplebut we insist on making

it complicatedrdquoConfucius

WTF

IT HURTS

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 2: Get Grulping with JavaScript Task Runners (Matt Gifford)

OBLIGATORY QUOTEFROM HISTORICAL FIGURECOMING UP

ldquolife is really simplebut we insist on making

it complicatedrdquoConfucius

WTF

IT HURTS

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 3: Get Grulping with JavaScript Task Runners (Matt Gifford)

ldquolife is really simplebut we insist on making

it complicatedrdquoConfucius

WTF

IT HURTS

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 4: Get Grulping with JavaScript Task Runners (Matt Gifford)

WTF

IT HURTS

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 5: Get Grulping with JavaScript Task Runners (Matt Gifford)

IT HURTS

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 6: Get Grulping with JavaScript Task Runners (Matt Gifford)

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 7: Get Grulping with JavaScript Task Runners (Matt Gifford)

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 8: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 9: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 10: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 11: Get Grulping with JavaScript Task Runners (Matt Gifford)

04x

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 12: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpgruntjscomplugins

2954as of 830am 5th June 2014

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 13: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 14: Get Grulping with JavaScript Task Runners (Matt Gifford)

$

This utility will walk you through creating a packagejson fileIt only covers the most common items and tries to guess sane defaults

Press ^C at any time to quit

name (grunt_project) version (000)

grunting_away

description entry point (indexjs) test command

npm init

etc

001

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 15: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

name grunting_away version 001 description main indexjs author Matt Gifford license ISC

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 16: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

name grunting_away version 001

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 17: Get Grulping with JavaScript Task Runners (Matt Gifford)

INSTALLING GRUNT

$ npm install lt whatever the module name is gt

Use npm to install the required modules

You may need sudo or Administrative rights

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 18: Get Grulping with JavaScript Task Runners (Matt Gifford)

INSTALLING GRUNT

Grunt 03 requires a global install of the library

Grunt 04 changed a lot (for the better)

Now has the ability to run different local versions

$ npm install grunt-cli -g

-g installs the CLI package globally Good times

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 19: Get Grulping with JavaScript Task Runners (Matt Gifford)

INSTALLING GRUNT

We have the global CLI Now we need a local Grunt

$ npm install grunt --save-dev

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 20: Get Grulping with JavaScript Task Runners (Matt Gifford)

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 21: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

name grunting_away version 001 devDependencies grunt ^045

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 22: Get Grulping with JavaScript Task Runners (Matt Gifford)

name grunting_away version 001 devDependencies grunt ^045

devDependencies grunt ^045

packagejson

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 23: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Can be written as Gruntfilecoffee (if that floats your boat)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 24: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 25: Get Grulping with JavaScript Task Runners (Matt Gifford)

VERSION CONTROL

| -- packagejson

| -- Gruntfilejs

commit these and share the wealth

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 26: Get Grulping with JavaScript Task Runners (Matt Gifford)

TEAM GRUNTING

$ npm install

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 27: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

| -- stylesheets

-- formcss

-- maincss

can be managed more effectively

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 28: Get Grulping with JavaScript Task Runners (Matt Gifford)

CSS CONCATENATION

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

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 29: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

name grunting_away version 001 devDependencies grunt ^045 grunt-contrib-concat ^040

grunt-contrib-concat ^040

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 30: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 31: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [stylesheetscss]

)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 32: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig( concat css files

stylesheetsengagecss [ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 33: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt concat

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) taskFile stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 34: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 35: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig(

concat css

options banner Combined CSS file n

snip

options banner Combined CSS file n

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 36: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig(

pkg gruntfilereadJSON(packagejson) concat css

snip

pkg gruntfilereadJSON(packagejson)

options banner lt= pkgname gt combined file generated lt= grunttemplatetoday(dd-mm-yyyy) gt n

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 37: Get Grulping with JavaScript Task Runners (Matt Gifford)

CSS MINIFICATION

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

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 38: Get Grulping with JavaScript Task Runners (Matt Gifford)

packagejson

name grunting_away version 010 devDependencies grunt ^045 grunt-contrib-concat ^040 grunt-contrib-cssmin ^090

grunt-contrib-cssmin ^090

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 39: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

moduleexports = function(grunt) gruntinitConfig( Pure awesomeness will live here )

gruntloadNpmTasks(grunt-contrib-concat) gruntloadNpmTasks(grunt-contrib-cssmin)

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 40: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig( snip

cssmin css

files stylesheetsengagemincss [ stylesheetsengagecss ]

)

cssmin css files

stylesheetsengagemincss [ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 41: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt cssmin

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 42: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- stylesheets

-- engagecss

-- engagemincss

-- formcssminified file

-- maincss

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 43: Get Grulping with JavaScript Task Runners (Matt Gifford)

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 44: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 45: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt revcss

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 46: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

hashed minified file

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 47: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- engagecss

-- engagemincss

-- formcss

-- maincss

we donrsquot need these

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 48: Get Grulping with JavaScript Task Runners (Matt Gifford)

CLEAN UP OPERATION

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 49: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)

clean combinedcss src [stylesheetsengagecss] mincss src [stylesheetsengagemincss] revcss src [stylesheetsengagemincss]

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 50: Get Grulping with JavaScript Task Runners (Matt Gifford)

TOO MANY TASKS

We already have a load of tasks to run

What happens when we need to run them all

Type each command out

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 51: Get Grulping with JavaScript Task Runners (Matt Gifford)

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 52: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 53: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt css

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 54: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- stylesheets

-- 73a5cf64engagemincss

-- formcss

-- maincss

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 55: Get Grulping with JavaScript Task Runners (Matt Gifford)

WATCHINGALWAYS WATCHING

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 56: Get Grulping with JavaScript Task Runners (Matt Gifford)

WATCHING FOR FILE CHANGES

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 57: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 58: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 59: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt

Running watch taskWaiting

Running cleanrevcss (clean) taskCleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) taskFile stylesheetsengagecss created

Running cssmincss (cssmin) taskFile stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) taskCleaning stylesheetsengagecssOK

Running revcss (rev) taskstylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errorsCompleted in 0485s at Mon Jun 02 2014 022621 GMT+0100 (BST) - Waiting

gtgt File stylesheetsmaincss changed

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 60: Get Grulping with JavaScript Task Runners (Matt Gifford)

THE CODE BASE

| -- javascripts

-- mainjs

-- formControlsjs

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 61: Get Grulping with JavaScript Task Runners (Matt Gifford)

JAVASCRIPT MANAGEMENT

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

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

$ npm install grunt-remove-logging --save-dev

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 62: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-jshint)

jshint options curly true eqeqeq true eqnull true browser true globals jQuery true all [Gruntfilejsjavascriptsmainjs]

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 63: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 64: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist src javascriptsengageminjs dest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 65: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 66: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

rev css files src [stylesheetsengagemincss] js files src [javascriptsengageminjs]

js files src [javascriptsengageminjs]

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 67: Get Grulping with JavaScript Task Runners (Matt Gifford)

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 68: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

gruntregisterTask(js [jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 69: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 70: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNTFILEJS

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css]

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 71: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt

Running watch taskWaiting

Running jshintall (jshint) task

javascriptsmainjs 1 |consolelog(monkeh love is good love) ^ Missing semicolon

gtgt 1 error in 2 filesWarning Task jshintall failed Use --force to continue

Aborted due to warningsCompleted in 2090s at Mon Jun 02 2014 031355 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 72: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt

Running watch taskWaiting

Running jshintall (jshint) taskgtgt 2 files lint free

Running cleanjsrev (clean) taskCleaning javascriptsengageminjsOK

Running uglifyjs (uglify) taskFile javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) taskRemoved 1 logging statements from javascriptsengageminjs

Running revjs (rev) taskjavascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errorsCompleted in 0721s at Mon Jun 02 2014 031405 GMT+0100 (BST) - Waiting

gtgt File javascriptsmainjs changed

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 73: Get Grulping with JavaScript Task Runners (Matt Gifford)

RELOADING YOUR APP

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 74: Get Grulping with JavaScript Task Runners (Matt Gifford)

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 75: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 76: Get Grulping with JavaScript Task Runners (Matt Gifford)

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON(packagejson) local_settings local_url

http reload options url lt= local_settingslocal_url gt

local_settings local_url

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 77: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(default [checklocalconf])

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 78: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(checklocalconf Check if the local config JSON file exists function(arg) if(gruntfileexists(grunt_local_settingsjson)) grunttaskrun(watch) else gruntlogerrorlns() gruntlogerrorlns(The grunt_local_settingsjson file does not appear to exist) gruntlogerrorlns() gruntlogerrorlns() gruntlogerrorlns( local_url httpyour_local_serverreload) gruntlogerrorlns() gruntlogerrorlns() gruntfailfatal(Please create and save the grunt_local_settingsjson file) )

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 79: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(http_watcher Set the local url before running the watch command function() var jsonLocalSettings = gruntfilereadJSON(grunt_local_settingsjson) gruntconfigset(local_settings jsonLocalSettings) gruntconfigrequires(local_settings) grunttaskrun(httpreload))

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 80: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

watch js files [javascriptsmainjs] tasks [js] css files [ stylesheetsformcss stylesheetsmaincss ] tasks [css] cfcs files [cfcscfc] tasks [http_watcher]

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 81: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt

Running checklocalconf taskWaiting

gtgt gtgt The grunt_local_settingsjson file does not appear to existgtgt Please create it in this directory with the following content (the URLgtgt for your local app with reload action)gtgt gtgt gtgt local_url httpyour_local_serverreloadgtgt gtgt Fatal error Please create and save the grunt_local_settingsjson file then re-run this command

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 82: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ grunt

Running checklocalconf task

Running watch taskWaiting

Running http_watcher task

Running httpreload (http) taskgtgt 200

Done without errorsCompleted in 2061s at Tue Jun 03 2014 120144 GMT+0100 (BST) - Waiting

gtgt File cfcstestcfc changed

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 83: Get Grulping with JavaScript Task Runners (Matt Gifford)

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 84: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

injector options css files layoutcfm [stylesheetsengagemincss] js files layoutcfm [javascriptsengageminjs]

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 85: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntregisterTask(css [cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

injectorcss

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 86: Get Grulping with JavaScript Task Runners (Matt Gifford)

TIDY UP

There are no limits to the number of plugins you can use

Your Gruntfile could get messy quickly

You may also be duplicating file paths a lot

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 87: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-clean)gruntloadNpmTasks(grunt-contrib-concat)gruntloadNpmTasks(grunt-contrib-csslint)gruntloadNpmTasks(grunt-contrib-cssmin)gruntloadNpmTasks(grunt-http)gruntloadNpmTasks(grunt-injector)gruntloadNpmTasks(grunt-contrib-jshint)gruntloadNpmTasks(grunt-contrib-uglify)gruntloadNpmTasks(grunt-contrib-watch)gruntloadNpmTasks(grunt-remove-logging)gruntloadNpmTasks(grunt-rev)gruntloadNpmTasks(grunt-notify)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 88: Get Grulping with JavaScript Task Runners (Matt Gifford)

TIDY UP

$ npm install matchdep --save-dev

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 89: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

require(matchdep)filterDev(grunt-)forEach(gruntloadNpmTasks)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 90: Get Grulping with JavaScript Task Runners (Matt Gifford)

ASSIGN VARIABLES

Use the variable system to reduce duplicate text

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 91: Get Grulping with JavaScript Task Runners (Matt Gifford)

Gruntfilejs

gruntinitConfig( pkg gruntfilereadJSON(packagejson) minCSS stylesheetsengagemincss

)

cssmin css files lt= minCSS gt [ stylesheetsengagecss ]

clean mincss src [lt= minCSS gt]

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 92: Get Grulping with JavaScript Task Runners (Matt Gifford)

WHAT ELSE CAN IT DO

image optimisation and resizing

git integration

run unit tests (eg Jasmine)

templating

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 93: Get Grulping with JavaScript Task Runners (Matt Gifford)

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 94: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpgulpjscomgulpjs

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 95: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpgulpjscomplugins

635as of 830am 5th June 2014

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 96: Get Grulping with JavaScript Task Runners (Matt Gifford)

INSTALLING GULP

As a system wide module

$ npm install gulp -g

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 97: Get Grulping with JavaScript Task Runners (Matt Gifford)

INSTALLING GULP

$ npm install gulp --save-dev

Getting a local gulp version for the project

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 98: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Lives in the root directory of your project

Commit it into your source control repo

Holds your task configurations

Lowercase file name

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 99: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Include gulpvar gulp = require(gulp)

gulptask(default function() place code for your default task here)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 100: Get Grulping with JavaScript Task Runners (Matt Gifford)

PIPES AND STREAMS

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 101: Get Grulping with JavaScript Task Runners (Matt Gifford)

GRUNT

GULP

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 102: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Include gulpvar gulp = require(gulp)

Include Our Pluginsvar jshint = require(gulp-jshint)var concat = require(gulp-concat)var uglify = require(gulp-uglify)var rename = require(gulp-rename)var header = require(gulp-header)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 103: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Default Taskgulptask(default [watch])

Watch Files For Changesgulptask(watch function() gulpwatch(jsjs [lint scripts]))

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 104: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Lint Taskgulptask(lint function() return gulpsrc(jsjs) pipe(jshint()) pipe(jshintreporter(default)))

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 105: Get Grulping with JavaScript Task Runners (Matt Gifford)

gulpfilejs

Concatenate amp Minify JSgulptask(scripts function() var headerValue = Evaluated by gulpn return gulpsrc(jsjs) pipe(concat(combinedjs)) pipe(header(headerValue)) pipe(gulpdest(dist)) pipe(rename(combinedminjs)) pipe(uglify()) pipe(header(headerValue)) pipe(gulpdest(dist)))

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 106: Get Grulping with JavaScript Task Runners (Matt Gifford)

httpgulpfictiondivshotio

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 107: Get Grulping with JavaScript Task Runners (Matt Gifford)

Streaming and piping give speed enhancements

Code over configuration

Still early adoption - plugins limited

JS Node exposure beneficial ()

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 108: Get Grulping with JavaScript Task Runners (Matt Gifford)

Sub tasks easily managed

Impressive number of plugins and extensions

IO issues and speed (in comparison)

Configuration could get messy

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 109: Get Grulping with JavaScript Task Runners (Matt Gifford)

ITS NOT A CONTEST

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 110: Get Grulping with JavaScript Task Runners (Matt Gifford)

HAPPY

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 111: Get Grulping with JavaScript Task Runners (Matt Gifford)

Save your config files (repo)

Use skeleton variation across your projects

FINAL WORDS

Create

Employ

Refine

Relax

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 112: Get Grulping with JavaScript Task Runners (Matt Gifford)

Has the potential to be addictive

Check for updates and improved methods

Use your time wisely

FINAL WORDS

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom

Page 113: Get Grulping with JavaScript Task Runners (Matt Gifford)

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom