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:
- var gulp = require (' gulp '); Gulp itself
- Gulp.task (' default ', [' Task1 ',' Task2 '], function () {
- //Put your default task code in this
- Console.log ("Default");
- });
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:
- var gulp = require (' gulp '); Gulp itself
- Gulp.task (' task1 ',function () {
- Console.log ("Task1");
- });
- Gulp.task (' task2 ',function () {
- Console.log ("Task2");
- })
- Gulp.task (' default ', function () {
- Put your default task code in this
- Console.log ("Default");
- });
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:
- var gulp = require (' gulp '); Gulp itself
- Gulp.task (' task1 ',function () {
- Console.log ("Task1");
- });
- Gulp.task (' task2 ',function () {
- Console.log ("Task2");
- })
- Gulp.task (' default ', [' Task1 ',' Task2 '], function () {
- Console.log ("Default");
- });
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