Learn Gulp. Jonathan Birkholz. This book is for sale at This version was published on

Similar documents
Git Workbook. Self-Study Guide to Git. Lorna Mitchell. This book is for sale at

Modern Online Radio with Liquidsoap

The Laravel Survival Guide

We are assuming you have node installed!

Webpack. What is Webpack? APPENDIX A. n n n

Kotlin for Android Developers

Grunt Cookbook. Effective Recipes To Master Grunt. Matt Goldspink. This book is for sale at

Automate with Grunt. Extracted from: The Build Tool for JavaScript. The Pragmatic Bookshelf

Kotlin for Android Developers

Leaflet Tips and Tricks

Programming for Kids

DrupalCon Barcelona Preston So September 22, 2015

Functional Reactive Programming on ios

The Little Mongo DB Schema Design Book

Introduction to Using NPM scripts as a Build Tool. 1. 1

This tutorial has been prepared for beginners to help them understand the basic functionalities of Gulp.

Tools. SWE 432, Fall Design and Implementation of Software for the Web

JavaScript Web Tools with Visual Studio 2015 and ASP.NET 5. April 2015.

Getting started with Tabris.js Tutorial Ebook

MOdern Java(Script) Server Stack

Laravel: From Apprentice To Artisan

Vue.js Developer friendly, Fast and Versatile

Create-A-Page Design Documentation

A Primer on Design Patterns

Web Development for Dinosaurs An Introduction to Modern Web Development

Your First Meteor Application

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

How APEXBlogs was built

Building Mapping Apps for ios With Swift

Chapter 1 - Development Setup of Angular

Installing VS Code. Instructions for the Window OS.

Webpack 2 The last bundler you would need in Vijay Dharap, Principal Architect, Infosys

JQuery and Javascript

Python For Hackers. Shantnu Tiwari. This book is for sale at This version was published on

Firefox for Nokia N900 Reviewer s Guide

Teach Yourself Enterprise Architect in Ten Days

Exercise 1 Using Boolean variables, incorporating JavaScript code into your HTML webpage and using the document object

AngularJS Cookbook. 70 Recipes for AngularJS 1.2. Sascha Brink. This book is for sale at

welcome to BOILERCAMP HOW TO WEB DEV

Designing with OpenSCAD

Lab 6: Testing. Software Studio DataLab, CS, NTHU

Which is why we ll now be learning how to write in CSS (or cascading sheet style)

Programming for Beginners

EssEntial indesign skills Brought to you By InDesign

Want the *GUIDED* tour?

In this project, you ll learn how to create your own webpage to tell a story, joke or poem. Think about the story you want to tell.

Build Powerful FrontEnd Workflows with PostCSS. Guide to writing/generating cutting edge CSS

Taking Fireworks Template and Applying it to Dreamweaver

HTML/CSS Lesson Plans

SHELL SCRIPTING: HOW TO AUTOMATE COMMAND LINE TASKS USING BASH SCRIPTING AND SHELL PROGRAMMING BY JASON CANNON

Quick Desktop Application Development Using Electron

Kindle Formatting Guide

Beginning Mobile App Development with React Native

How to Make a Book Interior File

Table of contents. DMXzone Font Awesome DMXzone

Procedure for Creating a Standalone Player With Virtools Dev 3.5/4 & VC++ 7 (.NET 2003)

React. HTML code is made up of tags. In the example below, <head> is an opening tag and </head> is the matching closing tag.

Scope Monthly. Guide to updating and maintaining the Scope Monthly Website. Last Updated: Table of Contents

GMAIL BEGINNERS GUIDE

Let's see a couple of examples

Node.js By Example. Learn to use Node.js by creating a fully functional social network. Krasimir Tsonev BIRMINGHAM - MUMBAI

Functional Programming in Ruby

In this extension to Build and Publish a website we will look at additional/optional features available in Wordpress, and some more Plug-ins.

INTRODUCTION TO IONIC 2

Overview of BC Learning Network SMS2 Introduction

DESIGNING RESPONSIVE DASHBOARDS. Best Practices for Building Responsive Analytic Applications

Enhance InfoPath form with Validation, Formatting and Lookups

Index. Elad Elrom 2016 E. Elrom, Pro MEAN Stack Development, DOI /

Sona Systems Guide Adding Time Slots

DOWNLOAD PDF EXCEL MACRO TO PRINT WORKSHEET TO

roots Documentation Release jeff escalante

SEEM4570 System Design and Implementation. Lecture 4 AJAX and Demo

Laravel and AngularJS

Beginning Mac Programming

Customizing DAZ Studio

ThingLink User Guide. Andy Chen Eric Ouyang Giovanni Tenorio Ashton Yon

Where Did My Files Go? How to find your files using Windows 10

5. Finally, create a new Javascript file called speak.js. Leave it blank for now.

RC Justified Gallery User guide for version 3.2.X. Last modified: 06/09/2016

Getting Started With NodeJS Feature Flags

Serverless Microservices Are The New Black. Lorna Mitchell, IBM

Tips and Ticks

ValuePRO Tutorial Internet Explorer 8 Configuration

We aren t getting enough orders on our Web site, storms the CEO.

Part 3: Images & form styling NOMZAMO S WEBSITE

iperceptions Comment Card Methodology

Bluehost and WordPress

Theme System. Wisej Themes 1 OVERVIEW

Last modification of document: by Tomasz Dobrzyński

Documentation And Collaborating With Developers

What s New in. Word Presented by Janet Porter

(Refer Slide Time: 01:12)

Web Application Development

Getting Started with ReactJS

TekTalk Word 2007 Notes

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Docker for Developers

LEARN WITH INTRODUCTION TO TYPESCRIPT

Node.js. Node.js Overview. CS144: Web Applications

5th April Installation Manual. Department of Computing and Networking Software Development Degree

Transcription:

Learn Gulp Jonathan Birkholz This book is for sale at http://leanpub.com/learngulp This version was published on 2015-09-02 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. 2015 Jonathan Birkholz

Contents 1. Gulp Series Introduction............................... 1 2. Hello Gulp........................................ 2 3. Moving Files with Gulp................................ 4 4. Concat: Combining multiple files into one with Gulp............. 6

1. Gulp Series Introduction Gulp has been a real treat to work with and I wanted to share the ease of which you can use it to quickly create an awesome build. We are going to be using gulp to build a static content generation site like Jeykll. Obviously it will not be super feature rich, but the basics will be mapped out. By the end we will have a build script that will run on file change, the content for the pages will be converted from markdown files, and we will have a preview web server that will live reload with these changes. 1

2. Hello Gulp Let s start a new node project in our folder and add a package.json. $ npm init // /package.json { "name": "learning_gulp", "version": "0.0.0", "description": "A sample project to learn how Gulp works", "main": "index.js", "author": "YOUR_NAME_HERE", "license": "ISC" } Time to install gulp using npm. First globally to access the gulp command and then locally for our package.json. $ npm install gulp -g $ npm install gulp --save-dev By default gulp looks for a gulpfile.js to run. Let s create a simple gulpfile.js. // /gulpfile.js var gulp = require('gulp'); gulp.task('default', [], function() { }); console.log("hello Gulp! You are mighty fine."); In your terminal run the gulp command. $ gulp You should see: 2

Hello Gulp 3 Using gulpfile ~/YOUR_DIRECTORY/gulpfile.js Starting 'default'... Hello Gulp! You are mighty fine. Finished 'default' after 118 μs Congratulations creating your first gulp build script!

3. Moving Files with Gulp The first thing we will learn to do with gulp is to move files. /* /contents/ */ h1 { color: red; } /* /contents/ */ p { font-size: 30px; } Our project structure should now look like: /node_modules /contents gulpfile.js package.json Update our gulpfile.js from the previous section and instruct gulp to move all the files found in the styles folder to our build folder. // /gulpfile.js var gulp = require('gulp'); gulp.task('default', [], function() { console.log("moving all files in styles folder"); gulp.src("contents/**.*").pipe(gulp.dest('build')); }); If we review the code, we can see two main gulp operations. 4

Moving Files with Gulp 5 1. gulp.src tells gulp what files to work on with this task. 2. gulp.dest tells gulp where to drop off files after this task is finished working on them. What do we expect will happen when we run gulp? If you guessed the files will be copied and moved to the build folder, then give yourself a cookie. When we run gulp, we should see: $ gulp Using gulpfile ~/YOUR_DIRECTORY/gulpfile.js Starting 'default'... Moving all files in styles folder Finished 'default' after 5.25 ms Our project should now look like: /build /node_modules /contents gulpfile.js package.json Unimpressed? That just means you totally understand everything and are ready to move on with our great gulp adventure.

4. Concat: Combining multiple files into one with Gulp Printing Hello and moving files is rather boring. Let s do something productive. When we create websites, we are always trying to deliver the best experience possible. This includes having our webpages displaying fast. Back in the day, this meant having all our styles in one css file. While this made our webpages load faster, it made maintaining the css file a nightmare! These days we can use multiple css files for better organization and then concat (meaning merge or combine) the files together into one large file. We left our project looking like: /build /node_modules /contents gulpfile.js package.json Right now, we have two separate css files in our build folder. We are going to use a gulp plugin to concat all our css files in the styles folder. Gulp contains some basic tasks, but the power of gulp is the customization you can bring into your build process by using plugins. For a list of all the gulp plugins available, go to http://gulpjs.com/plugins/ To concat the files together, we will need to install one of these plugins. 6

Concat: Combining multiple files into one with Gulp 7 $ npm install gulp-concat --save-dev For more information on the gulp-concat plugin, visit https://www.npmjs.org/package/gulpconcat/. We can then update our default gulp task to concat the files. // gulpfile.js var gulp = require('gulp'); var concat = require('gulp-concat'); gulp.task('default', [], function() { console.log("concating and moving all the css files in styles folder"); gulp.src("contents/**.css").pipe(concat('main.css')).pipe(gulp.dest('build')); }); Couple of things have changed, can you spot them? First, we had to reference the gulp plugin with: var concat = require('gulp-concat'); We chose to label this concat. Obviously we could call it anything we want, but concat communicates what the plugin does to those reading our build script. Second, we added another step to our task. In between the src and the pipe(gulp.dest...) steps, we added pipe(concat(...)). Gulp works by streaming files from one process to another. This allows us to create complex build tasks out of small, simple steps. Composition == winning. Now run our gulp task: $ gulp Using gulpfile ~/YOUR_DIRECTORY/gulpfile.js Starting 'default'... Moving all the css files in styles folder Finished 'default' after 6.09 ms Our task will read all the css files in the styles folder, combine them into one main.css file, and then place that file in the build folder. Our project should now look like:

Concat: Combining multiple files into one with Gulp 8 /build main.css /node_modules gulpfile.js package.json Notice the and files are still in our build folder. :( We don t want those chumps there anymore. In the next chapter we will learn how to get rid of those files.