[英]How to run Gulp-tasks in the particular order
I am using runsequence plugin. 我正在使用runsequence插件。 But It seems that I am doing something wrong so it is not working.
但似乎我做错了什么,所以它不起作用。 I am trying to create browserify build and concat it with my handlebars precompiled templates on server using run-sequence gulp plugin.
我正在尝试使用运行序列gulp插件在服务器上创建我的车把预编译模板并将其与我的车把预编译模板连接起来。
In gulpfile correspoding tasks looks like this: 在gulpfile中,相应的任务如下所示:
gulp.task("browserify", function () {
gulp.src('src/js/map.js')
.pipe(browserify({
insertGlobals: false,
debug: false
}))
.pipe(gulp.dest('build'))
.pipe(notify({ message: "browserify ended" }));
});
gulp.task("scripts", function () {
var newDir;
newDir = './build/1111';
gulp.src(['./build/map.js', './build/templates/templates.js'])
.pipe(concat('build.js'))
.pipe(gulp.dest(newDir))
.pipe(notify({ message: "scripts build ended" }));
});
gulp.task('default', function () {
runSequence( 'browserify', 'scripts' );
});
But actually scripts task are trying invoke before browserify task is done. 但是实际上脚本任务正在尝试在完成browserify任务之前调用。 So I get this output:
所以我得到这个输出:
$ gulp
[10:40:26] Using gulpfile ~/projects/map2/gulpfile.js
[10:40:26] Starting 'default'...
[10:40:26] Starting 'browserify'...
[10:40:26] Finished 'browserify' after 7.84 ms
[10:40:26] Starting 'scripts'...
[10:40:26] Finished 'scripts' after 4.58 ms
[10:40:26] Finished 'default' after 14 ms
[10:40:26] gulp-notify: [Gulp notification] templates build ended
[10:40:26] gulp-notify: [Gulp notification] browserify ended
And scripts
task don't create build.js file (note there is no message "scripts build ended" from notify plugin). 而且
scripts
任务不会创建build.js文件(请注意,通知插件没有消息“脚本构建已结束”)。
I figured out it myself. 我自己弄清楚了。 For achieving this there should be some signal from task about finishing work.
为了实现这一目标,应该从任务中获得一些有关完成工作的信号。 Check this article for more information.
查看本文以获取更多信息。 Actually I choose to return stream like this:
实际上,我选择像这样返回流:
gulp.task('browserify', function (cb) {
var stream = gulp.src('src/js/clientAppControl.js')
.pipe(browserify({
insertGlobals: false,
debug: false
}))
.pipe(gulp.dest('build'))
.pipe(notify({ message: 'browserify ended' }));
return stream;
});
and dependencies started to work properly. 并且依赖项开始正常工作。
Similar to the answer you added, but a little cleaner in my opinion, is to remove return stream
and replace var stream =
with return
. 与您添加的答案类似,但在我看来,更简洁的方法是删除
return stream
并将var stream =
替换为return
。
gulp.task('browserify', function (cb) {
return gulp.src('src/js/clientAppControl.js')
.pipe(browserify({
insertGlobals: false,
debug: false
}))
.pipe(gulp.dest('build'))
.pipe(notify({ message: 'browserify ended' }));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.