Download - The Quest for the Perfect Workflow

Transcript
Page 1: The Quest for the Perfect Workflow

@andismith

Page 2: The Quest for the Perfect Workflow

About Me

Andi Smith Technical Architect@ AKQA!

- andismith.com- devtoolsecrets.com- @andismith

Page 3: The Quest for the Perfect Workflow

The Perfect Experience

- For our users- For us?

Page 4: The Quest for the Perfect Workflow

The Challenge

Find the perfect workflow

Page 5: The Quest for the Perfect Workflow
Page 6: The Quest for the Perfect Workflow
Page 7: The Quest for the Perfect Workflow
Page 8: The Quest for the Perfect Workflow

Did I Succeed?

- Well, no.

- One size does not fit all.

Page 9: The Quest for the Perfect Workflow

The Perfect Workflow?

Depends on your requirements.

Page 10: The Quest for the Perfect Workflow

Project Requirements

It needs to be content editable.

Page 11: The Quest for the Perfect Workflow

Client Requirements

It needs to use our current CMS.

Page 12: The Quest for the Perfect Workflow

Hosting Requirements

It will be hosted in a Java environment.

Page 13: The Quest for the Perfect Workflow

Your Requirements

I’d prefer to use Sass over LESS.

Page 14: The Quest for the Perfect Workflow

IMPROVE

@andismith

Page 15: The Quest for the Perfect Workflow

Points to Consider

- Less repetition- Less errors- Better performance

Page 16: The Quest for the Perfect Workflow

Automation = More Fun!

Credit: giphy.com/gifs/tscu52qG7VbwI

Page 17: The Quest for the Perfect Workflow

Less Pain!

Credit: giphy.com/gifs/XOxay70W2WHbq

Page 18: The Quest for the Perfect Workflow

How?!

SETUP

DEVELOP

BUILD

Page 19: The Quest for the Perfect Workflow

SETUP@andismith

Page 20: The Quest for the Perfect Workflow

Choose a Task Runner

Credit: flickr.com/photos/nomadic_lass/6970307781/

Page 21: The Quest for the Perfect Workflow

Task Runners

Page 22: The Quest for the Perfect Workflow

bit.ly/1jPCxeN

Intro to Task Runners

Page 23: The Quest for the Perfect Workflow

Which to Use?

Page 24: The Quest for the Perfect Workflow

Which to Use?

Easy to start withStable2000+ pluginsYeoman SupportSlower than competitors.

++++-

Grunt

Page 25: The Quest for the Perfect Workflow

Which to Use?

FastNo need to temp store filesLess mature than Grunt

++!

-Gulp

Page 26: The Quest for the Perfect Workflow

Your Choice

- Checklist of requirements- Check tasks are available

and working- Grunt is more mature, so

less risk

Page 27: The Quest for the Perfect Workflow

Scaffold Your WorkflowGet a head start with Yeoman!

yeoman.io

Page 28: The Quest for the Perfect Workflow

Generating a Base

Page 29: The Quest for the Perfect Workflow

Choosing a Base- yo webapp

!

- yo assemble- yo firefox-os- yo phonegap- yo wordpress!

yeoman.io/community-generators.html

Page 30: The Quest for the Perfect Workflow

Customise!

Credit: sailorusagichan.deviantart.com/art/Batmobile-Lawn-mower-310787147

Page 31: The Quest for the Perfect Workflow

Source !== Destination

Don’t overwrite your work!

src!- html - css - javascript - sass

dest!- html - css (min) - javascript (min)

Page 32: The Quest for the Perfect Workflow

Loading Tasks…grunt.loadNpmTasks(‘grunt-contrib-connect’); grunt.loadNpmTasks(‘grunt-contrib-clean’); grunt.loadNpmTasks(‘grunt-contrib-copy’); grunt.loadNpmTasks(‘grunt-contrib-sass’); grunt.loadNpmTasks(‘grunt-contrib-watch’); grunt.loadNpmTasks(‘grunt-autoprefixer');

Page 33: The Quest for the Perfect Workflow

npm install load-grunt-tasks

Auto Load Tasks

Load tasks from package.json

npm install gulp-load-plugins

Page 34: The Quest for the Perfect Workflow

Auto Load Tasks (Grunt)

grunt.loadNpmTasks(‘grunt-contrib-copy’); grunt.loadNpmTasks(‘grunt-contrib-watch’); grunt.loadNpmTasks(‘grunt-contrib-connect’); grunt.loadNpmTasks(‘grunt-autoprefixer'); grunt.loadNpmTasks('grunt-sass');

require('load-grunt-tasks')(grunt);

Before:

After:

Page 35: The Quest for the Perfect Workflow

Auto Load Tasks (Gulp)

var connect = require(‘gulp-connect’); var jshint = require(‘gulp-jshint’); var concat = require(‘gulp-concat’);

var plugins = require(‘gulp-load-plugins’)(); // plugins.jshint

Before:

After:

Page 36: The Quest for the Perfect Workflow

npm installgrunt-contrib-connect

Start a Local Server

Host locally without additional software

npm install gulp-connect

Page 37: The Quest for the Perfect Workflow

Start a Local Server

connect: { dev: { options: { base: ‘./dest’, port: 4000 } } },

In Grunt:

Page 38: The Quest for the Perfect Workflow

Start a Local Server

gulp.task(‘connect', connect.server({ root: ‘./dest’, port: 4000 }) );

In Gulp:

Page 39: The Quest for the Perfect Workflow

npm install time-grunt

Workflow Performance

Time your tasks

npm install gulp-duration

Page 40: The Quest for the Perfect Workflow

Workflow Performance

Page 41: The Quest for the Perfect Workflow

npm install grunt-concurrent

Make Grunt Faster

Run tasks concurrently

Page 42: The Quest for the Perfect Workflow

Make Grunt Fastergrunt.initConfig({ concurrent: { compile: ['coffee', 'sass'] } }); !grunt.registerTask('default', ['concurrent:compile');

Page 43: The Quest for the Perfect Workflow

SETUP- Scaffold Your Workflow- Source !== Destination- Auto Load Tasks- Start a Local Server- Time your Tasks- Run Tasks Concurrently

Page 44: The Quest for the Perfect Workflow

DEVELOP@andismith

Page 45: The Quest for the Perfect Workflow

Performance

Credit: Me!

Page 46: The Quest for the Perfect Workflow

Focus on

Speed up/help devSpeed up workflow!

NOT concatenating or obfuscating code

Page 47: The Quest for the Perfect Workflow

Ask Yourselves

What is the task?Do you need it?Do you really need it?

Page 48: The Quest for the Perfect Workflow

CSS Prefixes-moz-transition: -moz-transform 200ms; -ms-transition: -ms-transform 200ms; -o-transition: -o-transform 200ms; -webkit-transition: -webkit-transform 200ms; transition: transform 200ms;

Page 49: The Quest for the Perfect Workflow

npm install grunt-autoprefixer

Use Autoprefixer

Automatically add CSS vendor prefixes

npm install gulp-autoprefixer

Page 50: The Quest for the Perfect Workflow

Use Autoprefixer

border-radius: 2px;

-moz-border-radius: 2px; -webkit-border-radius: 2px; border-radius: 2px;

Source:

Output:

Page 51: The Quest for the Perfect Workflow

npm installgrunt-contrib-watch

Watch & LiveReload

Watch for changes and auto-refresh the browser

gulp.watch

Page 52: The Quest for the Perfect Workflow

Watch & LiveReload

Split your watch into smaller groupswatch: { options: { livereload: true }, sass: { files: PATHS.SRC + PATHS.SASS + ‘{,*/}*.scss', tasks: [‘styles'] }, scripts: { files: PATHS.SRC + PATHS.JS + '{,*/}*.js', tasks: [‘scripts'] }

Page 53: The Quest for the Perfect Workflow

Globbing Performance

images/**/*.{gif,jpg,png}

images/{,*/}*.{gif,jpg,png}

Before:

After:

More: bit.ly/1g2Rar8

Page 54: The Quest for the Perfect Workflow

Watch & LiveReload- Chrome:

bit.ly/1ojCxVq- Firefox:

bit.ly/1hs7yBT- Safari:

bit.ly/1sbwfcC

Page 55: The Quest for the Perfect Workflow

npm install grunt-newer

Compile Changed Files

Make compilation more efficient

npm install gulp-changed

Page 56: The Quest for the Perfect Workflow

Compile Changed Files

Prefix “newer:” to your task in Grunt.watch: { options: { livereload: true }, sass: { files: PATHS.SRC + PATHS.SASS + ‘{,*/}*.scss', tasks: [‘newer:styles’] }, scripts: { files: PATHS.SRC + PATHS.JS + '{,*/}*.js', tasks: [‘newer:scripts’] }

Page 57: The Quest for the Perfect Workflow

Compile Changed Files

Add .pipe(changed(dest)) in Gulpgulp.src([PATHS.SRC + PATHS.SASS + '{,*/}*.scss']) .pipe(changed(PATHS.DEST + PATHS.SASS)) .pipe(sass())

Page 58: The Quest for the Perfect Workflow

Live Editing Our FilesMake changes in the browser by setting up source mapssass: { options: { sourcemap: true, style: ‘compressed', trace: true }, dist: { ... } }

Page 59: The Quest for the Perfect Workflow
Page 60: The Quest for the Perfect Workflow

Live Editing Our FilesEnable source maps in Chrome Developer Tools settings

Page 61: The Quest for the Perfect Workflow

Live Editing Our FilesAllow Developer Tools to access your source in Settings, Workspace

Page 62: The Quest for the Perfect Workflow

Live Editing Our FilesMap our CSS file to our SASS file.

Page 63: The Quest for the Perfect Workflow

Live Editing Our FilesCSS Style Inspector shows line numbers

Page 64: The Quest for the Perfect Workflow

npm install grunt-responsive-images

Grunt Responsive Images

Resize images automatically for <picture>!

brew install graphicsmagick

Page 65: The Quest for the Perfect Workflow

Grunt Responsive Images

responsive_images: { images: { options: { sizes: [{ height: 320, name: “small", width: 400 }, { height: 768, name: “medium", width: 1024 }, { height: 980, name: “large", width: 1280 }] }, files: [{ ... }] },

Page 66: The Quest for the Perfect Workflow

DEVELOP- Autoprefixer- Watch & LiveReload- Improve your Globbing

Performance- Newer/Changed files- Live editing CSS/JavaScript- Grunt Responsive Images

Page 67: The Quest for the Perfect Workflow

BUILD@andismith

Page 68: The Quest for the Perfect Workflow

For build & release- Slower, optimisation tasks.- Make sure you test a build with

these tasks before go-live!

Page 69: The Quest for the Perfect Workflow

npm install grunt-usemin

UseMin

Compile CSS/JS and replace references in HTML.

npm install gulp-usemin

Page 70: The Quest for the Perfect Workflow

UseMin

<!-- build:css /css/main.css --> <link rel="stylesheet" href=“/css/main.css" /> <link rel="stylesheet" href=“/css/carousel.css" /> <link rel="stylesheet" href=“/css/forum.css" /> <!-- endbuild -->

HTML:

Page 71: The Quest for the Perfect Workflow

UseMin

grunt.registerTask('minify', [ ‘useminPrepare', ‘concat', ‘cssmin', ‘uglify', ‘usemin' ]);

Grunt file:

Page 72: The Quest for the Perfect Workflow

npm installgrunt-combine-media-queries

Combine Media Queries

Reduce file size with 1 media query per breakpoint

npm installgulp-combine-media-queries

Page 73: The Quest for the Perfect Workflow

h1 { margin: 10px; @media screen and (min-width: 800px) { margin: 20px; } } !p { font-size: 1.2em; @media screen and (min-width: 800px) { font-size: 1.4em; } }

Sass:

Combine Media Queries

Page 74: The Quest for the Perfect Workflow

h1 { margin: 10px; } !@media screen and (min-width: 800px) { h1 { margin: 20px; } } !p { font-size: 1.2em; } !@media screen and (min-width: 800px) { p { font-size: 1.4em; } }

CSS:

Combine Media Queries

Page 75: The Quest for the Perfect Workflow

h1 { margin: 10px; } p { font-size: 1.2em; } !@media screen and (min-width: 800px) { h1 { margin: 20px; } p { font-size: 1.4em; } }

After:

Combine Media Queries

Page 76: The Quest for the Perfect Workflow

npm install grunt-uncss

UnCss

Remove unused CSS

npm install gulp-uncss

Page 77: The Quest for the Perfect Workflow

npm install grunt-modernizr

Streamline Modernizr

Create at build time

npm install gulp-modernizr

Page 78: The Quest for the Perfect Workflow

npm install grunt-imagemin

Minify Your Images

Reduce image file size

npm install gulp-imagemin

Page 79: The Quest for the Perfect Workflow

npm install grunt-contrib-compress

Compress Your Files

Reduce your file size so your users download less.

npm install gulp-gzip

Page 80: The Quest for the Perfect Workflow

npm install grunt-zopfli

Zopfli

Improved compression, but slower.brew install zopfli

npm install gulp-zopfli

Page 81: The Quest for the Perfect Workflow

Shrinkwrap

Lock your task dependencies.!

npm shrinkwrap

Page 82: The Quest for the Perfect Workflow

BUILD- UseMin- Combine Media Queries- Remove Unused CSS- Streamline Modernizr- Minify Your Images- Compress- Shrinkwrap Your Dependencies

Page 83: The Quest for the Perfect Workflow

Page 84: The Quest for the Perfect Workflow

That’s a lot of things!

Credit: flickr.com/photos/jason-samfield/5654182142

Page 85: The Quest for the Perfect Workflow

Is it?

- Most require minimal setup.

- Avoid mistaeks.

Page 86: The Quest for the Perfect Workflow

But…

- Don’t include tasks you don’t need.

Page 87: The Quest for the Perfect Workflow

A better workflow

SETUP

DEVELOP

BUILD

Page 88: The Quest for the Perfect Workflow

PERFECT?@andismith

Page 89: The Quest for the Perfect Workflow

Sample CSS WorkflowSass Compliation

Watch

Autoprefixer

Combine Media Queries

UseMin

Live EditingUnCSS

Newer

Build

Develop

Compress

Page 90: The Quest for the Perfect Workflow

Sample JS Workflow

JSHint

Watch

Compress

Live Editing

Modernizr

Newer Build

Develop

UseMin

Page 91: The Quest for the Perfect Workflow

A better workflow

SETUP

DEVELOP

BUILD

Page 92: The Quest for the Perfect Workflow

THANKS

@andismith

- Slides/Blog:http://j.mp/qftpw

- My site:http://andismith.com