dra*_*fly 24 javascript node.js gulp
也许这与我的方法有关,但我有以下情况:
component-a一个gulpfile.其任务之一(例如构建)构建组件并在dist文件夹中创建组合的js文件component-b一个gulpfile.其任务之一(例如构建)构建组件并在dist文件夹中创建组合的js文件我不知道的是如何从/components/component-?/gulpfile.js执行构建任务.是否有可能或者我应该处理这种情况呢?
Wal*_*man 22
使用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模块或节点的要求"