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

也许这是我的方法有问题,但我有以下情况:

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

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

要求( '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()) }) 

一饮而尽,突突

虽然使用gulp-chug

“放弃,太复杂,只是使用吞噬作为一个球体”

正式的黑名单表明…

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