A post on the difference between the two, why you may want one over the other, and the advantages or disadvantages of either can be its post.
But for this, I’d like to take the starter packages I wrote about regarding Gulp and give a simple example of a starter Gulp file and how to use it in your WordPress projects.
Getting Started with Gulp
First, I’m a fan of Homebrew, so when it comes to managing packages that are not part of the Mac App Store, I use it. This makes installing packages, updating them, and uninstalling them much easier.
If you’ve not read my guide on Homebrew, please do so as the remainder of this post assumes you have it installed.
1. Install Gulp
If you have Homebrew installed, make sure that everything looks good and is up to date, I have an entire guide for setting up Gulp on your local machine.
So if you don’t already have that setup, check out this post for how to do it.
2. Write Your Gulp Configuration File, Part 1
To initialize a Gulp configuration file, enter the following command in the root directory of your project in your terminal:
Easy, isn’t it?
This will create a blank gulpfile.js in your project’s root directory. Next, it’s time to edit the file.
For this post, I’m going to be using four packages that I’ve previously outlined:
Tasks that you want to run from the command line should not have spaces in them.
To set up the basic tasks so that you can run them from the command-line, you’ll need to do the following:
Running Them Individually
But this gets old fast. Further, it’s less efficient especially when you can set up a watch to automatically run your tasks whenever you save a file.
2. Write Your Gulp Configuration File, Part 2
Setting up a watch is probably the best thing you can do when it comes to saving time with Gulp.
Watch files and do something when a file changes. This always returns an EventEmitter that emits
Then just run the task:
A Note About Versions
In earlier versions of Gulp, the second argument for the watch function would accept an array; however, the latest version requires an actual function (which you can see above in that I’ve declared series).
The short of it is that Gulp 4 allows for sequential execution, which is done via series, and parallel execution (which can use the parallel function). Those are beyond the scope of this post as this is purely meant to help get you started.
Once done, you should have a lot more automation in your build process.