Featured image for How to Use Gulp

// Coding

How to Use Gulp

Subscribe to our newsletter
Featured image for How to Use Gulp

Each developer is forced to do routine and monotonous tasks in web development profession, especially the HTML-coder. But what if some of these tasks can be automated? In this case the task manager will help. One of the most popular is Gulp.

The simplest definition says that Gulp is a task manager/stream collector of projects, which is developed in the JavaScript programming language. It can help automate different tasks, while significantly saving time.

How to use Gulp

How to use Gulp in your project and what exactly is to be automated? We will try to check and consider in this article. Following simple instructions from the documentation, first of all, we see that Gulp works with Node.js. So, need to install it on the computer. Next step is the installation of the module, which can help to use Gulp in any place on your PC. To do this, execute the following code on the command line:
npm i gulp –g

After that, you need to install and add it to your project, after changing the directory, to the required one and use the following command:
npm i gulp --save-dev

How to Use Gulp

We understood how to install. But if there are questions, then for more clear instructions there is always official documentation. Let's move on to the setup stage. For example, we will use two directories: merehead/first-catalog and merehead/secondary-catalog.

In the merehead/first-catalog directory will be the source files, and in the merehead/secondary-catalog directory - files after processing by Gulp.
The basic syntax of any task can be represented in the following code:
gulp.task(‘example’, function() {

But for some practice we need to use a real Gulp-plugin. In one of the previous articles, I talked about the advantages of CSS preprocessors. We can use Gulp to convert SASS to CSS. At first, we need to install the plugin that can solve this issue. The following code can do installation:
npm install yourPlaginNameHere --save-dev

Next, we will create a configuration file for the task manager, which we will call gulpfile.js and add the following lines:
var yourPlaginNameHere= require('yourPlaginNameHere'); //Connection of a plugin.

And we will create our first task, which includes plugins SASS, autoprefixer, css-min и rename.
gulp.task('yourPlaginNameHere', function () {
.pipe(rename({suffix: '.min'}))

Thus, Gulp helps us, process our files and did the following:
1) It checked all styles files with the extension .scss
2) It converted Sass to CSS
3) It put all the necessary vendor prefixes in CSS
4) It minimized CSS
5) It renamed the files and added the suffix "min"
6) It put the processed files in a folder secondary-catalog/app-css

Thus, we have 6 items, which at least one of them was performed manually. A note, this is just an example of one small task. This short syntax and the flexibility of Gulp makes it a powerful tool. So, every developer can save a lot of time.

We gradually saw what tasks help automate Gulp. The example above describes the process of minimizing CSS, using preprocessors, and prefixing. In addition, the list of skills of this task-manager includes:
- Optimizing images
- Using HTML templates, such as Jade
- Code testing and validation
- Minimize and combine JavaScript.

Benefits of Gulp

There are also many other useful plugins. For example, gulp-connect allows you to create and run a local server with livereload support. With this plugin, you can see the changes in the browser after you have updated your sass, HTML or JS file without a lot of clicks on the "update" button.

Another feature of Gulp is that in addition to automating the development process by creating various tasks, it can automate the process of working these same tasks! After all, if you check an example of our tasks above, then to run it you should run the command every time:
gulp sass

Here, Watch method will help us, which monitors the status of the files and run specific tasks, again and again, depending on whether there are changes in those or other files. Let's imagine a code example where this method is used in the following sentence:

gulp.task('myWatcher', ['yourTaskNameHere'], function() {
gulp.watch ('./merehead/first-catalog/app-style/*.scss', ['yourTaskNameHere']);
gulp.task('default', ['myWatcher']);

Now, if we execute the Gulp command in the project, the Watch task is run, which will monitor your files and update them during the running session.

At the beginning of the article, I said that Gulp is also a project collector. But, in the role of an assembler, it is convenient to use it only on a small project. When your project uses React, Redux and many different libraries, it's much more convenient to use Webpack. In our company we work on the following way: at the stage of coding of mockups or on small projects I use Gulp, and for full-fledged web applications, other developers of our company use Webpack.


In conclusion, I want to say that for my purposes Gulp is the ideal solution. I think that for yours too. I recommend using this task manager. It will help automate routine tasks, save time and effort. This allows you to perform tasks more efficiently and quickly. So install Gulp, get acquainted with a lot of useful plugins and create personal tasks, depending on your needs.

Merehead does professional development of how to use gulp. If you have questions, contact us for a free consultation.

How can we help you?

Full name *
Email *
Your budget
Tell us about your project
Merehead review. Vleppo is a startup, digital asset exchange platform based on the Komodo blockchain protocol.

  Category: Coding 11/17/2021
Optimal Website Load Time
Page loading time obviously is an important part of any website’s user experience. And many times we’ll let it slide to accommodate better aesthetic design, new nifty functionality or add more content to web pages.
  Category: Coding 11/17/2021
What is Proof of Concept (POC) in Software Development
Some companies, but more often startups, face the problem of false values. Basically, this problem occurs when the original idea was scantily considered. In this case, the project is already moving at the beginning of the development along the wrong path. If you started development with a small MVP and failed, it's not so sad. Much worse, if you spent several tens of thousands of dollars, several months, and a startup was a failure even though if it was a crypto exchange software. This is very sad, although it happens quite often in the startup industry.
  Category: Coding 11/17/2021
How to Use Jira for Project Management
Jira is one of the most universal project management tools in the areas of finance, software development, marketing, HR management. This service is great for both small teams and corporate use.