Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FOWA: Development with GulpJS

Jack Franklin
September 30, 2014

FOWA: Development with GulpJS

Jack Franklin

September 30, 2014
Tweet

More Decks by Jack Franklin

Other Decks in Technology

Transcript

  1. We do a lot of things over and over again

    in a day to day workflow
  2. Streams in Node are one of the rare occasions when

    doing something the fast way is actually easier. SO USE THEM. Not since bash has streaming been introduced into a high level language as nicely as it is in node." ! -@dominictarr https://gist.github.com/dominictarr/2401787
  3. var gulp = require(‘gulp’); var uglify = require(‘gulp-uglify’); ! gulp.task(‘minify’,

    function() { gulp.src(‘app.js’) .pipe(uglify()) .pipe(gulp.dest(‘out’)); }); Gulpfile.js
  4. var gulp = require(‘gulp’); var uglify = require(‘gulp-uglify’); ! gulp.task(‘minify’,

    function() { gulp.src(‘app.js’) .pipe(uglify()) .pipe(gulp.dest(‘out’)); }); Gulpfile.js
  5. var gulp = require(‘gulp’); var uglify = require(‘gulp-uglify’); ! gulp.task(‘minify’,

    function() { gulp.src(‘app.js’) .pipe(uglify()) .pipe(gulp.dest(‘out’)); }); Gulpfile.js
  6. var gulp = require(‘gulp’); var uglify = require(‘gulp-uglify’); ! gulp.task(‘minify’,

    function() { gulp.src(‘app.js’) .pipe(uglify()) .pipe(gulp.dest(‘out’)); }); Gulpfile.js
  7. var gulp = require(‘gulp’); var uglify = require(‘gulp-uglify’); ! gulp.task(‘minify’,

    function() { gulp.src(‘app.js’) .pipe(uglify()) .pipe(gulp.dest(‘out’)); }); Gulpfile.js
  8. var gulp = require(‘gulp’); var concat = require(‘gulp-concat’); var uglify

    = require(‘gulp-uglify’); ! gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(concat(‘app.js’)) .pipe(uglify()) .pipe(gulp.dest(‘’))
 });
  9. var gulp = require(‘gulp’); var concat = require(‘gulp-concat’); var uglify

    = require(‘gulp-uglify’); ! gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(concat(‘app.js’)) .pipe(uglify()) .pipe(gulp.dest(‘’))
 });
  10. var gulp = require(‘gulp’); var concat = require(‘gulp-concat’); var uglify

    = require(‘gulp-uglify’); ! gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(concat(‘app.js’)) .pipe(uglify()) .pipe(gulp.dest(‘’))
 });
  11. var gulp = require(‘gulp’); var concat = require(‘gulp-concat’); var uglify

    = require(‘gulp-uglify’); ! gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(concat(‘app.js’)) .pipe(uglify()) .pipe(gulp.dest(‘’))
 });
  12. var gulp = require(‘gulp’); var concat = require(‘gulp-concat’); var uglify

    = require(‘gulp-uglify’); ! gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(concat(‘app.js’)) .pipe(uglify()) .pipe(gulp.dest(‘’))
 });
  13. “By default, tasks run with maximum concurrency -- e.g. it

    launches all the tasks at once and waits for nothing” https://github.com/gulpjs/gulp/blob/master/docs/recipes/running-tasks-in-series.md
  14. gulp.task(‘one’, function(cb) { // do stuff cb(null);
 }); ! gulp.task(‘two’,

    function() { return gulp.src(‘…’).pipe(…)
 });
  15. gulp.task(‘one’, function(cb) { // do stuff cb(null);
 }); ! gulp.task(‘two’,

    function() { return gulp.src(‘…’).pipe(…)
 });
  16. gulp.task(‘one’, function(cb) { // do stuff cb(null);
 }); ! gulp.task(‘two’,

    function() { return gulp.src(‘…’).pipe(…);
 });
  17. gulp.task(‘one’, function(cb) {…}); ! gulp.task(‘two’, function() { return gulp.src(‘…’).pipe(…)
 });

    ! gulp.task(‘three’, [‘two’], function() { // task two is done now
 });
  18. gulp.task(‘one’, function(cb) {…}); ! gulp.task(‘two’, function() { return gulp.src(‘…’).pipe(…)
 });

    ! gulp.task(‘three’, [‘one’, ’two’], function() { // task two is done now
 });
  19. var minify = function(files) { return gulp.src(files) .pipe(concat(‘combined.js’)) .pipe(uglify());
 };

    ! gulp.task(‘js’, function() { minify(‘*.js’) .pipe(gulp.dest(‘dist’));
 }); ! gulp.task(‘other’, function() { minify(‘templates/*.js’) .pipe(gulp.dest(‘templates’)); 
 });
  20. var minify = function(files) { return gulp.src(files) .pipe(concat(‘combined.js’)) .pipe(uglify());
 };

    ! gulp.task(‘js’, function() { minify(‘*.js’) .pipe(gulp.dest(‘dist’));
 }); ! gulp.task(‘other’, function() { minify(‘templates/*.js’) .pipe(gulp.dest(‘templates’)); 
 });
  21. var minify = function(files) { return gulp.src(files) .pipe(concat(‘combined.js’)) .pipe(uglify());
 };

    ! gulp.task(‘js’, function() { minify(‘*.js’) .pipe(gulp.dest(‘dist’));
 }); ! gulp.task(‘other’, function() { minify(‘templates/*.js’) .pipe(gulp.dest(‘templates’)); 
 });
  22. var uglify = require(‘gulp-uglif var jshint = require(‘gulp-jshin var concat

    = require(‘gulp-conca var uglify = require(‘gulp-uglif var jshint = require(‘gulp-jshin var concat = require(‘gulp-conca var uglify = require(‘gulp-uglif var jshint = require(‘gulp-jshin var concat = require(‘gulp-conca var uglify = require(‘gulp-uglif var jshint = require(‘gulp-jshin
  23. var gulp = require(‘gulp’), plugins = require(‘gulp-load-plugins’)(); { “dependencies”: {

    “gulp-jshint”: “*”, “gulp-concat”: “*” } } package.json
  24. var gulp = require(‘gulp’); var plugins = require(‘gulp-load- plugins’)(); !

    gulp.task(‘min’, function() { gulp.src(‘…’) .pipe(plugins.concat(‘app.js’)) .pipe(plugins.uglify()) .pipe(gulp.dest(‘’))
 });
  25. 1. Task dependencies ! 2. API cleaned up ! 3.

    Error handling https://medium.com/@contrahacks/gulp-3828e8126466
  26. if you can think of it, there’s probably a plugin

    for it (779) http://gulpjs.com/plugins/