SlideShare a Scribd company logo
Automating Your
Workflow with Gulp.js
php[world] 2016
@colinodell - joind.in/talk/17992
Colin O’Dell
• Lead Web Developer at Unleashed Technologies
• PHP League Member
 league/commonmark
 league/html-to-markdown
• PHP 7 Upgrade Guide e-book
@colinodell - joind.in/talk/17992
Agenda
• What Are Task Runners?
• Getting Started with Gulp.js
• Gulp API
• Task Examples
• Q&A
@colinodell - joind.in/talk/17992
What Are Task Runners?
Software that automates, coordinates, and controls the
process of running build tasks.
• Define tasks & dependencies
• Execute those tasks
@colinodell - joind.in/talk/17992
What Are Task Runners?
Three types of tasks:
1. Tranformations
2. Tests
3. Commands
@colinodell - joind.in/talk/17992
Transformations
• Compiling SASS/LESS, CoffeeScript, etc.
• Combining/minifying files
• Compressing images
• Copying files to a different location
@colinodell - joind.in/talk/17992
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
Running Tests
• Linting for syntax errors
• Checking code styles
• Running automated tests (unit, functional, etc)
@colinodell - joind.in/talk/17992
0110011
1001111
0010011
1010010
✓✗
Running Misc. Commands
• Deleting previous builds
• Installing dependencies with Composer, npm, bower, yarn, etc.
• Any shell command
@colinodell - joind.in/talk/17992
✓✗
@colinodell - joind.in/talk/17992
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
✓✗
✓✗
When/Where To Run Build Tasks
• Locally during development
• Continuous integration
• Deployments
@colinodell - joind.in/talk/17992
Different Task Runners
Comparison between Apache Ant, Phing, Grunt, and Gulp
@colinodell - joind.in/talk/17992
Apache Ant
• Like Make, but built in Java
• Typically installed via package manager (apt-get)
• XML configuration files
@colinodell - joind.in/talk/17992
<?xml version="1.0"?>
<project name="Hello World Project" default="info">
<target name="info">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
</project>
Apache Ant
@colinodell - joind.in/talk/17992
<?xml version="1.0"?>
<project name="Compress CSS and run PHPUnit" default="build">
<target name="build" depends="compress_css,phpunit"/>
<target name="compress_css">
<apply executable="java" parallel="false">
<fileset dir="." includes="foo.css, bar.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>
<target name="phpunit">
<exec executable="./vendor/bin/phpunit" failonerror="true">
<arg value="--configuration"/>
<arg path="phpunit.xml"/>
</exec>
</target>
</project>
Phing
• Based on Apache Ant, but built in PHP
• Typically installed via PEAR or Composer
• XML configuration files
@colinodell - joind.in/talk/17992
<?xml version="1.0"?>
<project name="Hello World Project" default="info">
<target name="info">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
</project>
Apache Ant
@colinodell - joind.in/talk/17992
<?xml version="1.0"?>
<project name="Compress CSS and run PHPUnit" default="build">
<target name="build" depends="compress_css,phpunit"/>
<target name="compress_css">
<apply executable="java" parallel="false">
<fileset dir="." includes="foo.css, bar.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>
<target name="phpunit">
<exec executable="./vendor/bin/phpunit" failonerror="true">
<arg value="--configuration"/>
<arg path="phpunit.xml"/>
</exec>
</target>
</project>
@colinodell - joind.in/talk/17992
<?xml version="1.0"?>
<project name="Compress CSS and run PHPUnit" default="build">
<target name="build" depends="compress_css,phpunit"/>
<target name="compress_css">
<apply executable="java" parallel="false">
<fileset dir="." includes="foo.css, bar.css"/>
<arg line="-jar"/>
<arg path="yuicompressor.jar"/>
<srcfile/>
<arg line="-o"/>
<mapper type="glob" from="*.css" to="*-min.css"/>
<targetfile/>
</apply>
</target>
<target name="phpunit">
<phpunit pharlocation="./vendor/bin/phpunit" configuration="phpunit.xml"/>
</target>
</project>
Grunt
• Built in JavaScript
• Many third-party plugins; easy to install
• JS-based configuration with heavy JSON usage
@colinodell - joind.in/talk/17992
var grunt = require('grunt');
grunt.registerTask('default', 'The default build task', function(){
console.log('Hello World!');
});
@colinodell - joind.in/talk/17992
var grunt = require('grunt');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-phpunit');
grunt.initConfig({
cssmin: {
target: {
files: [{
src: ['foo.css', 'bar.css'],
dest: 'build/css',
ext: '.min.css'
}]
}
},
phpunit: {
options: {
bin: 'vendor/bin/phpunit',
configuration: 'phpunit.xml',
coverage: false
}
}
});
grunt.registerTask('default', 'The default build task', ['cssmin', 'phpunit']);
Gulp.js
• Built in JavaScript
• Many third-party plugins; easy to install
• Uses JS code instead of configuration
• Built around file streams
@colinodell - joind.in/talk/17992
var gulp = require('gulp');
gulp.task('default', function() {
console.log('Hello world.');
});
@colinodell - joind.in/talk/17992
var gulp = require('gulp');
var cssmin = require('gulp-minify-css');
var phpunit = require('gulp-phpunit');
var rename = require('gulp-rename');
gulp.task('cssmin', function() {
return gulp.src(['foo.css', 'bar.css'])
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('build/css'));
});
gulp.task('phpunit', function() {
var options = { noCoverage: true };
return gulp.src('phpunit.xml')
.pipe(phpunit('./vendor/bin/phpunit', options));
});
gulp.task('default', ['cssmin', 'phpunit']);
@colinodell - joind.in/talk/17992
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
0110011
1001111
0010011
1010010
{ … }
0110011
1001111
0010011
1010010
Getting Started with
Gulp.js
@colinodell - joind.in/talk/17992
Installing gulp-cli
@colinodell - joind.in/talk/17992
Initializing npm
@colinodell - joind.in/talk/17992
Adding gulp to a project
@colinodell - joind.in/talk/17992
Adding gulp to a project
@colinodell - joind.in/talk/17992
gulpfile.js
@colinodell - joind.in/talk/17992
var gulp = require('gulp');
gulp.task('default', function() {
// place code for your default task here
});
gulpfile.js
@colinodell - joind.in/talk/17992
Gulp API
@colinodell - joind.in/talk/17992
gulp.task(name [, deps] [, fn])
• Defines tasks and their dependencies
• Three parameters:
 Name (required)
 Array of task dependencies
 Function to run
@colinodell - joind.in/talk/17992
gulp.task('sometask', function() {
// Do stuff
});
gulp.task('sometask', ['dep1', 'dep2'], function() {
// Do stuff
});
gulp.task('js', ['jshint', 'jsmin']);
gulp.src(globs [, options])
• Two parameters:
 Globs of files (required)
 String or array
 Options
• Returns a stream of Vinyl files that can be piped to plugins
@colinodell - joind.in/talk/17992
gulp.src('styles/foo.css')
gulp.src('styles/*.css')
gulp.src('styles/**/*.css')
gulp.src(['styles/**/*.css', '!*.min.css'])
var themeBase = 'src/theme';
var distThemeBase = 'web/theme';
var paths = {
img: [themeBase + '/img/**/*.{gif,png,jpg,svg,svgz}'],
js: [themeBase + '/js/**/*.js'],
font: [themeBase + '/fonts/**/*.{otf,eot,svg,ttf,woff,woff2}'],
css: [themeBase + '/styles/**/*.css'],
favicons: [themeBase + '/favicons/**/*.{png,xml,ico,json,svg}'],
php: ['src/**/*.php'],
xml: ['src/**/*.xml'],
distContrib: distThemeBase + '/contrib/',
distCSS: distThemeBase + '/css/',
distJS: distThemeBase + '/js/',
distImg: distThemeBase + '/img/',
distFont: distThemeBase + '/fonts/',
distFavicons: distThemeBase + '/favicons/'
};
gulp.src(paths.css);
@colinodell - joind.in/talk/17992
.pipe(destination)
• Called on gulp.src() result stream
• destination is a stream (typically an input stream created by a plugin)
@colinodell - joind.in/talk/17992
return gulp.src(['foo.css', 'bar.css'])
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('build/css'));
gulp.dest(path [,options])
• Writes the streamed files to the given path
@colinodell - joind.in/talk/17992
return gulp.src(['foo.css', 'bar.css'])
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('build/css'));
Examples
Code Linting
@colinodell - joind.in/talk/17992
jshint
@colinodell - joind.in/talk/17992
var jshint = require('gulp-jshint');
gulp.task('jshint', function() {
return gulp.src(paths.js)
.pipe(jshint())
.pipe(jshint.reporter())
.pipe(jshint.reporter('fail'));
});
jshint
@colinodell - joind.in/talk/17992
csslint
@colinodell - joind.in/talk/17992
var csslint = require('gulp-csslint');
gulp.task('csslint', function() {
return gulp.src([paths.css, '!**/*.min.css'])
.pipe(csslint('.csslintrc'))
.pipe(csslint.reporter())
.pipe(csslint.failReporter());
});
phplint
@colinodell - joind.in/talk/17992
var phplint = require('gulp-phplint');
gulp.task('phplint', function() {
return gulp.src(paths.phpLint)
.pipe(phplint())
.pipe(phplint.reporter('fail'));
});
phpcs
@colinodell - joind.in/talk/17992
var phpcs = require('gulp-phpcs');
gulp.task('phpcs', ['phplint'], function() {
var options = {
bin: 'vendor/bin/phpcs',
standard: 'PSR2
};
return gulp.src(paths.php)
.pipe(phpcs(options))
.pipe(phpcs.reporter('log'))
.pipe(phpcs.reporter('fail'));
});
eol
@colinodell - joind.in/talk/17992
var eol = require('gulp-eol-enforce');
gulp.task('eol', function(){
var paths = [].concat(paths.php, paths.less, paths.js, paths.xml);
return gulp.src(paths)
.pipe(eol('n'));
});
'lint' task group
@colinodell - joind.in/talk/17992
gulp.task('lint', ['eol', 'phpcs', 'csslint', 'jshint']);
gulp.task('lint', function() {
gulp.start('eol', 'phpcs', 'csslint', 'jshint');
});
Examples
Transformations
@colinodell - joind.in/talk/17992
Compile, autoprefix, and minify LESS
@colinodell - joind.in/talk/17992
var autoprefixer = require('gulp-autoprefixer'),
less = require('gulp-less'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename')
;
gulp.task('less', function() {
return gulp.src(paths.less)
.pipe(less())
.pipe(autoprefixer({
browsers: ['last 3 versions', 'ie >= 8']
}))
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.distCSS));
});
Compile, autoprefix, and minify SASS
@colinodell - joind.in/talk/17992
var autoprefixer = require('gulp-autoprefixer'),
sass = require('gulp-sass'),
minifycss = require('gulp-minify-css'),
rename = require('gulp-rename')
;
gulp.task('sass', function() {
return gulp.src(paths.sass)
.pipe(sass())
.pipe(autoprefixer({
browsers: ['last 3 versions', 'ie >= 8']
}))
.pipe(minifycss())
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest(paths.distCSS));
});
Compressing Images
@colinodell - joind.in/talk/17992
var imagemin = require('gulp-imagemin');
gulp.task('images', function () {
var options = {
svgoPlugins: [{removeViewBox: false}]
};
return gulp.src(paths.img)
.pipe(imagemin(options))
.pipe(gulp.dest(paths.distImg));
});
Examples
Unit Tests
@colinodell - joind.in/talk/17992
PHPUnit Tests
@colinodell - joind.in/talk/17992
var phpunit = require('gulp-phpunit');
gulp.task('phpunit', function () {
return gulp.src('phpunit.xml')
.pipe(phpunit('./vendor/bin/phpunit', {notify: true}));
});
Examples
Command Line Scripts
@colinodell - joind.in/talk/17992
Run Shell Commands
@colinodell - joind.in/talk/17992
var shell = require('gulp-shell');
gulp.task('deps', shell.task([
'composer install',
'npm install',
'bower install'
]));
Examples
Task Groups
@colinodell - joind.in/talk/17992
Task Groups
@colinodell - joind.in/talk/17992
gulp.task('lint', function() {
gulp.start('eol', 'phpcs', 'csslint', 'jshint');
});
gulp.task('build', function() {
gulp.start('css', 'images', 'js', 'fonts', 'favicons');
});
gulp.task('test', function() {
gulp.start('lint', 'phpcs');
});
gulp.task('default', function() {
gulp.start('test', 'build');
});
@colinodell - joind.in/talk/17992
@colinodell - joind.in/talk/17992
Useful Utilities
@colinodell - joind.in/talk/17992
gulp-changed
@colinodell - joind.in/talk/17992
var imagemin = require('gulp-imagemin');
gulp.task('images', function () {
var options = {
svgoPlugins: [{removeViewBox: false}]
};
return gulp.src(paths.img)
.pipe(imagemin(options))
.pipe(gulp.dest(paths.distImg));
});
gulp-changed
@colinodell - joind.in/talk/17992
var changed = require('gulp-changed');
var imagemin = require('gulp-imagemin');
gulp.task('images', function () {
var options = {
svgoPlugins: [{removeViewBox: false}]
};
return gulp.src(paths.img)
.pipe(changed(paths.distImg))
.pipe(imagemin(options))
.pipe(gulp.dest(paths.distImg));
});
gulp-newer
@colinodell - joind.in/talk/17992
var gulp = require('gulp');
var newer = require('gulp-newer');
var concat = require('gulp-concat');
gulp.task('concat', function() {
return gulp.src('lib/*.js')
.pipe(newer('dist/all.js'))
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'));
});
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('build-js', function() {
return gulp.src(paths.js)
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.distJs));
});
gulp-sourcemaps
@colinodell - joind.in/talk/17992
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
gulp.task('build-js', function() {
return gulp.src(paths.js)
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(paths.distJs));
});
gulp-sourcemaps
@colinodell - joind.in/talk/17992
gulp-load-plugins
@colinodell - joind.in/talk/17992
{
"devDependencies": {
"gulp": "~3.9",
"gulp-autoprefixer": "~2.3.1",
"gulp-bower": "~0.0.10",
"gulp-changed": "~1.2.1",
"gulp-csslint": "~0.1.5",
"gulp-eol-enforce": "*",
"gulp-imagemin": "~2.3.0",
"gulp-jshint": "~1.11.2",
"gulp-less": "~3.0.3",
"gulp-minify-css": "~1.2.0",
"gulp-phpcs": "~0.6.0",
"gulp-rename": "~1.2.2",
"gulp-uglify": "~1.2.0"
}
}
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
bower = require('gulp-bower'),
changed = require('gulp-changed'),
csslint = require('gulp-csslint'),
eol = require('gulp-eol-enforce'),
imagemin = require('gulp-imagemin'),
jshint = require('gulp-jshint'),
less = require('gulp-less'),
minifycss = require('gulp-minify-css'),
phpcs = require('gulp-phpcs'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');
gulp-load-plugins
@colinodell - joind.in/talk/17992
{
"devDependencies": {
"gulp": "~3.9",
"gulp-autoprefixer": "~2.3.1",
"gulp-bower": "~0.0.10",
"gulp-changed": "~1.2.1",
"gulp-csslint": "~0.1.5",
"gulp-eol-enforce": "*",
"gulp-imagemin": "~2.3.0",
"gulp-jshint": "~1.11.2",
"gulp-less": "~3.0.3",
"gulp-minify-css": "~1.2.0",
"gulp-phpcs": "~0.6.0",
"gulp-rename": "~1.2.2",
"gulp-uglify": "~1.2.0"
}
}
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')();
// ...
.pipe(plugins.changed('app.css'))
.pipe(plugins.less())
// ...
gulp.watch(paths, tasks)
@colinodell - joind.in/talk/17992
gulp.task('watch', function() {
gulp.watch(paths.less, ['css']);
gulp.watch(paths.img, ['images']);
gulp.watch(paths.js, ['js']);
gulp.watch(paths.font, ['fonts']);
gulp.watch(paths.favicons, ['favicons']);
gulp.watch(paths.php, ['phpcs']);
});
gulp.watch(paths, tasks)
@colinodell - joind.in/talk/17992
• Example: https://youtu.be/9d9756j2pq8?t=100
Other Plugins & Integrations
• Browsersync – Live browser reloads
• gulp-notify – Sends notifications to OS notification center or Growl
• gulp-autopolyfiller – Like autoprefixer, but for JS polyfills
• gulp-git – Run Git commands within Gulp
• gulp-ssh – Connect to servers via SSH and SFTP
@colinodell - joind.in/talk/17992
Summary
@colinodell - joind.in/talk/17992
• Task runners help automate build processes
• Automate during development, CI, and deployment
• Gulp is fast, easy-to-use, and has tons of great plugins
Questions?
@colinodell - joind.in/talk/17992
Thanks!
Slides/Feedback:
https://joind.in/talk/17992
@colinodell - joind.in/talk/17992

More Related Content

What's hot (20)

PDF
But we're already open source! Why would I want to bring my code to Apache?
gagravarr
 
PDF
Matt's PSGI Archive
Dave Cross
 
PDF
Free The Enterprise With Ruby & Master Your Own Domain
Ken Collins
 
PDF
Perl in the Internet of Things
Dave Cross
 
PDF
Getting Git Right
Sven Peters
 
PDF
Modern Perl for the Unfrozen Paleolithic Perl Programmer
John Anderson
 
PDF
Git training v10
Skander Hamza
 
PDF
Kamailio Updates - VUC 588
Daniel-Constantin Mierla
 
KEY
Perl in Teh Cloud
Pedro Figueiredo
 
PDF
effective_r27
Hiroshi Ono
 
PDF
VCS for Teamwork - GIT Workshop
Anis Ahmad
 
PDF
An introduction to git
olberger
 
KEY
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
PDF
Node.js cluster
Derek Willian Stavis
 
PDF
Kamailio - Load Balancing Load Balancers
Daniel-Constantin Mierla
 
PPTX
Server Side Swift
Chad Moone
 
PDF
Building real time applications with Symfony2
Antonio Peric-Mazar
 
PDF
Ruby in office time reboot
Kentaro Goto
 
PDF
Kamailio - Surfing Big Waves Of SIP With Style
Daniel-Constantin Mierla
 
KEY
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 
But we're already open source! Why would I want to bring my code to Apache?
gagravarr
 
Matt's PSGI Archive
Dave Cross
 
Free The Enterprise With Ruby & Master Your Own Domain
Ken Collins
 
Perl in the Internet of Things
Dave Cross
 
Getting Git Right
Sven Peters
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
John Anderson
 
Git training v10
Skander Hamza
 
Kamailio Updates - VUC 588
Daniel-Constantin Mierla
 
Perl in Teh Cloud
Pedro Figueiredo
 
effective_r27
Hiroshi Ono
 
VCS for Teamwork - GIT Workshop
Anis Ahmad
 
An introduction to git
olberger
 
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 
Node.js cluster
Derek Willian Stavis
 
Kamailio - Load Balancing Load Balancers
Daniel-Constantin Mierla
 
Server Side Swift
Chad Moone
 
Building real time applications with Symfony2
Antonio Peric-Mazar
 
Ruby in office time reboot
Kentaro Goto
 
Kamailio - Surfing Big Waves Of SIP With Style
Daniel-Constantin Mierla
 
Intro to PSGI and Plack
Tatsuhiko Miyagawa
 

Viewers also liked (20)

PPT
XP+Scrum+DevOps
Guillaume Sondag
 
PPTX
Debugging Effectively - SunshinePHP 2017
Colin O'Dell
 
PPTX
From Docker to Production - SunshinePHP 2017
Chris Tankersley
 
PPTX
Debugging Effectively - PHP UK 2017
Colin O'Dell
 
PPTX
Docker for Developers - Sunshine PHP
Chris Tankersley
 
PDF
MVC in PHP
Vineet Kumar Saini
 
PDF
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
James Titcumb
 
PDF
Create, test, secure, repeat
Michelangelo van Dam
 
PDF
Hack the Future
Jason McCreary
 
PPTX
Engineer - Mastering the Art of Software
Cristiano Diniz da Silva
 
PDF
Zend Framework Foundations
Chuck Reeves
 
PDF
php[world] 2015 Training - Laravel from the Ground Up
Joe Ferguson
 
PDF
Amp your site an intro to accelerated mobile pages
Robert McFrazier
 
PDF
Console Apps: php artisan forthe:win
Joe Ferguson
 
PDF
Presentation Bulgaria PHP
Alena Holligan
 
PDF
Code Coverage for Total Security in Application Migrations
Dana Luther
 
PDF
Git Empowered
Jason McCreary
 
PDF
Dip Your Toes in the Sea of Security
James Titcumb
 
PPTX
Php extensions
Elizabeth Smith
 
PDF
Conscious Coupling
CiaranMcNulty
 
XP+Scrum+DevOps
Guillaume Sondag
 
Debugging Effectively - SunshinePHP 2017
Colin O'Dell
 
From Docker to Production - SunshinePHP 2017
Chris Tankersley
 
Debugging Effectively - PHP UK 2017
Colin O'Dell
 
Docker for Developers - Sunshine PHP
Chris Tankersley
 
MVC in PHP
Vineet Kumar Saini
 
Adding 1.21 Gigawatts to Applications with RabbitMQ (Bulgaria PHP 2016 - Tuto...
James Titcumb
 
Create, test, secure, repeat
Michelangelo van Dam
 
Hack the Future
Jason McCreary
 
Engineer - Mastering the Art of Software
Cristiano Diniz da Silva
 
Zend Framework Foundations
Chuck Reeves
 
php[world] 2015 Training - Laravel from the Ground Up
Joe Ferguson
 
Amp your site an intro to accelerated mobile pages
Robert McFrazier
 
Console Apps: php artisan forthe:win
Joe Ferguson
 
Presentation Bulgaria PHP
Alena Holligan
 
Code Coverage for Total Security in Application Migrations
Dana Luther
 
Git Empowered
Jason McCreary
 
Dip Your Toes in the Sea of Security
James Titcumb
 
Php extensions
Elizabeth Smith
 
Conscious Coupling
CiaranMcNulty
 
Ad

Similar to Automating Your Workflow with Gulp.js - php[world] 2016 (20)

PPTX
JS Essence
Uladzimir Piatryka
 
PPT
Build Automation of PHP Applications
Pavan Kumar N
 
PDF
Frontend JS workflow - Gulp 4 and the like
Damien Seguin
 
PDF
World is changed. i feel it in the front end
Andriy Yun
 
ODP
Knolx session
Knoldus Inc.
 
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
PDF
PHP Development Tools
Antony Abramchenko
 
PDF
6 tips for improving ruby performance
Engine Yard
 
PDF
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
ODP
Drupal Theme Development - DrupalCon Chicago 2011
Ryan Price
 
PDF
Killing the Angle Bracket
jnewmanux
 
PDF
Introduction to Apache Amaterasu (Incubating): CD Framework For Your Big Data...
DataWorks Summit
 
PDF
Reactive Type safe Webcomponents with skateJS
Martin Hochel
 
PPTX
Javascript first-class citizenery
toddbr
 
PDF
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
PDF
Into The Box 2018 Ortus Keynote
Ortus Solutions, Corp
 
KEY
Wider than rails
Alexey Nayden
 
PDF
AD102 - Break out of the Box
Karl-Henry Martinsson
 
PDF
Brad Wood - CommandBox CLI
Ortus Solutions, Corp
 
PDF
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
JS Essence
Uladzimir Piatryka
 
Build Automation of PHP Applications
Pavan Kumar N
 
Frontend JS workflow - Gulp 4 and the like
Damien Seguin
 
World is changed. i feel it in the front end
Andriy Yun
 
Knolx session
Knoldus Inc.
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
Fabio Franzini
 
PHP Development Tools
Antony Abramchenko
 
6 tips for improving ruby performance
Engine Yard
 
DSLing your System For Scalability Testing Using Gatling - Dublin Scala User ...
Aman Kohli
 
Drupal Theme Development - DrupalCon Chicago 2011
Ryan Price
 
Killing the Angle Bracket
jnewmanux
 
Introduction to Apache Amaterasu (Incubating): CD Framework For Your Big Data...
DataWorks Summit
 
Reactive Type safe Webcomponents with skateJS
Martin Hochel
 
Javascript first-class citizenery
toddbr
 
Exploring Async PHP (SF Live Berlin 2019)
dantleech
 
Into The Box 2018 Ortus Keynote
Ortus Solutions, Corp
 
Wider than rails
Alexey Nayden
 
AD102 - Break out of the Box
Karl-Henry Martinsson
 
Brad Wood - CommandBox CLI
Ortus Solutions, Corp
 
Everything is Awesome - Cutting the Corners off the Web
James Rakich
 
Ad

More from Colin O'Dell (20)

PPTX
Demystifying Unicode - Longhorn PHP 2021
Colin O'Dell
 
PPTX
Releasing High Quality Packages - Longhorn PHP 2021
Colin O'Dell
 
PPTX
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Colin O'Dell
 
PPTX
Debugging Effectively - ConFoo Montreal 2019
Colin O'Dell
 
PPTX
Automating Deployments with Deployer - php[world] 2018
Colin O'Dell
 
PPTX
Releasing High-Quality Packages - php[world] 2018
Colin O'Dell
 
PPTX
Debugging Effectively - DrupalCon Nashville 2018
Colin O'Dell
 
PPTX
CommonMark: Markdown Done Right - ZendCon 2017
Colin O'Dell
 
PPTX
Debugging Effectively - All Things Open 2017
Colin O'Dell
 
PPTX
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Colin O'Dell
 
PPTX
Debugging Effectively - ZendCon 2016
Colin O'Dell
 
PPTX
Hacking Your Way to Better Security - ZendCon 2016
Colin O'Dell
 
PPTX
Hacking Your Way to Better Security - PHP South Africa 2016
Colin O'Dell
 
PPTX
Debugging Effectively - DrupalCon Europe 2016
Colin O'Dell
 
PPTX
CommonMark: Markdown done right - Nomad PHP September 2016
Colin O'Dell
 
PPTX
Debugging Effectively - Frederick Web Tech 9/6/16
Colin O'Dell
 
PPTX
Debugging Effectively
Colin O'Dell
 
PPTX
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Colin O'Dell
 
PDF
Hacking Your Way To Better Security - php[tek] 2016
Colin O'Dell
 
PDF
CommonMark: Markdown Done Right
Colin O'Dell
 
Demystifying Unicode - Longhorn PHP 2021
Colin O'Dell
 
Releasing High Quality Packages - Longhorn PHP 2021
Colin O'Dell
 
Releasing High Quality PHP Packages - ConFoo Montreal 2019
Colin O'Dell
 
Debugging Effectively - ConFoo Montreal 2019
Colin O'Dell
 
Automating Deployments with Deployer - php[world] 2018
Colin O'Dell
 
Releasing High-Quality Packages - php[world] 2018
Colin O'Dell
 
Debugging Effectively - DrupalCon Nashville 2018
Colin O'Dell
 
CommonMark: Markdown Done Right - ZendCon 2017
Colin O'Dell
 
Debugging Effectively - All Things Open 2017
Colin O'Dell
 
Hacking Your Way To Better Security - DrupalCon Baltimore 2017
Colin O'Dell
 
Debugging Effectively - ZendCon 2016
Colin O'Dell
 
Hacking Your Way to Better Security - ZendCon 2016
Colin O'Dell
 
Hacking Your Way to Better Security - PHP South Africa 2016
Colin O'Dell
 
Debugging Effectively - DrupalCon Europe 2016
Colin O'Dell
 
CommonMark: Markdown done right - Nomad PHP September 2016
Colin O'Dell
 
Debugging Effectively - Frederick Web Tech 9/6/16
Colin O'Dell
 
Debugging Effectively
Colin O'Dell
 
Hacking Your Way To Better Security - Dutch PHP Conference 2016
Colin O'Dell
 
Hacking Your Way To Better Security - php[tek] 2016
Colin O'Dell
 
CommonMark: Markdown Done Right
Colin O'Dell
 

Recently uploaded (20)

PDF
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PDF
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
PDF
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
PDF
Executive Business Intelligence Dashboards
vandeslie24
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Powering GIS with FME and VertiGIS - Peak of Data & AI 2025
Safe Software
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
Salesforce CRM Services.VALiNTRY360
VALiNTRY360
 
Import Data Form Excel to Tally Services
Tally xperts
 
Tally software_Introduction_Presentation
AditiBansal54083
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
How Odoo Became a Game-Changer for an IT Company in Manufacturing ERP
SatishKumar2651
 
Continouous failure - Why do we make our lives hard?
Papp Krisztián
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Mobile CMMS Solutions Empowering the Frontline Workforce
CryotosCMMSSoftware
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Perfecting XM Cloud for Multisite Setup.pptx
Ahmed Okour
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Executive Business Intelligence Dashboards
vandeslie24
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 

Automating Your Workflow with Gulp.js - php[world] 2016

  • 1. Automating Your Workflow with Gulp.js php[world] 2016 @colinodell - joind.in/talk/17992
  • 2. Colin O’Dell • Lead Web Developer at Unleashed Technologies • PHP League Member  league/commonmark  league/html-to-markdown • PHP 7 Upgrade Guide e-book @colinodell - joind.in/talk/17992
  • 3. Agenda • What Are Task Runners? • Getting Started with Gulp.js • Gulp API • Task Examples • Q&A @colinodell - joind.in/talk/17992
  • 4. What Are Task Runners? Software that automates, coordinates, and controls the process of running build tasks. • Define tasks & dependencies • Execute those tasks @colinodell - joind.in/talk/17992
  • 5. What Are Task Runners? Three types of tasks: 1. Tranformations 2. Tests 3. Commands @colinodell - joind.in/talk/17992
  • 6. Transformations • Compiling SASS/LESS, CoffeeScript, etc. • Combining/minifying files • Compressing images • Copying files to a different location @colinodell - joind.in/talk/17992 0110011 1001111 0010011 1010010 0110011 1001111 0010011 1010010
  • 7. Running Tests • Linting for syntax errors • Checking code styles • Running automated tests (unit, functional, etc) @colinodell - joind.in/talk/17992 0110011 1001111 0010011 1010010 ✓✗
  • 8. Running Misc. Commands • Deleting previous builds • Installing dependencies with Composer, npm, bower, yarn, etc. • Any shell command @colinodell - joind.in/talk/17992 ✓✗
  • 10. When/Where To Run Build Tasks • Locally during development • Continuous integration • Deployments @colinodell - joind.in/talk/17992
  • 11. Different Task Runners Comparison between Apache Ant, Phing, Grunt, and Gulp @colinodell - joind.in/talk/17992
  • 12. Apache Ant • Like Make, but built in Java • Typically installed via package manager (apt-get) • XML configuration files @colinodell - joind.in/talk/17992 <?xml version="1.0"?> <project name="Hello World Project" default="info"> <target name="info"> <echo>Hello World - Welcome to Apache Ant!</echo> </target> </project>
  • 13. Apache Ant @colinodell - joind.in/talk/17992 <?xml version="1.0"?> <project name="Compress CSS and run PHPUnit" default="build"> <target name="build" depends="compress_css,phpunit"/> <target name="compress_css"> <apply executable="java" parallel="false"> <fileset dir="." includes="foo.css, bar.css"/> <arg line="-jar"/> <arg path="yuicompressor.jar"/> <srcfile/> <arg line="-o"/> <mapper type="glob" from="*.css" to="*-min.css"/> <targetfile/> </apply> </target> <target name="phpunit"> <exec executable="./vendor/bin/phpunit" failonerror="true"> <arg value="--configuration"/> <arg path="phpunit.xml"/> </exec> </target> </project>
  • 14. Phing • Based on Apache Ant, but built in PHP • Typically installed via PEAR or Composer • XML configuration files @colinodell - joind.in/talk/17992 <?xml version="1.0"?> <project name="Hello World Project" default="info"> <target name="info"> <echo>Hello World - Welcome to Apache Ant!</echo> </target> </project>
  • 15. Apache Ant @colinodell - joind.in/talk/17992 <?xml version="1.0"?> <project name="Compress CSS and run PHPUnit" default="build"> <target name="build" depends="compress_css,phpunit"/> <target name="compress_css"> <apply executable="java" parallel="false"> <fileset dir="." includes="foo.css, bar.css"/> <arg line="-jar"/> <arg path="yuicompressor.jar"/> <srcfile/> <arg line="-o"/> <mapper type="glob" from="*.css" to="*-min.css"/> <targetfile/> </apply> </target> <target name="phpunit"> <exec executable="./vendor/bin/phpunit" failonerror="true"> <arg value="--configuration"/> <arg path="phpunit.xml"/> </exec> </target> </project>
  • 16. @colinodell - joind.in/talk/17992 <?xml version="1.0"?> <project name="Compress CSS and run PHPUnit" default="build"> <target name="build" depends="compress_css,phpunit"/> <target name="compress_css"> <apply executable="java" parallel="false"> <fileset dir="." includes="foo.css, bar.css"/> <arg line="-jar"/> <arg path="yuicompressor.jar"/> <srcfile/> <arg line="-o"/> <mapper type="glob" from="*.css" to="*-min.css"/> <targetfile/> </apply> </target> <target name="phpunit"> <phpunit pharlocation="./vendor/bin/phpunit" configuration="phpunit.xml"/> </target> </project>
  • 17. Grunt • Built in JavaScript • Many third-party plugins; easy to install • JS-based configuration with heavy JSON usage @colinodell - joind.in/talk/17992 var grunt = require('grunt'); grunt.registerTask('default', 'The default build task', function(){ console.log('Hello World!'); });
  • 18. @colinodell - joind.in/talk/17992 var grunt = require('grunt'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-phpunit'); grunt.initConfig({ cssmin: { target: { files: [{ src: ['foo.css', 'bar.css'], dest: 'build/css', ext: '.min.css' }] } }, phpunit: { options: { bin: 'vendor/bin/phpunit', configuration: 'phpunit.xml', coverage: false } } }); grunt.registerTask('default', 'The default build task', ['cssmin', 'phpunit']);
  • 19. Gulp.js • Built in JavaScript • Many third-party plugins; easy to install • Uses JS code instead of configuration • Built around file streams @colinodell - joind.in/talk/17992 var gulp = require('gulp'); gulp.task('default', function() { console.log('Hello world.'); });
  • 20. @colinodell - joind.in/talk/17992 var gulp = require('gulp'); var cssmin = require('gulp-minify-css'); var phpunit = require('gulp-phpunit'); var rename = require('gulp-rename'); gulp.task('cssmin', function() { return gulp.src(['foo.css', 'bar.css']) .pipe(minifycss()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('build/css')); }); gulp.task('phpunit', function() { var options = { noCoverage: true }; return gulp.src('phpunit.xml') .pipe(phpunit('./vendor/bin/phpunit', options)); }); gulp.task('default', ['cssmin', 'phpunit']);
  • 23. Installing gulp-cli @colinodell - joind.in/talk/17992
  • 24. Initializing npm @colinodell - joind.in/talk/17992
  • 25. Adding gulp to a project @colinodell - joind.in/talk/17992
  • 26. Adding gulp to a project @colinodell - joind.in/talk/17992
  • 27. gulpfile.js @colinodell - joind.in/talk/17992 var gulp = require('gulp'); gulp.task('default', function() { // place code for your default task here });
  • 29. Gulp API @colinodell - joind.in/talk/17992
  • 30. gulp.task(name [, deps] [, fn]) • Defines tasks and their dependencies • Three parameters:  Name (required)  Array of task dependencies  Function to run @colinodell - joind.in/talk/17992 gulp.task('sometask', function() { // Do stuff }); gulp.task('sometask', ['dep1', 'dep2'], function() { // Do stuff }); gulp.task('js', ['jshint', 'jsmin']);
  • 31. gulp.src(globs [, options]) • Two parameters:  Globs of files (required)  String or array  Options • Returns a stream of Vinyl files that can be piped to plugins @colinodell - joind.in/talk/17992 gulp.src('styles/foo.css') gulp.src('styles/*.css') gulp.src('styles/**/*.css') gulp.src(['styles/**/*.css', '!*.min.css'])
  • 32. var themeBase = 'src/theme'; var distThemeBase = 'web/theme'; var paths = { img: [themeBase + '/img/**/*.{gif,png,jpg,svg,svgz}'], js: [themeBase + '/js/**/*.js'], font: [themeBase + '/fonts/**/*.{otf,eot,svg,ttf,woff,woff2}'], css: [themeBase + '/styles/**/*.css'], favicons: [themeBase + '/favicons/**/*.{png,xml,ico,json,svg}'], php: ['src/**/*.php'], xml: ['src/**/*.xml'], distContrib: distThemeBase + '/contrib/', distCSS: distThemeBase + '/css/', distJS: distThemeBase + '/js/', distImg: distThemeBase + '/img/', distFont: distThemeBase + '/fonts/', distFavicons: distThemeBase + '/favicons/' }; gulp.src(paths.css); @colinodell - joind.in/talk/17992
  • 33. .pipe(destination) • Called on gulp.src() result stream • destination is a stream (typically an input stream created by a plugin) @colinodell - joind.in/talk/17992 return gulp.src(['foo.css', 'bar.css']) .pipe(minifycss()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('build/css'));
  • 34. gulp.dest(path [,options]) • Writes the streamed files to the given path @colinodell - joind.in/talk/17992 return gulp.src(['foo.css', 'bar.css']) .pipe(minifycss()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest('build/css'));
  • 35. Examples Code Linting @colinodell - joind.in/talk/17992
  • 36. jshint @colinodell - joind.in/talk/17992 var jshint = require('gulp-jshint'); gulp.task('jshint', function() { return gulp.src(paths.js) .pipe(jshint()) .pipe(jshint.reporter()) .pipe(jshint.reporter('fail')); });
  • 38. csslint @colinodell - joind.in/talk/17992 var csslint = require('gulp-csslint'); gulp.task('csslint', function() { return gulp.src([paths.css, '!**/*.min.css']) .pipe(csslint('.csslintrc')) .pipe(csslint.reporter()) .pipe(csslint.failReporter()); });
  • 39. phplint @colinodell - joind.in/talk/17992 var phplint = require('gulp-phplint'); gulp.task('phplint', function() { return gulp.src(paths.phpLint) .pipe(phplint()) .pipe(phplint.reporter('fail')); });
  • 40. phpcs @colinodell - joind.in/talk/17992 var phpcs = require('gulp-phpcs'); gulp.task('phpcs', ['phplint'], function() { var options = { bin: 'vendor/bin/phpcs', standard: 'PSR2 }; return gulp.src(paths.php) .pipe(phpcs(options)) .pipe(phpcs.reporter('log')) .pipe(phpcs.reporter('fail')); });
  • 41. eol @colinodell - joind.in/talk/17992 var eol = require('gulp-eol-enforce'); gulp.task('eol', function(){ var paths = [].concat(paths.php, paths.less, paths.js, paths.xml); return gulp.src(paths) .pipe(eol('n')); });
  • 42. 'lint' task group @colinodell - joind.in/talk/17992 gulp.task('lint', ['eol', 'phpcs', 'csslint', 'jshint']); gulp.task('lint', function() { gulp.start('eol', 'phpcs', 'csslint', 'jshint'); });
  • 44. Compile, autoprefix, and minify LESS @colinodell - joind.in/talk/17992 var autoprefixer = require('gulp-autoprefixer'), less = require('gulp-less'), minifycss = require('gulp-minify-css'), rename = require('gulp-rename') ; gulp.task('less', function() { return gulp.src(paths.less) .pipe(less()) .pipe(autoprefixer({ browsers: ['last 3 versions', 'ie >= 8'] })) .pipe(minifycss()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest(paths.distCSS)); });
  • 45. Compile, autoprefix, and minify SASS @colinodell - joind.in/talk/17992 var autoprefixer = require('gulp-autoprefixer'), sass = require('gulp-sass'), minifycss = require('gulp-minify-css'), rename = require('gulp-rename') ; gulp.task('sass', function() { return gulp.src(paths.sass) .pipe(sass()) .pipe(autoprefixer({ browsers: ['last 3 versions', 'ie >= 8'] })) .pipe(minifycss()) .pipe(rename({ suffix: '.min' })) .pipe(gulp.dest(paths.distCSS)); });
  • 46. Compressing Images @colinodell - joind.in/talk/17992 var imagemin = require('gulp-imagemin'); gulp.task('images', function () { var options = { svgoPlugins: [{removeViewBox: false}] }; return gulp.src(paths.img) .pipe(imagemin(options)) .pipe(gulp.dest(paths.distImg)); });
  • 47. Examples Unit Tests @colinodell - joind.in/talk/17992
  • 48. PHPUnit Tests @colinodell - joind.in/talk/17992 var phpunit = require('gulp-phpunit'); gulp.task('phpunit', function () { return gulp.src('phpunit.xml') .pipe(phpunit('./vendor/bin/phpunit', {notify: true})); });
  • 50. Run Shell Commands @colinodell - joind.in/talk/17992 var shell = require('gulp-shell'); gulp.task('deps', shell.task([ 'composer install', 'npm install', 'bower install' ]));
  • 51. Examples Task Groups @colinodell - joind.in/talk/17992
  • 52. Task Groups @colinodell - joind.in/talk/17992 gulp.task('lint', function() { gulp.start('eol', 'phpcs', 'csslint', 'jshint'); }); gulp.task('build', function() { gulp.start('css', 'images', 'js', 'fonts', 'favicons'); }); gulp.task('test', function() { gulp.start('lint', 'phpcs'); }); gulp.task('default', function() { gulp.start('test', 'build'); });
  • 55. Useful Utilities @colinodell - joind.in/talk/17992
  • 56. gulp-changed @colinodell - joind.in/talk/17992 var imagemin = require('gulp-imagemin'); gulp.task('images', function () { var options = { svgoPlugins: [{removeViewBox: false}] }; return gulp.src(paths.img) .pipe(imagemin(options)) .pipe(gulp.dest(paths.distImg)); });
  • 57. gulp-changed @colinodell - joind.in/talk/17992 var changed = require('gulp-changed'); var imagemin = require('gulp-imagemin'); gulp.task('images', function () { var options = { svgoPlugins: [{removeViewBox: false}] }; return gulp.src(paths.img) .pipe(changed(paths.distImg)) .pipe(imagemin(options)) .pipe(gulp.dest(paths.distImg)); });
  • 58. gulp-newer @colinodell - joind.in/talk/17992 var gulp = require('gulp'); var newer = require('gulp-newer'); var concat = require('gulp-concat'); gulp.task('concat', function() { return gulp.src('lib/*.js') .pipe(newer('dist/all.js')) .pipe(concat('all.js')) .pipe(gulp.dest('dist')); });
  • 59. var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); gulp.task('build-js', function() { return gulp.src(paths.js) .pipe(concat('app.js')) .pipe(uglify()) .pipe(gulp.dest(paths.distJs)); }); gulp-sourcemaps @colinodell - joind.in/talk/17992
  • 60. var concat = require('gulp-concat'); var uglify = require('gulp-uglify'); var sourcemaps = require('gulp-sourcemaps'); gulp.task('build-js', function() { return gulp.src(paths.js) .pipe(sourcemaps.init()) .pipe(concat('app.js')) .pipe(uglify()) .pipe(sourcemaps.write()) .pipe(gulp.dest(paths.distJs)); }); gulp-sourcemaps @colinodell - joind.in/talk/17992
  • 61. gulp-load-plugins @colinodell - joind.in/talk/17992 { "devDependencies": { "gulp": "~3.9", "gulp-autoprefixer": "~2.3.1", "gulp-bower": "~0.0.10", "gulp-changed": "~1.2.1", "gulp-csslint": "~0.1.5", "gulp-eol-enforce": "*", "gulp-imagemin": "~2.3.0", "gulp-jshint": "~1.11.2", "gulp-less": "~3.0.3", "gulp-minify-css": "~1.2.0", "gulp-phpcs": "~0.6.0", "gulp-rename": "~1.2.2", "gulp-uglify": "~1.2.0" } } var gulp = require('gulp'), autoprefixer = require('gulp-autoprefixer'), bower = require('gulp-bower'), changed = require('gulp-changed'), csslint = require('gulp-csslint'), eol = require('gulp-eol-enforce'), imagemin = require('gulp-imagemin'), jshint = require('gulp-jshint'), less = require('gulp-less'), minifycss = require('gulp-minify-css'), phpcs = require('gulp-phpcs'), rename = require('gulp-rename'), uglify = require('gulp-uglify');
  • 62. gulp-load-plugins @colinodell - joind.in/talk/17992 { "devDependencies": { "gulp": "~3.9", "gulp-autoprefixer": "~2.3.1", "gulp-bower": "~0.0.10", "gulp-changed": "~1.2.1", "gulp-csslint": "~0.1.5", "gulp-eol-enforce": "*", "gulp-imagemin": "~2.3.0", "gulp-jshint": "~1.11.2", "gulp-less": "~3.0.3", "gulp-minify-css": "~1.2.0", "gulp-phpcs": "~0.6.0", "gulp-rename": "~1.2.2", "gulp-uglify": "~1.2.0" } } var gulp = require('gulp'), plugins = require('gulp-load-plugins')(); // ... .pipe(plugins.changed('app.css')) .pipe(plugins.less()) // ...
  • 63. gulp.watch(paths, tasks) @colinodell - joind.in/talk/17992 gulp.task('watch', function() { gulp.watch(paths.less, ['css']); gulp.watch(paths.img, ['images']); gulp.watch(paths.js, ['js']); gulp.watch(paths.font, ['fonts']); gulp.watch(paths.favicons, ['favicons']); gulp.watch(paths.php, ['phpcs']); });
  • 64. gulp.watch(paths, tasks) @colinodell - joind.in/talk/17992 • Example: https://youtu.be/9d9756j2pq8?t=100
  • 65. Other Plugins & Integrations • Browsersync – Live browser reloads • gulp-notify – Sends notifications to OS notification center or Growl • gulp-autopolyfiller – Like autoprefixer, but for JS polyfills • gulp-git – Run Git commands within Gulp • gulp-ssh – Connect to servers via SSH and SFTP @colinodell - joind.in/talk/17992
  • 66. Summary @colinodell - joind.in/talk/17992 • Task runners help automate build processes • Automate during development, CI, and deployment • Gulp is fast, easy-to-use, and has tons of great plugins

Editor's Notes

  • #5: 2-3 EXAMPLES OF TASKS
  • #22: Vinyl is a very simple metadata object that describes a file. When you think of a file, two attributes come to mind: path and contents. These are the main attributes on a Vinyl object. A file does not necessarily represent something on your computer’s file system. You have files on S3, FTP, Dropbox, Box, CloudThingly.io and other services. Vinyl can be used to describe files from all of these sources. No intermediate writes Non-blocking
  • #60: Similar to gulp-changed, but supports many-to-one mappings
  • #65: FINAL
  • #71: ASK ALEXA!!!