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

Gulp and Grunt

Gulp and Grunt

Big Gulp! Task Automation with Gulp, Node and JavaScript

by John Papa

Are you interested in learning how to automate your testing and build tasks? Let's explore how gulp works on node.js to automate previously manual tasks using JavaScript. You'll learn when and where gulp is appropriate, how it compares to grunt, where gulp adds value, and how it can automate monotonous yet critical workflow.

https://github.com/johnpapa/ng-demos/tree/master/grunt-gulp

John Papa

April 15, 2014
Tweet

More Decks by John Papa

Other Decks in Technology

Transcript

  1. @john_papa   Automate tasks you don’t want to do   Code

     quality     Minifying     Run  tests  
  2. @john_papa   What are gulp and grunt?   Build  automa:on  tools

        Alleviates  cri:cal  but  monotonous  work     Frees  up  your  :me!  
  3. @john_papa   How are they different ?   Code  over  configura:on

        Stream  based     Configura:on  over  code     File  based  
  4. @john_papa   How would you create this workflow?   Get  files

        Modify  them       Make  new  ones  
  5. @john_papa   typical grunt task Modify   File   System

      Temp   Read   Files   Write   Files   Modify   Temp   Read   Files   Write   Files   Modify   Temp   Read   Files   Write   Files  
  6. @john_papa   gulp uses streams Modify   Modify   Modify

      File  System   File  System   Read   Files   Write   Files  
  7. @john_papa   Before you begin   Download  &  install  node.js  

      ◦ hMp://nodejs.org       Install  globally  (run  from  any  path)  
  8. @john_papa   gulp in a nutshell Install  gulp   globally

      1 Create   package   file   2 Install   dependent   packages   3 Code  your   tasks  in   gulpfile.js   4 Load  tasks   into  gulp   5
  9. @john_papa   Install gulp locally to the package -­‐-­‐save-­‐dev  

      is  for  development   -­‐-­‐save     is  for  produc:on  
  10. @john_papa   Installing package dependencies Combine   files  into  1

      Minify   files   Verify   code   quality  
  11. @john_papa   1. gulp.task ( name, [dep], fn)   Registers  a

     task  name  with  a  func:on     Op:onally  declare  dependencies  
  12. @john_papa   2. gulp.src ( glob )   Takes  a  file

     system  glob  (set  of  files)       Emits  files  that  match  
  13. @john_papa   3. gulp.dest ( folder )   Piped  files  are

     wriMen  to  the  file  system  
  14. @john_papa   4. gulp.watch ( glob, fn )   Run  a

     func:on  when  the  glob  changes  
  15. @john_papa   Before you begin   Download  &  install  node.js  

      ◦ hMp://nodejs.org       Install  globally  (run  from  any  path)  
  16. @john_papa   grunt in a nutshell Install  CLI   1

    Create   package   file   2 Install   dependent   packages   3 Configure   tasks  in   grun`ile.js   4 Load  tasks   into  grunt   5 Register   custom   tasks   6
  17. @john_papa   Create package.json file   Prompts  you  for    

    ◦ author   ◦ package  name   ◦ basics  
  18. @john_papa   grunt 101   grunt  wrapper     Task  configura:on  

      Loading  tasks     Register  custom  tasks     Organiza:on  :ps  
  19. @john_papa     Configura:on  over  code     File  based     2400+

     packages     <  2  years  old     Very  widely  used       Code  over  configura:on     Stream  based     400+  packages     <  1  year  old     Rising  rapidly  
  20. @john_papa   Resources   node.js    hMp://nodejs.org     gulp  hMp://gulpjs.com  

        grunt  hMp://gruntjs.com       Sample  code   ◦ hMps://github.com/johnpapa/ng-­‐demos/grunt-­‐gulp