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 同步写入文件


- 从原点悬停时触发 translateY() 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01