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

Introduction to Gulp.js tool

Introduction to Gulp.js tool

Automating your workflow with Gulp.js

Bo-Yi Wu

July 20, 2014
Tweet

More Decks by Bo-Yi Wu

Other Decks in Technology

Transcript

  1. 6 Setup Download Server Setup PHP Ruby Develop Watch Live

    Reload Lint Coffee Sass/Less Work Flow
  2. 7 Setup Download Server Setup PHP Ruby Develop Watch Live

    Reload Lint Coffee Sass/Less Build Testing Compile Concat Rename Minify Image-min Deployment Work Flow
  3. 9 Tasks Tasks Html / Jade JavaScript / CoffeeScript /

    LiveScript – JSHint CSS / Sass / Compass / Stylus Testing – Mocha Deploy – Minify – Rename – Replace
  4. 16

  5. 21 Typical grunt task Typical grunt task File System Read

    Files Modify Write Files Temp Read Files Modify Write Files Temp File System
  6. 22 Gulp Gulp uses streams File System Read Files Modify

    Modify Write Files Modify Modify File System
  7. 24 Easy to use Easy to use By preferring code

    over configuration, gulp keeps simple things simple and makes complex tasks manageable.
  8. 25 Easy to use Easy to use var gulp =

    require('gulp‘), coffee = require(‘gulp-coffee’);
  9. 26 Easy to use Easy to use var gulp =

    require('gulp‘), coffee = require(‘gulp-coffee’); gulp.task('coffee', function() { //ready to go });
  10. 27 Easy to use Easy to use var gulp =

    require('gulp‘), coffee = require(‘gulp-coffee’); gulp.task('coffee', function() { gulp.src(‘assets/coffee/**/*.coffee’) .pipe(coffee()) .pipe(gulp.dest(‘assets/js/’)); });
  11. 30 Efficient Efficient By harnessing the power of node's streams

    you get fast builds that don't write intermediary files to disk.
  12. 32 Efficient var gulp = require('gulp‘), coffee = require(‘gulp-coffee’); gulp.task('coffee',

    function() { gulp.src(‘assets/coffee/main.coffee’) .pipe(coffee()) .pipe(uglify()) .pipe(rename(‘assets/js/main.min.js’)) .pipe(gulp.dest(‘dist/assets/js/’)); }); Read file
  13. 33 Efficient var gulp = require('gulp‘), coffee = require(‘gulp-coffee’); gulp.task('coffee',

    function() { gulp.src(‘assets/coffee/main.coffee’) .pipe(coffee()) .pipe(uglify()) .pipe(rename(‘assets/js/main.min.js’)) .pipe(gulp.dest(‘dist/assets/js/’)); }); Process in Memory Process in Memory Process in Memory
  14. 34 Efficient var gulp = require('gulp‘), coffee = require(‘gulp-coffee’); gulp.task('coffee',

    function() { gulp.src(‘assets/coffee/main.coffee’) .pipe(coffee()) .pipe(uglify()) .pipe(rename(‘assets/js/main.min.js’)) .pipe(gulp.dest(‘dist/assets/js/’)); }); Write file
  15. 36 High Quality High Quality gulp's strict plugin guidelines assure

    plugins stay simple and work the way you expect.
  16. 37 Gulp plugins Gulp plugins more than 600+ plugins more

    than 600+ plugins http://gulpjs.com/plugins/ http://gulpjs.com/plugins/
  17. 38 Gulp plugin gulp-coffee / gulp-livescript gulp-ruby-sass / gulp-compass gulp-imagemin

    gulp-rename gulp-minify-css gulp-htmlmin gulp-mocha gulp-replace gulp-livereload
  18. 39 gulp black list gulp-browserify gulp-requirejs gulp-shell gulp-connect gulp-twitter gulp-if-else

    https://github.com/gulpjs/plugins/blob/master/src/blackList.json
  19. 40 Easy to Learn Easy to Learn With a minimal

    API surface, you can pick up gulp in no time. Your build works just like you envision it: a series of streaming pipes.
  20. 41 Only 4 functions you need to learn Only 4

    functions you need to learn
  21. 44 gulp.task(name[, deps], fn) gulp.task(name[, deps], fn) gulp.task(‘hello', function() {

    console.log('Hello world!'); }); gulp.task('css', ['greet'], function () { // Deal with CSS here }); gulp.task('build', ['css', 'js', 'imgs']); gulp.task('default', function () { // Your default task });
  22. 48 Write your first Gulp Task Write your first Gulp

    Task gulpfile.[js|coffee|ls] Support CoffeeScript or LiveScript from Gulp > 3.7.0 Thanks @tkellen https://github.com/tkellen/node-liftoff
  23. 49 var gulp = require('gulp'), jshint = require('gulp-jshint'), uglify =

    require('gulp-uglify'), concat = require('gulp-concat'); gulp.task('js', function () { return gulp.src('js/*.js') .pipe(jshint()) .pipe(jshint.reporter('default')) .pipe(uglify()) .pipe(concat('app.js')) .pipe(gulp.dest('build')); });
  24. 52 gutil = require 'gulp-util' coffee = require 'gulp-coffee' coffeelint

    = require 'gulp-coffeelint' compass = require 'gulp-compass' w3cjs = require 'gulp-w3cjs' imagemin = require 'gulp-imagemin' cache = require 'gulp-cache' changed = require 'gulp-changed' connect = require 'gulp-connect' size = require 'gulp-size' gulpif = require 'gulp-if' rename = require 'gulp-rename' uglify = require 'gulp-uglify' minifyCSS = require 'gulp-minify-css' htmlmin = require 'gulp-htmlmin' replace = require 'gulp-replace' mocha = require 'gulp-mocha'
  25. 54 var gulp = require('gulp'), $ = require('gulp-load-plugins')(); gulp.task('js', function

    () { return gulp.src('js/*.js') .pipe($.jshint()) .pipe($.jshint.reporter('default')) .pipe($.uglify()) .pipe($.concat('app.js')) .pipe(gulp.dest('build')); });
  26. 60 var gulp = require('gulp'); gulp.task('one', function(cb) { // do

    stuff -- async or otherwise cb(err); }); gulp.task('two', ['one'], function() { // task 'one' is done now }); gulp.task('default', ['one', 'two']);
  27. 61 Using run-sequence Using run-sequence Run a series of dependent

    gulp tasks in order https://github.com/OverZealous/run-sequence
  28. 63 Reloading Changes In The Browser Reloading Changes In The

    Browser gulp-livereload https://github.com/vohof/gulp-livereload
  29. 64 var gulp = require('gulp'), sass = require('gulp-sass'), livereload =

    require('gulp-livereload'), watch = require('gulp-watch'); gulp.task(‘sass', function() { gulp.src(‘sass/*.scss') .pipe(watch()) .pipe(sass()) .pipe(gulp.dest('css')) .pipe(livereload()); });
  30. 65 gulp-webserver gulp-webserver Streaming gulp plugin to run a local

    webserver with LiveReload https://github.com/schickling/gulp-webserver
  31. 68 var browserSync = require('browser-sync'), reload = browserSync.reload; // Watch

    Files For Changes & Reload gulp.task('serve', function () { browserSync({ server: { baseDir: 'app' } }); gulp.watch(['*.html'], reload); });
  32. 70 var gulp = require('gulp'), $ = require('gulp-load-plugins')(); gulp.task('bootstrap', function()

    { return gulp.src('bootstrap/js/*.js') .pipe($.jshint()) .pipe($.jshint.reporter(stylish)) .pipe($.uglify()) .pipe(gulp.dest('public/bootstrap')); }); gulp.task('coffee', function() { return gulp.src('lib/js/*.coffee') .pipe($.coffee()) .pipe($.jshint()) .pipe($.jshint.reporter(stylish)) .pipe($.uglify()) .pipe(gulp.dest('public/js')); });
  33. 72 var gulp = require('gulp'), $ = require('gulp-load-plugins')(), lazypipe =

    require('lazypipe'); // give lazypipe var jsTransform = lazypipe() .pipe($.jshint) .pipe($.jshint.reporter, stylish) .pipe($.uglify); gulp.task('bootstrap', function() { return gulp.src('bootstrap/js/*.js') .pipe(jsTransform()) .pipe(gulp.dest('public/bootstrap')); }); gulp.task('coffee', function() { return gulp.src('lib/js/*.coffee') .pipe($.coffee()) .pipe(jsTransform()) .pipe(gulp.dest('public/js')); });
  34. 74 Deploy Process Deploy Process CoffeeScript / LiveScript Compass /

    Sass Jade Image-min RequireJS Rename Replace Copy
  35. 76 Why not use Makefile? Why not use Makefile? Using

    Gulp.js tool only for development
  36. 80

  37. 83 Features Features • The latest html5boilerplate.com source code. •

    Includes Normalize.scss v3.0.x and v1.1.x. • The latest jQuery and Modernizr via Bower package manager. • Support CoffeeScript, RequireJS, Sass or Compass, html minification (via htmlcompressor). • Support JavaScript test framework Mocha. • Support streaming build system Gulp. • Support Minify PNG and JPEG images with image-min. • Support browser-sync Keep multiple browsers & devices in sync when building websites.
  38. 84 How to install? How to install? $ npm install

    -g slush $ npm install -g slush-html5-template
  39. 85 Scaffold your first project Scaffold your first project $

    mkdir app $ cd app && slush html5-template $ npm start
  40. 86

  41. 88 Orchestrator Orchestrator A module for sequencing and executing tasks

    and dependencies in maximum concurrency https://github.com/orchestrator/orchestrator
  42. 91

  43. 92