Transcript
Page 1: What makes me "Grunt"?

what makes me “Grunt”?

developer happiness courtesy of automation

/ Fabien Doiron @fabien_doiron

Page 2: What makes me "Grunt"?

no automationmake me go something something

Page 3: What makes me "Grunt"?

I work on Cratedsoftware developer, front-end

@fabien_doiron

Page 5: What makes me "Grunt"?

when I got into development

front-end development was pretty simple

Page 6: What makes me "Grunt"?

typical tools

HTML / CSS / JS / FTP / browser

Page 7: What makes me "Grunt"?

then something happened

front-end development became complex

Page 8: What makes me "Grunt"?

current typical tools

linting / preprocessors / concatenation /

minification / versioning / testing /

coverage / dependency management /

continuous deployment / version control /

frameworks / libraries…

Page 9: What makes me "Grunt"?

tools mentionedfrom our stack

Page 11: What makes me "Grunt"?

4 reasons

we use build tools & automation

Page 12: What makes me "Grunt"?

build tools

in 10 seconds or less

Page 13: What makes me "Grunt"?

what?

automation

Page 14: What makes me "Grunt"?

why?

automate what you have but don't want to do

Page 15: What makes me "Grunt"?

how?

configure a task once, run as often as you want~ ▸ build task:target

Page 16: What makes me "Grunt"?

who?

Grunt, Gulp, Phing, Make, Rake, Jake, Brunch, Ant…

Page 17: What makes me "Grunt"?
Page 18: What makes me "Grunt"?

1.

project setup

Page 19: What makes me "Grunt"?

project setup: goal

coding ready in minutes

Page 21: What makes me "Grunt"?

project setup

in 3 easy steps

Page 22: What makes me "Grunt"?

i.

~ ▸ git clone … # get code from repository

~ ▸ git pull # get latest code from repository

Page 23: What makes me "Grunt"?

ii.

~ ▸ vagrant up # puts together a complete environment

# provision environment with chef

Page 24: What makes me "Grunt"?

iii.

~ ▸ phing proj:build # get deps with composer, npm & bower

# database migration with phinx

# front-end build with grunt

~ ▸ grunt build # lint, preprocess, concat, min, version

# my personal favourite: ascii

Page 25: What makes me "Grunt"?
Page 26: What makes me "Grunt"?
Page 27: What makes me "Grunt"?

2.

project output

Page 28: What makes me "Grunt"?

project output: goal

reproducible results regardless of developer setup/workflow

Page 29: What makes me "Grunt"?

reduce the risk of

“works on my machine”

by abstracting the output settings from the

user to the build tool

Page 30: What makes me "Grunt"?

project output: tools

Page 31: What makes me "Grunt"?

compiling CSS: user settings

~ ▸ sass in.scss:out.css~ ▸ lessc in.scss > out.css

results: can vary

Page 32: What makes me "Grunt"?

example task (Sass)

module.exports = function ( grunt ) {

var src = '<%= grunt.option( "src" ) %>';

var tmp = '<%= grunt.option( "tmp" ) %>';

grunt.config( 'sass', {

dist: {

files: [ {

expand: true,

cwd: src + '/sass',

src: [ '*.scss' ],

dest: tmp + '/sass',

ext: '.css'

} ]

}

} );

grunt.loadNpmTasks( 'grunt-contrib-sass' );

};

Page 33: What makes me "Grunt"?

compiling CSS: tool settings

~ ▸ grunt sass~ ▸ grunt less

results: are the same

Page 34: What makes me "Grunt"?
Page 35: What makes me "Grunt"?

3.

coding environment

Page 36: What makes me "Grunt"?

coding environment: goal

easily work in a dev and/or production replica environment

Page 37: What makes me "Grunt"?

coding environment: tools

Page 38: What makes me "Grunt"?

coding environments setup

in 4 easy steps

Page 39: What makes me "Grunt"?
Page 40: What makes me "Grunt"?

i. separate targets

~ ▸ grunt build:dev # all source files, commented, unminified

~ ▸ grunt build:prod # concat, minified, versioned files

Page 41: What makes me "Grunt"?
Page 42: What makes me "Grunt"?
Page 43: What makes me "Grunt"?
Page 44: What makes me "Grunt"?

grunt versioning task

versioning: {

options: {

cwd: 'public',

outputConfigDir: 'public/config'

},

dist: {

files: [{

assets: '<%= uglify.main.files %>',

key: 'global',

dest: 'js',

type: 'js',

ext: '.min.js'

}, { … } ]

}

}

Page 45: What makes me "Grunt"?
Page 46: What makes me "Grunt"?
Page 47: What makes me "Grunt"?

iii. generated configuration file

~ ▸ grunt build:dev <?php

return array( 'static.assets' => array(

'global' => array(

'css' => array( '/static/css/main.css' ),

'js' => array( '/static/js/file1.js', '/static/js/file2.js', … )

),

'home' => array(

'css' => array(),

'js' => array( 'static/js/home1.js', '/static/js/home2.js' )

),

'anotherKey' => array( … )

) );

Page 48: What makes me "Grunt"?

iii. generated configuration file

~ ▸ grunt build:prod <?php

return array( 'static.assets' => array(

'global' => array(

'css' => array( '/static/css/main.7f41197e.min.css' ),

'js' => array( '/static/js/plugins.7409b19a.min.js',

'/static/js/common.4923a32c.min.js', … )

),

'home' => array(

'css' => array(),

'js' => array( 'static/js/home.47b0990d.min.js' )

),

'anotherKey' => array( … )

) );

Page 49: What makes me "Grunt"?
Page 50: What makes me "Grunt"?
Page 51: What makes me "Grunt"?

ii. generated output

~ ▸ grunt build:dev ~ ▸ grunt build:prod ▾ public ▾ static ▾ css main.css

▾ js plugin1.js

plugin2.js

common1.js

common2.js

home1.js

home2.js

▾ public ▾ static ▾ css main.7f41197e.min.css

▾ js plugins.7409b19a.min.js

common.4923a32c.min.js

home.47b0990d.min.js

Page 52: What makes me "Grunt"?
Page 53: What makes me "Grunt"?
Page 54: What makes me "Grunt"?
Page 55: What makes me "Grunt"?
Page 56: What makes me "Grunt"?
Page 57: What makes me "Grunt"?

iv. use generated configuration file

// inside our layouts

<?php $this->versionedAsset()->render( 'global' ); ?>

~ ▸ grunt build:dev

~ ▸ grunt build:prod

<link rel="stylesheet" href="/static/css/main.css">

<script src="/static/js/file1.js"></script>

<script src="/static/js/file2.js"></script> …

<link rel="stylesheet" href="/static/css/main.7f41197e.min.css">

<script src="/static/js/plugins.7409b19a.min.js"></script>

<script src="/static/js/common.4923a32c.min.js"></script>

Page 58: What makes me "Grunt"?

why did we go down this road?

Page 59: What makes me "Grunt"?

cloudfront invalidation ~15 minutes

no longer applicable*

*appending a hash creates a “new” file

Page 60: What makes me "Grunt"?

cleaner includes in our layouts

messy if( APPLICATION_ENV == "production") {

// include concat/min files

} else {

// include all dev files

}

clean <?php $this->versionedAsset()->render( 'global' ); ?>

Page 61: What makes me "Grunt"?

demo

Page 62: What makes me "Grunt"?

4.

debugging

Page 63: What makes me "Grunt"?

debugging: goal

effectively debug errors

Page 64: What makes me "Grunt"?

debugging [ compiled, ] concatenated,

minified code is hard

Page 65: What makes me "Grunt"?

our approach

when a bug is found/reported

Page 66: What makes me "Grunt"?

i. build dev environment

reproduce the errorrule out minification erroruse devtools on source filesupdate/add unit, integration, regression testsgenerally all we need

Page 67: What makes me "Grunt"?

ii. build prod environment

reproduce the erroruse devtools with source mapsstill have access to source fileseasier to debug than on the live siteupdate/add unit, integration, regression tests

Page 68: What makes me "Grunt"?

“trying to fix a bug in minified code is like

using a new API with no documentation”

Page 69: What makes me "Grunt"?

recap

Page 70: What makes me "Grunt"?

being a front-end developer is hardbuild tools make you awesomeautomate the repetitive tasksfrictionless project setupreproduce output every timeaccess to dev and production environments locallytake the stress out of debugging

Page 72: What makes me "Grunt"?

CONFOO2014

40% offcoupon code because you were awesome

*valid until March 30, 2014

Page 73: What makes me "Grunt"?

thank you

questions

/ Fabien Doiron @fabien_doiron


Top Related