Book Image

Getting Started with Gulp

By : Travis Maynard
Book Image

Getting Started with Gulp

By: Travis Maynard

Overview of this book

<p>Gulp is a fast and powerful JavaScript task runner that is built upon the node.js platform. It allows you to create tasks that can automate common workflow processes. Gulp.js is comparatively new and has been developed keeping in mind the issues that developers have encountered with Grunt.</p> <p>Getting Started with Gulp introduces you to the world of building and testing JavaScript applications using gulp. This book is a hands-on guide to get you up to speed with gulp. It will instill you with the ability to automate several common development tasks to vastly improve your development workflow. It will get you started with gulp quickly and efficiently, providing you with core concepts of gulp, node.js, and npm.</p> <p>By the end of this book, you will be able to create your very own gulp environments from scratch, create and maintain tasks and project builds, and automate your workflow with plugins and custom tasks.</p>
Table of Contents (14 chapters)

The watch task


So far, all of the tasks that we have written are actually only capable of running once. Once they complete, their job is considered done. However, this isn't very helpful as we would end up having to go back to our command line to run them again every time we make a change to our files. This is where gulp's .watch method comes into play. The watch method's job is to specifically look for changes to files and then respond by running tasks in relation to those changes. Since we will be focusing on CSS, JavaScript, and images independently, we will need to specify three separate watch methods as well. To better organize these watch methods, we will create an additional watch task that will serve as a reference and an easy way to organize them within our gulpfile.

Writing the watch task

Since the watch method is built into gulp as a core feature, no new plugins are needed. So we can move straight to actually writing the task itself. Additionally, we will not use the .src or .dest...