Improving your workflow with gulp

41
Improving your workflow twitter.com/alexnewmn github.com/alex.newman alexnewman.io

Transcript of Improving your workflow with gulp

Page 1: Improving your workflow with gulp

Improving your workflow

twitter.com/alexnewmngithub.com/alex.newman

alexnewman.io

Page 2: Improving your workflow with gulp

Improving your workflow

● Why should you use gulp?● gulp API● gulp vs Grunt● The power of gulp● The future of gulp● Gotchas● Questions at the end

Page 3: Improving your workflow with gulp

Quick Facts

● 44,000 downloads a day● Used by

○ Bede Gaming○ Google○ Netflix○ Soundcloud

● Uses Node.js and Orchestrator.js● It’s open source!

Page 4: Improving your workflow with gulp

Why another task runner?

● gulp aims to be simple for users● gulp plugins should do one thing well● Can work with existing node modules● Grunt was great but did a few things wrong...

Page 5: Improving your workflow with gulp

Why use gulp?

● Code over config

Page 6: Improving your workflow with gulp

Code over config

Page 7: Improving your workflow with gulp

Why use gulp?

● Code over config

● Minimal API

● Uses streams

Page 8: Improving your workflow with gulp

Streams?

“If you dig a trench on a hill and fill up the high end using a water hose the water will run down the

hill along the trench”Tim Caswell - HowToNode.org

Page 9: Improving your workflow with gulp

● Streams use ‘pipes’, which allow us to pass data through the stream.

●●● Streams are what makes gulp fast

Streams?

Page 10: Improving your workflow with gulp

Why use gulp?

● Code over config

● Minimal API

● Uses streams

● Runs with maximum concurrency

Page 11: Improving your workflow with gulp

Maximum Concurrency

● Runs tasks together using orchestrator● Can minify your js and css at the same time● Speed!!!

Page 12: Improving your workflow with gulp

Why use gulp?

● Code over config

● Minimal API

● Uses streams

● Runs with maximum concurrency

● Fast!

Page 13: Improving your workflow with gulp

gulp API

Page 14: Improving your workflow with gulp

gulp.task

● Define a task name

● Set dependencies if required

● Can run multiple plugins

main.scss sass autoprefix min main.css

Page 15: Improving your workflow with gulp

gulp

Page 16: Improving your workflow with gulp

gulp

grunt...

Page 17: Improving your workflow with gulp

gulp.task

Page 18: Improving your workflow with gulp

gulp API

Page 19: Improving your workflow with gulp

gulp.src

● Specify the file to be processed

● Can be a string or an array of files

● Can change the base of the file

● Accepts globbing - **/*.scss

Page 20: Improving your workflow with gulp

gulp.src

Page 21: Improving your workflow with gulp

gulp API

Page 22: Improving your workflow with gulp

gulp.dest

● Where the processed file should be saved

● Can be used with src’s base option

Page 23: Improving your workflow with gulp

gulp API

Page 24: Improving your workflow with gulp

gulp.watch

● Watch files and run tasks when files change

● Accepts globbing - **/*.js

Page 25: Improving your workflow with gulp

gulp API

That’s it!

Page 26: Improving your workflow with gulp
Page 27: Improving your workflow with gulp

gulp

● Uses streams● Easy to maintain● Fast!● Runs concurrently● Fast growing

Gruntvs

Page 28: Improving your workflow with gulp

gulp

● Uses streams● Easy to maintain● Fast!● Runs concurrently● Fast growing

Gruntvs● Has to run in order● Difficult to maintain● Slow(er)!● Writes to Temp files● More plugins● Paved the way

Page 29: Improving your workflow with gulp

Task runners at Bede

● Switched to gulp in August 2014● Build times were almost twice as fast with

twice as many files to process● Can use arrays instead of specifying each

file● gulp in TeamCity for build tasks

Page 30: Improving your workflow with gulp

The power of gulp

● gulp can run a lot of tasks and processes easily and very fast

● Html minification, css minification, js linting, image compression, clean files, browserify bundles…

● Can use plugins without importing each one

Page 31: Improving your workflow with gulp

The power of gulp

Page 32: Improving your workflow with gulp

The power of gulp

Page 33: Improving your workflow with gulp

The future of gulp

● gulp 4 is in the line●●

Page 34: Improving your workflow with gulp

gulp.parallel and gulp.series

Page 35: Improving your workflow with gulp

The future of gulp

● gulp 4 is in the line●●● ES6

Page 36: Improving your workflow with gulp

ES6 Support

Page 37: Improving your workflow with gulp

The future of gulp

● gulp 4 is in the line●●● ES6● Error handling!

Page 38: Improving your workflow with gulp

Gotchas

● Error handling● Errors break the stream, cancelling the

task● Can be intimidating● Easy to rely on gulp plugins

Page 39: Improving your workflow with gulp

Summary

● Why should you use gulp?● Minimal API● gulp vs Grunt● The power of gulp● The future of gulp● Gotchas

Page 40: Improving your workflow with gulp

alexnewman.io

github.com/alexnewmannn

twitter.com/alexnewmnAll code available on my github in the FrontendNE-Talk repository

Page 41: Improving your workflow with gulp

Questions?