从另一个gulpfile.js中的一个gulpfile.js运行gulp任务

dra*_*fly 24 javascript node.js gulp

也许这与我的方法有关,但我有以下情况:

  1. 我有component-a一个gulpfile.其任务之一(例如构建)构建组件并在dist文件夹中创建组合的js文件
  2. 我有component-b一个gulpfile.其任务之一(例如构建)构建组件并在dist文件夹中创建组合的js文件
  3. 我有一个使用这两个组件的项目.这个项目也有一个gulp文件,我想写一个任务:
    • 从/components/component-a/gulpfile.js执行构建任务
    • 从/components/component-b/gulpfile.js执行构建任务
    • concats /components/component-a/dist/build.js和/components/component-b/dist/build.js(我知道如何做到这一点)

我不知道的是如何从/components/component-?/gulpfile.js执行构建任务.是否有可能或者我应该处理这种情况呢?

Wal*_*man 22

要求( 'child_process')产卵.;

使用Node的child_process#spawn模块,从不同的目录运行Gulpfile非常简单.

尝试根据您的需求调整以下内容:

// Use `spawn` to execute shell commands with Node
const { spawn } = require('child_process')
const { join } = require('path')

/*
  Set the working directory of your current process as
  the directory where the target Gulpfile exists.
*/
process.chdir(join('tasks', 'foo'))

// Gulp tasks that will be run.
const tasks = ['js:uglify', 'js:lint']

// Run the `gulp` executable
const child = spawn('gulp', tasks)

// Print output from Gulpfile
child.stdout.on('data', function(data) {
    if (data) console.log(data.toString())
})
Run Code Online (Sandbox Code Playgroud)

一饮而尽,突突

尽管使用gulp-chug是一种解决方法,但它已经被gulp维护者列入黑名单 ......

"执行,太复杂,只是使用gulp作为一个球体"

官方黑名单的状态...

"没有理由存在,请使用require-all模块或节点的要求"