The Quest for the Perfect Workflow20. Choose a Task Runner
Credit: flickr.com/photos/nomadic_lass/6970307781/
24. Which to Use?
Easy to start with
Stable
2000+ plugins
Yeoman Support
Slower than
competitors.
+
+
+
+
-
Grunt
26. Your Choice
- Checklist of requirements
- Check tasks are available
and working
- Grunt is more mature, so
less risk
29. Choosing a Base
- yo webapp
!
- yo assemble
- yo firefox-os
- yo phonegap
- yo wordpress
!
yeoman.io/community-generators.html
34. 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:
35. 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:
37. Start a Local Server
connect: {
dev: {
options: {
base: ‘./dest’,
port: 4000
}
}
},
In Grunt:
38. Start a Local Server
gulp.task(‘connect',
connect.server({
root: ‘./dest’,
port: 4000
})
);
In Gulp:
43. SETUP
- Scaffold Your Workflow
- Source !== Destination
- Auto Load Tasks
- Start a Local Server
- Time your Tasks
- Run Tasks Concurrently
52. Watch & LiveReload
Split your watch into
smaller groups
watch: {
options: {
livereload: true },
sass: {
files: PATHS.SRC + PATHS.SASS + ‘{,*/}*.scss',
tasks: [‘styles'] },
scripts: {
files: PATHS.SRC + PATHS.JS + '{,*/}*.js',
tasks: [‘scripts'] }
56. 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’] }
57. Compile Changed Files
Add .pipe(changed(dest))
in Gulp
gulp.src([PATHS.SRC + PATHS.SASS + '{,*/}*.scss'])
.pipe(changed(PATHS.DEST + PATHS.SASS))
.pipe(sass())
58. Live Editing Our Files
Make changes in the browser by
setting up source maps
sass: {
options: {
sourcemap: true,
style: ‘compressed',
trace: true
},
dist: {
...
}
}
60. Live Editing Our Files
Enable source maps in Chrome
Developer Tools settings
61. Live Editing Our Files
Allow Developer Tools to access
your source in Settings,
Workspace
65. 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: [{
...
}]
},
66. DEVELOP
- Autoprefixer
- Watch & LiveReload
- Improve your Globbing
Performance
- Newer/Changed files
- Live editing CSS/JavaScript
- Grunt Responsive Images
68. For build & release
- Slower, optimisation tasks.
- Make sure you test a build with
these tasks before go-live!
70. 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:
73. 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
74. 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
75. 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
82. BUILD
- UseMin
- Combine Media Queries
- Remove Unused CSS
- Streamline Modernizr
- Minify Your Images
- Compress
- Shrinkwrap Your Dependencies
84. That’s a lot of things!
Credit: flickr.com/photos/jason-samfield/5654182142
89. Sample CSS Workflow
Sass Compliation
Watch
Autoprefixer
Combine Media
Queries
UseMin
Live Editing
UnCSS
Newer
Build
Develop
Compress