现在我遇到了问题 下面是我的代码
//代码 //config.json
[
{
"name": "1"
},
{
"name": "2"
},
{
"name": "3"
}
]
//吞
var gulp = require('gulp');
var fs = require('fs');
var gulpsync = require('gulp-sync')(gulp);
var config = JSON.parse(fs.readFileSync(paths.config, 'utf-8'));
var tasks = [];
warehouseConfig.forEach(function(item) {
var task = item.name;
tasks.push(task);
template.dist = task;
gulp.task('copy:' + task, function() {
template.dist = task;
console.log('start copy ' + task + 'dist:' + template.dist);
gulp.start('copy');
});
gulp.task(task, ['copy:' + task], function() {
return gulp.src(task)
.pipe(gulp.dest(task + '/'));
});
});
gulp.task('copy', ['copy:www', 'copy:plugins', 'copy:platforms']);
gulp.task( 'build:pre', gulpsync.sync(tasks));
gulp.task( 'build', ['clean'], function() {
gulp.start('build:pre');
});
现在,我有问题,同样的任务"复制"只运行一次,我希望它运行三次。 你有什么好主意吗?
答案 0 :(得分:0)
如果你只想运行那个gulp任务运行三次,你可以在子进程中实际运行它:
const exec = require('child_process').exec;
//replace gulp.start('copy') with
exec('gulp copy');
这会使它异步,您可以通过将其替换为:child_process.execSync
使其同步此处的链接:https://nodejs.org/api/child_process.html#child_process_child_process_execsync_command_options
希望这有效,因为gulp.start()已弃用:https://github.com/gulpjs/gulp/issues/505