Gulp调用子模块

Gulp call sub modules

有一个父文件夹(gulp 模块),其中有一些子文件夹(gulp 模块)。我想 运行 每个子项的默认 gulp 任务通过父项的 gulp 文件。

我的方法是通过使用 gulp-folders 和 运行 a gulpgulp-shell 通过将当前工作目录设置为相应的子目录来遍历文件夹。

var tOptions = {};
[...]

gulp.task('setup-modules', folders('./', function(folder){
    tOptions.cwd = folder;
    gulp.start('setup-module');
    return gulp.src('', {read: false});
}));

gulp.task('setup-module', shell.task([
    'gulp'
], tOptions));

似乎只有一个任务实例 setup-module 开始了。我需要更改什么才能获得任务 运行ning 的多个实例(对于每个子文件夹)?

如果您想 运行 除 default 以外的任何任务,您可以使用 gulp-chug and pass a glob to gulp.src() to access your child gulpfiles eliminating the need to iterate over each subdirectory. You can even specify which tasks you would like to run 而不是 gulp-shell

此外,gulp-chug 会做所有事情,所以除了一个包来完成你想要做的事情之外,没有必要依赖更多。

One of the examples from the gulp-chug docs 详细介绍了您正在讨论的几乎所有场景。

gulpfile.js (parent)

// This example was taken from the gulp-chug docs

var gulp = require( 'gulp' );
var chug = require( 'gulp-chug' );

gulp.task( 'default', function () {

    // Find and run all gulpfiles under all subdirectories 
    gulp.src( './**/gulpfile.js' )
        .pipe( chug() )
} );