⊗tlGpBsTC 2 of 14 menu

Creating Tasks in Gulp

Gulp requires a special file gulpfile.js, placed in the project's root folder. This file contains tasks for Gulp. These tasks are JavaScript functions.

Let's create a test task for warm-up. First, let's create the specified file and connect our library to it:

let gulp = require('gulp');

Let's create a function for our first task and export it:

let gulp = require('gulp'); function task(cb) { console.log('my first task completed!'); cb(); // a special callback, more on that later } exports.default = task;

To run our task, while in the project folder, execute the following command in the command line:

gulp

Create a task that outputs the current time to the console. Run this task via the command line.

Explanation of cb

You've probably noticed that a callback function is passed as a parameter to the task function, and it must be called at the end of the task:

function task(cb) { console.log('my first task'); cb(); // call the callback }

This is done to notify Gulp that the task is completed and it's possible to proceed to the next task.

Don't overthink it - just call the callback at the end. In the next lessons, when our task returns something via return, calling the callback won't be necessary.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline