Your First Task

Create a file in the root folder of your project called gulpfile.js

'use strict';

var gulp = require('gulp');

gulp.task("hello", function() {
  console.log("Hello!");
});

gulp.task("default", ["hello"], function());
  • use strict Causes the node engine to run the file in a strict interpretation of the JavaScript.
  • var gulp = require('gulp'); Assigns the gulp module to a variable. require is a Node method.
    You should always pick variable names that have meaning. Being verbose is often better than writing single or double letter variables.
  • gulp.task(task_name, task_function) Defines a task with gulp’s task method.
  • console.log("Hello!"); Prints “Hello!” in the console.

Running Tasks

gulp hello

 

 

The Default Task

'use strict';

var gulp = require('gulp');

gulp.task("hello", function() {
  console.log("Hello!");
});

gulp.task("default", ["hello"], function());

gulp.task(task_name, task_dependencies, task_function) Define a default task with its depenedencies.

 

Running A Default Task
gulp