Get Grulping with Javascript task runners

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

Transcript of Get Grulping with Javascript task runners

Page 1: Get Grulping with Javascript task runners

Get Grulping with JavaScript Task Runners

Matt Gifford

coldfumonkeh

monkehworkscom

OBLIGATORY QUOTE FROM HISTORICAL FIGURE COMING UP

ldquolife is really simple but 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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

OBLIGATORY QUOTE FROM HISTORICAL FIGURE COMING UP

ldquolife is really simple but 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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

ldquolife is really simple but 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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

almost all quality improvement comes via simplification of design manufacturing layout

processes and procedures

Tom Peters

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

httpnodejsorg

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

httpsgithubcomtvooosublime-grunt

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

httpgruntjscomgruntjs

04x

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

04x

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

httpgruntjscomplugins

4403as of 2200pm 14th May 2015

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

packagejson

Gruntfilejs

YOU NEED

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$

This utility will walk you through creating a packagejson file It 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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$

grunt-cli v0113

grunt --version

grunt v045

packagejson

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

packagejson

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

CSS CONCATENATION

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

packagejson

name version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

packagejson

name version devDependencies

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntinitConfig(

concat css

files stylesheetsengagecss

[stylesheetscss]

)

Gruntfilejs

gruntinitConfig(

concat css

files stylesheetsengagecss

[ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntinitConfig(

concat css

files stylesheetsengagecss

[ stylesheetsmaincss stylesheetsformcss]

)

$ grunt concat

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt concat

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

$ grunt concatcss

Running concatcss (concat) task File stylesheetsengagecss created

Done without errors

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

THE CODE BASE

| -- stylesheets

-- engagecss

-- formcss

-- maincssnew file generated by Grunt

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GruntfilejsgruntinitConfig(

options banner Combined CSS file n

options banner Combined CSS file n

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GruntfilejsgruntinitConfig(

pkg gruntfilereadJSON(

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 version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

CSS MINIFICATION

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

packagejson

name version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

packagejson

name version devDependencies

grunt-contrib-cssmin ^090

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

module gruntinitConfig( )

gruntloadNpmTasks( gruntloadNpmTasks(

gruntloadNpmTasks(grunt-contrib-cssmin)

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntinitConfig(

snip

css files

stylesheetsengagemincss[ stylesheetsengagecss

)

cssmin css

files stylesheetsengagemincss

[ stylesheetsengagecss ]

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt cssmin

Running cssmincss (cssmin) task File 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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

CACHE BUSTING

$ npm install grunt-rev --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntloadNpmTasks(grunt-rev)

rev css files src [stylesheetsengagemincss]

$ grunt revcss

Running revcss (rev) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt revcss

Running revcss (rev) task stylesheetsengagemincss 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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

simplification of processes and procedures

REMEMBER

Gruntfilejs

gruntregisterTask(css [

cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntregisterTask(css [

cleanrevcss concatcss cssmincss cleancombinedcss revcss cleanmincss

])

$ grunt css

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt css

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss 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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntloadNpmTasks(grunt-contrib-watch)

watch css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntregisterTask(default [watch])

$ grunt

Running watch task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt

Running watch task Waiting

Running cleanrevcss (clean) task Cleaning stylesheets73a5cf64engagemincssOK

Running concatcss (concat) task File stylesheetsengagecss created

Running cssmincss (cssmin) task File stylesheetsengagemincss created 2973 kB rarr 2362 kB

Running cleancombinedcss (clean) task Cleaning stylesheetsengagecssOK

Running revcss (rev) task stylesheetsengagemincss gtgt 73a5cf64engagemincss

Running cleanmincss (clean) task

Done without errors Completed 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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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 javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

gruntloadNpmTasks(grunt-contrib-uglify)

uglify js files

javascriptsengageminjs [ javascriptsmainjs ]

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist

src javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

gruntloadNpmTasks(grunt-remove-logging)

removelogging dist

src javascriptsengageminjsdest javascriptsengageminjs

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

rev css files src [stylesheetsengagemincss]

js

files src [javascriptsengageminjs]

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

rev css files src [

js

src [

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 [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

simplification of processes and procedures

REMEMBER

GRUNTFILEJS

gruntregisterTask(js [

jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs]

tasks [js]css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

gruntregisterTask(js [

jshint cleanjsrev uglifyjs removelogging revjs cleanminjs

])

GRUNTFILEJS

watch js files [javascriptsmainjs]

tasks [js]css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

watch js files [javascriptsmainjs]

tasks [js]css files [

stylesheetsformcssstylesheetsmaincss

]tasks [css]

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GRUNTFILEJS

watch js files [

tasks [

js files [javascriptsmainjs] tasks [js]

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt

Running watch task Waiting

Running jshintall (jshint) task

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

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

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

gtgt File javascriptsmainjs changed

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt

Running watch task Waiting

Running jshintall (jshint) task gtgt 2 files lint free

Running cleanjsrev (clean) task Cleaning javascriptsengageminjsOK

Running uglifyjs (uglify) task File javascriptsengageminjs created 21 B rarr 21 B

Running removeloggingdist (removelogging) task Removed 1 logging statements from javascriptsengageminjs

Running revjs (rev) task javascriptsengageminjs gtgt 0c115107engageminjs

Running cleanminjs (clean) task

Done without errors Completed 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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

PERFORMING HTTP REQUESTS

$ npm install grunt-http --save-dev

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntloadNpmTasks(grunt-http)

http reload options url http1270018000indexcfmreload=true

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

GruntfilejsgruntinitConfig( pkg gruntfilereadJSON( 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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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)

)

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejswatch js files [

tasks [

css files [ stylesheetsformcss stylesheetsmaincss ] tasks [ cfcs files [ tasks [

cfcs files [cfcscfc] tasks [http_watcher]

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt

Running checklocalconf task Waiting

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ grunt

Running checklocalconf task

Running watch task Waiting

Running http_watcher task

Running httpreload (http) task gtgt 200

Done without errors Completed 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([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

$ npm install grunt-injector --save-dev

INJECTING ASSETS

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

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

Gruntfilejs

gruntregisterTask([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntloadNpmTasks(grunt-injector)

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

Gruntfilejs

gruntregisterTask([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

Gruntfilejs

gruntregisterTask([cleanrevcssconcatcsscssmincsscleancombinedcssrevcsscleanmincss

])

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

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

1583as of 2200pm 14th May 2015

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

WHAT ELSE CAN IT DO

pretty much anything you want it to

httpgruntjscomplugins

httpgulpjscomgulpjs

httpgulpjscomplugins

1583as of 2200pm 14th May 2015

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

httpgulpjscomgulpjs

httpgulpjscomplugins

1583as of 2200pm 14th May 2015

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

httpgulpjscomplugins

1583as of 2200pm 14th May 2015

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Thank you

Matt Gifford

coldfumonkeh

monkehworkscom