Making gulp write files synchronously before moving on to the next task(在继续下一个任务之前使 gulp 同步写入文件)
问题描述
gulpfile.js
gulpfile.js
gulp.task('browser-bundle', ['react'], function() {
...
});
gulp.task('react', function(){
gulp.src(options.JSX_SOURCE)
.pipe(react())
.pipe(gulp.dest(options.JSX_DEST))
});
如您所见,我有浏览器捆绑任务,具体取决于反应任务.我相信这可以按预期工作,因为在输出中我看到了:
As you can see I have the browser-bundle task depending on the react task. I believe this works as expected because in the output I see this:
[gulp] Running 'react'...
[gulp] Finished 'react' in 3.43 ms
[gulp] Running 'browser-bundle'...
然而,虽然 react 任务已经完成,但它应该写入操作系统的文件还没有完全到位.我注意到,如果我在浏览器捆绑命令中添加了一个 sleep 语句,那么它会按预期工作,但这对我来说似乎有点 hacky.
However, although the react task is finished, the files its supposed to write to the operating system are not quite there yet. I've notice that if I put a sleep statement in the browser bundle command then it works as expected, however this seems a little hacky to me.
如果我希望在文件(来自 gulp.dest)被同步写入磁盘之前不认为反应任务完成,我该怎么做?
If I want the react task to not be considered finished until the files (from gulp.dest) have been synchronously written to disk how would I do that?
推荐答案
你需要一个return语句:
You need a return statement:
gulp.task('react', function(){
return gulp.src(options.JSX_SOURCE)
.pipe(react())
.pipe(gulp.dest(options.JSX_DEST))
});
这样,我所有的写操作都在下一个任务处理之前完成.
With this all my write operations are done before the next task processed.
这篇关于在继续下一个任务之前使 gulp 同步写入文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在继续下一个任务之前使 gulp 同步写入文件


基础教程推荐
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 动态更新多个选择框 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01