問題描述
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 任務已經完成,但它應該寫入操作系統(tǒng)的文件還沒有完全到位.我注意到,如果我在瀏覽器捆綁命令中添加了一個 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.
這篇關于在繼續(xù)下一個任務之前使 gulp 同步寫入文件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!