设置一个咕嘟咕嘟任务是默认
我在gulpFile
以下任务,有人在我的团队人创建:设置一个咕嘟咕嘟任务是默认
gulp.task('serve', [], function(){
gulp.run(
'fonts',
'browsersync',
'watch'
);
});
我想息事宁人,但我也想映射此任务的默认任务。所以,我想:
gulp.task('default',['serve']);
它似乎工作,在服务器运行,但由于某种原因,“监视”任务还没有发生的事情,我不上的变化让浏览器刷新。
这一切都按计划运行,如果我运行“吞噬服务”而不是“吞咽”。我做错了什么?
编辑: 这里的手表任务:
gulp.task('watch', ['styles', 'browsersync'], function() { //'default'
gulp.watch(
[
'./app/assets/sass/**/*.scss',
'./app/modules/**/*.scss'
], ['styles']);
gulp.watch([
'./app/**/*.js',
'./app/**/*.html'
], function() {
reload();
});
});
尝试运行它里面serve
的更新您的默认任务包括在数组参数表任务来代替。像这样:
gulp.task('default', ['serve', 'watch']);
如果检出咕嘟咕嘟文档上asynchronous task support,特别是最后一个例子,你会看到,你可以要求相关的任务来完成指定的任务应该开始之前。
var gulp = require('gulp');
// takes in a callback so the engine knows when it'll be done
gulp.task('one', function(cb) {
// do stuff -- async or otherwise
cb(err); // if err is not null and not undefined, the run will stop, and note that it failed
});
// identifies a dependent task must be complete before this one begins
gulp.task('two', ['one'], function() {
// task 'one' is done now
});
gulp.task('default', ['one', 'two']);
gulp.run
和gulp.start
被认为是不好的做法:
https://github.com/gulpjs/gulp/issues/426
https://github.com/gulpjs/gulp/issues/505
遗憾的是,答案在这里似乎是你的同事可能没有真正理解咕嘟咕嘟。如果不更改代码,您可能无法解决此问题。
没有更多的上下文,就像整个gulp文件一样,我无法重现您的确切问题。不过,我的直觉是,它与Gulp异步/连续执行任务的方式有关。可能是您的'默认'任务过早退出,因为gulp.run
不会同步执行。不管怎样,Gulp对什么时候需要等待什么任务感到困惑。您正在使用两种完全不同的工具来管理您的运行顺序。
相反的gulp.run
,你的“服务”任务应该真正使用的依赖于运行其他任务:
gulp.task('serve', ['fonts', 'browsersync', 'watch']);
gulp.task('default', ['serve']);
而且,值得指出的是您的手表任务已经上市的“browsersync”作为一个依赖。虽然技术上不正确(Gulp会第二次忽略它),但它可能导致过度复杂化和混乱,因此可能不是一个好主意。如果“手表”取决于“browsersync”,你可以从“服务”删除“browsersync”依赖性:
gulp.task('watch', ['styles', 'browsersync'], function() {
gulp.watch([
'./app/assets/sass/**/*.scss',
'./app/modules/**/*.scss'
], ['styles']);
gulp.watch([
'./app/**/*.js',
'./app/**/*.html'
], function() {
reload();
});
});
gulp.task('serve', ['fonts', 'watch']);
gulp.task('default', ['serve']);
这应该得到你正在寻找的结果。
所有这一切是说,如果你真的坚持走坏习惯,你可以尝试在你的“默认”任务使用gulp.run
:
gulp.task('default', function() {
gulp.run('serve');
});
我怀疑你的主要问题是,你是混合使用阵列任务依赖关系和gulp.run
,但是无论如何,gulp.run
是“做错了”。
您可能还想看看关于如何确保异步任务系列执行的Gulp文档: https://github.com/gulpjs/gulp/blob/master/docs/API.md#async -task支持 – 2015-02-11 18:00:39
您的手表任务是什么样的? – Seth 2015-02-11 14:12:32
已添加到原始问题中。抱歉。 – Steve 2015-02-11 15:11:01