Gulp Pit Series (3)--Create multiple Gulp.task

Source: Internet
Author: User

To continue the gulp, before you get more gulp, make a clear case of creating and using multiple task tasks in gulp.

Gulp the action to be done is written in Gulp.task (), the system has a default task, as follows:

    1. var gulp = require (' gulp '); Gulp itself
    2. Gulp.task (' default ', [' Task1 ',' Task2 '], function () {
    3. //Put your default task code in this
    4. Console.log ("Default");
    5. });

Executing the gulp instruction in the root directory of the project in the command line, you will see that the default task is executed and the console outputs "default".

So if we create multiple gulp.task, like this:

 
  1. var gulp = require (' gulp '); Gulp itself
  2. Gulp.task (' task1 ',function () {
  3. Console.log ("Task1");
  4. });
  5. Gulp.task (' task2 ',function () {
  6. Console.log ("Task2");
  7. })
  8. Gulp.task (' default ', function () {
  9. Put your default task code in this
  10. Console.log ("Default");
  11. });

Before continuing with the gulp instructions, you will find the following results:

Obviously, after the addition of Task1 and Task2 did not execute, so that the Gulpfile.js only support a task Baa?

Well, actually this is an extra worry, our code is just one step less

Because in fact in Gulpfile.js, all of the operation's entry is the task called ' Default ', so just add our own other task to the default, and the modified code is as follows:

 
  1. var gulp = require (' gulp '); Gulp itself
  2. Gulp.task (' task1 ',function () {
  3. Console.log ("Task1");
  4. });
  5. Gulp.task (' task2 ',function () {
  6. Console.log ("Task2");
  7. })
  8. Gulp.task (' default ', [' Task1 ',' Task2 '], function () {
  9. Console.log ("Default");
  10. });


Then let's run the Gulp command again:

It seems to be a success, and here you can see the order in which these tasks are executed, first executing the task introduced in default, and finally executing the operation in the default's own method.

Gulp Pit Series (3)--Create multiple Gulp.task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.