Gulp: 无法读取在上一个任务中创建的文件
Gulp: File not able to read which was created in last task
此处 app/folder1/
包含 3 angularjs 个文件(控制器、服务、工厂)。通过使用 'task1'
,我将所有 html 个文件组合成 'templates.js'。在'task2'
中,我需要将3个angularjs个文件和1个templates.js个文件合并成一个文件。
但在 'task2' 中,系统只读取 3 个 angularjs 文件。如果我 运行 'task2' 分开然后系统合并 4 个文件。
gulp.task('task1',function() {
gulp.src('app/**/*.html')
.pipe(minifyHtml({empty: true}))
.on('error', gutil.log)
.pipe(templateCache({root: 'app/folder1/',module:'myModule'}))
.on('error', gutil.log)
.pipe(gulp.dest('app/folder2/'))
.on('error', gutil.log);
});
});
gulp.task('task2',function(){
var newName = 'script_' + new Date().getTime() + '.js';
gulp.src('app/folder2/**/*.js')
.on('error', gutil.log)
.pipe(concat(newName,{newLine: ';'}))
.on('error', gutil.log)
.pipe(gulp.dest('/dist/'))
.on('error', gutil.log)
.pipe(uglify({mangle:false }))
.on('error', gutil.log)
.pipe(gulp.dest('/dist/'))
.on('error', gutil.log);
});
});
gulp.task('default', function(callback) {
runSequence('task1','task2',callback);
});
如果我使用 运行 gulp
命令,它不会合并 templates.js 文件。
如果我 运行 gulp
, gulp task2
那么它会按预期工作。
这是什么问题?
如果您不打算处理 task1
和 task2
.
中的 callback
,我认为您需要 return 流
return gulp.src('app/**/*.html')
.pipe(...
此处 app/folder1/
包含 3 angularjs 个文件(控制器、服务、工厂)。通过使用 'task1'
,我将所有 html 个文件组合成 'templates.js'。在'task2'
中,我需要将3个angularjs个文件和1个templates.js个文件合并成一个文件。
但在 'task2' 中,系统只读取 3 个 angularjs 文件。如果我 运行 'task2' 分开然后系统合并 4 个文件。
gulp.task('task1',function() {
gulp.src('app/**/*.html')
.pipe(minifyHtml({empty: true}))
.on('error', gutil.log)
.pipe(templateCache({root: 'app/folder1/',module:'myModule'}))
.on('error', gutil.log)
.pipe(gulp.dest('app/folder2/'))
.on('error', gutil.log);
});
});
gulp.task('task2',function(){
var newName = 'script_' + new Date().getTime() + '.js';
gulp.src('app/folder2/**/*.js')
.on('error', gutil.log)
.pipe(concat(newName,{newLine: ';'}))
.on('error', gutil.log)
.pipe(gulp.dest('/dist/'))
.on('error', gutil.log)
.pipe(uglify({mangle:false }))
.on('error', gutil.log)
.pipe(gulp.dest('/dist/'))
.on('error', gutil.log);
});
});
gulp.task('default', function(callback) {
runSequence('task1','task2',callback);
});
如果我使用 运行 gulp
命令,它不会合并 templates.js 文件。
如果我 运行 gulp
, gulp task2
那么它会按预期工作。
这是什么问题?
如果您不打算处理 task1
和 task2
.
callback
,我认为您需要 return 流
return gulp.src('app/**/*.html')
.pipe(...