Gulp is a toolkit for automating painful or time-consuming tasks in your development workflow, so you can stop messing around and build something. You can compile sass files, uglify and compress js files and much more.

Installation

Make sure that you’ve installed Node and npm before attempting to install gulp.

Install the gulp command

Make sure that you have your package.json created by manually creating it or typing npm init.

Run this command in your project directory:

Create a gulpfile

In your project directory, create a file named gulpfile.js in your project root with these contents:

The first step to using Gulp is to require it in the gulpfile. Then you can begin to write a gulp task with this gulp variable. task-name refers to the name of the task, which would be used whenever you want to run a task in Gulp. You can also run the same task in the command line by writing gulp task-name.

Run the gulp command in your project directory:

To run multiple tasks, you can use gulp <task> <othertask>

Gulp tasks are usually a bit more complex than this. It usually contains two additional Gulp methods, plus a variety of Gulp plugins.

gulp.src tells the Gulp task what files to use for the task, while gulp.desttells Gulp where to output the files once the task is completed.

Now, let’s run a task to compile the Sass.

In terminal

In Gulpfile.js, we’ll write:

A simple task which can be used to compile Sass and create style.css!

To execute [‘sass’], simply type the following command into your terminal:

Gulp can automatically compile Sass each time we save a Sass file

In your terminal, simply type

Now, anytime you make changes and save any file with a .scss extension, it will trigger this [‘watch’] task which executes [‘sass’].

Gulp is a task runner that uses Node.js as a platform. Gulp purely uses the JavaScript code and helps to run front-end tasks and large-scale web applications. It builds system automated tasks like CSS and HTML minification, concatenating library files, and compiling the SASS files. These tasks can be run using Shell or Bash scripts on the command line.

Reference