[英]Running gulp task from one gulpfile.js from another gulpfile.js
Perhaps it's something wrong with my approach but I have a following situation: 也许这与我的方法有关,但我有以下情况:
component-a
that has a gulpfile. component-a
-a有一个gulpfile。 One of its tasks (eg. build) builds the component and creates a combined js file in dist folder component-b
that has a gulpfile. component-b
有一个gulpfile。 One of its tasks (eg. build) builds the component and creates a combined js file in dist folder What I don't know is how to execute the build task from /components/component-?/gulpfile.js. 我不知道的是如何从/components/component-?/gulpfile.js执行构建任务。 Is it even possible or I should deal with this situation otherwise?
是否有可能或者我应该处理这种情况呢?
Running a Gulpfile from a different directory is quite simple with Node's child_process#spawn
module . 使用Node的
child_process#spawn
模块,从不同的目录运行Gulpfile非常简单。
Try adapting the following to your needs: 尝试根据您的需求调整以下内容:
// 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())
})
Although using gulp-chug
is one way to go about this, it has been blacklisted by gulp
's maintainers for being... 虽然使用
gulp-chug
是解决这个问题的一种方法, 但是已经被gulp
的维护人员列入黑名单 ,因为......
"execing, too complex and is just using gulp as a globber"
“执行,太复杂,只是使用gulp作为一个球体”
The official blacklist states... 官方黑名单声明......
"no reason for this to exist, use the require-all module or node's require"
“没有理由存在,请使用require-all模块或节点的要求”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.