How to use the series function from gulp

Find comprehensive JavaScript gulp.series code examples handpicked from public code repositorys.

Gulp.series is a function that creates a series of tasks to be run in a specific order in Gulp.js.

86
87
88
89
90
91
92
93
94
95

/**
 * install packages
 */
function install() {
  return gulp.series(async () => {
    const demoDist = config.demoDist
    const demoPackageJsonPath = path.join(demoDist, 'package.json')
    const packageJson = _.readJson(path.resolve(__dirname, '../package.json'))
    const dependencies = packageJson.dependencies || {}
fork icon67
star icon602
watch icon15

75
76
77
78
79
80
81
82
83
84
// gulp clean -> clean generated files
exports.clean = clean;
// gulp lint -> errors if code dirty
exports.lint = lint;
// gulp watch -> watch for changes and compile
exports.watch = gulp.series(build, watch);
// gulp tag -> Tag this release
exports.tag = gulp.series(changes, tag);
// gulp -> gulp watch
exports.default = exports.watch;
fork icon558
star icon2
watch icon0

+ 5 other calls in file

How does gulp.series work?

gulp.series works by taking one or more task functions as input and returning a new function that executes those tasks in sequence.

When the new function is called, it executes each task in order, waiting for each task to complete before moving on to the next.

If any task returns an error, the new function stops execution and passes the error back up to the caller.

The resulting function can be used as a task in a Gulp.js workflow, allowing you to define a sequence of tasks that must be run in a specific order.

By creating a series of tasks, you can break down complex workflows into smaller, more manageable pieces that can be executed in sequence.

78
79
80
81
82
83
84
85
86
87
                .pipe(srcmap.write('.', { sourceRoot: function (file) { return file.cwd + '/test'; } }))
                .pipe(gulp.dest('out/test/'));
});

// COMPOSED GULP TASKS /////////////////////////////////////////////////////
gulp.task("compile", gulp.series("compile:src", "compile:test"));

gulp.task("build", gulp.series("clean", "lint", "compile"));

gulp.task("watch", function () {
fork icon869
star icon0
watch icon1

+ 5 other calls in file

88
89
90
91
92
93
94
95
96
97
                .pipe(eslint())
                .pipe(gulpif(config.watch, plumber()))
                .pipe(eslint.format())
                .pipe(eslint.failAfterError());

const jsState1 = gulp.series(jsLint);
const jsState3 = gulp.parallel(jsLibs, jsApp, jsAdmin);
const jsState2 = gulp.series(jsClean, webpack, jsState3, jsMin);

exports.jsLint = jsLint;
fork icon825
star icon0
watch icon161

+ 31 other calls in file

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const gulp = require("gulp");

// A task that logs a message to the console
function task1() {
  console.log("Task 1 completed");
  return Promise.resolve();
}

// A task that creates a new file
function task2() {
  console.log("Task 2 completed");
  return Promise.resolve();
}

// A task that watches for changes to files
function watchTask() {
  console.log("Watching for changes");
}

// Define a default task that runs the series of tasks in order
gulp.task("default", gulp.series(task1, task2, watchTask));

In this example, we define three tasks: task1, task2, and watchTask. task1 and task2 are simple tasks that log a message to the console and return a resolved Promise. watchTask is a task that watches for changes to files but does not return a Promise. We then define a default task using gulp.task that runs the series of tasks in order using gulp.series. The resulting default task executes task1, task2, and watchTask in sequence, waiting for each task to complete before moving on to the next. When gulp is run from the command line with no arguments, it executes the default task, running the series of tasks in order.

86
87
88
89
90
91
92
93
94
95
});

// COMPOSED GULP TASKS /////////////////////////////////////////////////////
gulp.task("compile", gulp.series("compile:src", "compile:test"));

gulp.task("build", gulp.series("clean", "copytypings", "lint", "compile"));

gulp.task("watch", function () {
        gulp.watch([config.paths.project.root + '/src/**/*',
        config.paths.project.root + '/test/**/*.ts'],
fork icon864
star icon0
watch icon275

+ 5 other calls in file

77
78
79
80
81
82
83
84
85
86

// ----- TASKS -----
//

// Compiles JavaScript into a single file
gulp.task('javascript', gulp.series('javascript:foundation', 'javascript:deps', 'javascript:docs'));

// Core has to be dealt with slightly differently due to bootstrapping externals
// and the dependency on foundation.core.utils
//
fork icon0
star icon1
watch icon3

+ 5 other calls in file

39
40
41
42
43
44
45
46
47
48
gulp.task('integration-tests', gulp.series('unit-tests', function () {
  return gulp.src(['test/integration/*.js'], {read: false})
    .pipe(mocha({reporter: 'spec'}));
}));

gulp.task('addAssets', gulp.series('integration-tests', function () {
  var jsFiles = gulp.src([
      paths.srcJS,
      'node_modules/jquery/dist/jquery.min.js',
      'node_modules/jquery-mockjax/dist/jquery.mockjax.min.js',
fork icon758
star icon0
watch icon150

+ 15 other calls in file

68
69
70
71
72
73
      force: true,
    }),
  )
})

gulp.task('default', gulp.series('clean', 'build'))
fork icon187
star icon0
watch icon43

+ 7 other calls in file

79
80
81
82
83
84
85
86
87
    return gulp.watch('css/*.css', gulp.series(['css']))
});

// 使用 gulp.task('default') 定义默认任务
// 在命令行使用 gulp 启动 css 任务和 auto 任务
gulp.task('default', gulp.series(['css', 'auto']))
```

你可以访问 [gulp-minify-css](https://github.com/jonathanepollack/gulp-minify-css) 以查看更多用法。
fork icon372
star icon0
watch icon354

+ 11 other calls in file

37
38
39
40
41
42
43
44
45
                .pipe(rename({ suffix: '.min' }))
                .pipe(uglify({ preserveComments: 'license' }))
                .pipe(gulp.dest('./dist/'));
}));

gulp.task('docDist', gulp.series('buildMin', function() {
        return gulp.src('./dist/granim.min.js')
                .pipe(copy('./docs/assets/js/vendor/', { prefix: 1 }));
}));
fork icon262
star icon0
watch icon0

+ 27 other calls in file

31
32
33
34
35
36
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('./dist'));
    done();
});

gulp.task('default', gulp.series(['css', 'js']));
fork icon375
star icon0
watch icon64

244
245
246
247
248
249
250
251
252
253
254
255
  return compileTs({ packages, sourcemap: true });
});


gulp.task(
  'compile',
  gulp.series('compile:static', 'compile:build-scripts', 'compile:dynamic', 'compile:extension'),
);


/** Run webpack to bundle into the flat session launcher (for VS or standalone debug server)  */
gulp.task('flatSessionBundle:webpack-bundle', async () => {
fork icon238
star icon0
watch icon35

+ 29 other calls in file

405
406
407
408
409
410
411
412
413
414
415
416
        default:
            throw new Error('Unknown WebPack Configuration');
    }
}


gulp.task('prePublishBundle', gulp.series('webpack'));
gulp.task('checkDependencies', gulp.series('checkNativeDependencies', 'checkNpmDependencies'));
gulp.task('prePublishNonBundle', gulp.parallel('compile', gulp.series('compile-webviews')));


function spawnAsync(command, args, env, rejectOnStdErr = false) {
fork icon209
star icon956
watch icon43

+ 14 other calls in file

112
113
114
115
116
117
118
119
120
121
122
123
    .pipe($.replace(new RegExp(`(${blackWordList.join('|')})`, 'g'), '--****--'))
    .pipe(gulp.dest('./build/dist'));
});


/** 本地方法命令 */
gulp.task('watch', gulp.series('webpack:watch'));


gulp.task('dev:main', done => {
  const devWatchTasks = ['webpack:watch'];
  const devServeTasks = ['generate-mainweb', 'copy', 'server'];
fork icon58
star icon132
watch icon11

+ 4 other calls in file

68
69
70
71
72
73
74
75
76
77
 * 1. download
 * 2. name zip as <id>-gtfs.zip (in dir download)
 * 3. test zip loads with OpenTripPlanner
 * 4. copy to id dir if test is succesful
 */
gulp.task('gtfs:dl', gulp.series('del:id', function () {
  const urlEntry = {}
  config.ALL_CONFIGS().map(cfg => cfg.src).reduce((acc, val) => acc.concat(val), []).forEach(
    (entry) => {
      if (urlEntry[entry.url] === undefined) {
fork icon21
star icon11
watch icon18

+ 8 other calls in file

264
265
266
267
268
269
270
271
272
273
274
275
      gulp.watch(SITE_BASE + 'versioning-machine/**/*.css').on('change', browserSync.reload);
      gulp.watch(SITE_BASE + '**/*.html', gulp.series('html'));
    })
);


gulp.task('deploy', gulp.series('clean', gulp.parallel('vendor-scripts-deploy', 'scripts-deploy', 'styles-deploy', 'images-deploy'), 'files-deploy', (done) => {
  done();
}));


/* Erasers */
fork icon4
star icon7
watch icon5

+ 15 other calls in file

265
266
267
268
269
270
271
272
273
274
275
      gulp.watch(SITE_BASE + '**/*.html', gulp.series('html'));
    })
);


gulp.task('files',
  gulp.series('clean',
    gulp.parallel(
      'vendor-scripts-deploy',
      'scripts-deploy',
      'styles-deploy',
fork icon4
star icon7
watch icon5

+ 116 other calls in file

688
689
690
691
692
693
694
695
696
        return gulpUtil.noop();
      })
  ]);
});


gulp.task('xslt', gulp.series('xslt:erase:poems', 'xslt:manifest', 'xslt:index', 'xslt:poems', 'sitemap', (done) => {
  done();
}));
fork icon4
star icon7
watch icon5

+ 3 other calls in file

917
918
919
920
921
922
923
924
925
926
927
function watch() {
  const cssPath = paths.editor + "/**/*.scss";


  gulp.watch(
    cssPath,
    gulp.series.apply(undefined, [
      editorCSS,
      proEditorCSS,
      ...(IS_EXPORT ? [exportCSS, proExportCSS] : [])
    ])
fork icon74
star icon254
watch icon28

+ 6 other calls in file

401
402
403
404
405
406
407
408
409
410
// Basic Tasks
gulp.task("js", gulp.series(set_dev, js));
gulp.task("js_min", js);
gulp.task("css", css);
gulp.task("styles", styles);
gulp.task("images", gulp.series(set_dev, images));
gulp.task("manifests", gulp.series(set_dev, manifests));
gulp.task("fonts", fonts);
gulp.task("jekyll", jekyll);

fork icon538
star icon177
watch icon94

+ 3 other calls in file