久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='jjAAT'></tfoot><legend id='jjAAT'><style id='jjAAT'><dir id='jjAAT'><q id='jjAAT'></q></dir></style></legend>

      • <bdo id='jjAAT'></bdo><ul id='jjAAT'></ul>

      <small id='jjAAT'></small><noframes id='jjAAT'>

    1. <i id='jjAAT'><tr id='jjAAT'><dt id='jjAAT'><q id='jjAAT'><span id='jjAAT'><b id='jjAAT'><form id='jjAAT'><ins id='jjAAT'></ins><ul id='jjAAT'></ul><sub id='jjAAT'></sub></form><legend id='jjAAT'></legend><bdo id='jjAAT'><pre id='jjAAT'><center id='jjAAT'></center></pre></bdo></b><th id='jjAAT'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jjAAT'><tfoot id='jjAAT'></tfoot><dl id='jjAAT'><fieldset id='jjAAT'></fieldset></dl></div>

    2. Gulp 任務中`return` 語句和`callback` 參考的用途

      Purpose of `return` Statement and `callback` Reference in Gulp Task(Gulp 任務中`return` 語句和`callback` 參考的用途)

    3. <i id='GI6r6'><tr id='GI6r6'><dt id='GI6r6'><q id='GI6r6'><span id='GI6r6'><b id='GI6r6'><form id='GI6r6'><ins id='GI6r6'></ins><ul id='GI6r6'></ul><sub id='GI6r6'></sub></form><legend id='GI6r6'></legend><bdo id='GI6r6'><pre id='GI6r6'><center id='GI6r6'></center></pre></bdo></b><th id='GI6r6'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='GI6r6'><tfoot id='GI6r6'></tfoot><dl id='GI6r6'><fieldset id='GI6r6'></fieldset></dl></div>
      <tfoot id='GI6r6'></tfoot>
      • <small id='GI6r6'></small><noframes id='GI6r6'>

          <bdo id='GI6r6'></bdo><ul id='GI6r6'></ul>

              <tbody id='GI6r6'></tbody>
            1. <legend id='GI6r6'><style id='GI6r6'><dir id='GI6r6'><q id='GI6r6'></q></dir></style></legend>

                本文介紹了Gulp 任務中`return` 語句和`callback` 參考的用途的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                限時送ChatGPT賬號..

                我無法讓 gulp run-sequence 執行我給它的兩個函數(它只會執行其中一個.我有這樣的事情:

                gulp.task('wire', function(){gulp.src('./index.html').pipe(wiredep()).pipe(gulp.dest('.'));});var filesToInject = ['./app/**/*.js', './app/**/*.css'];gulp.task('注入', function (){var target = gulp.src('./index.html');var sources = gulp.src(filesToInject, {read: false});返回target.pipe(注入(來源)).pipe(gulp.dest('.'));});gulp.task('wire-inject', function(callback){序列('wire','inject',回調);});

                那只會運行 inject 任務.只有當我在 wire 任務中的 gulp.src 之前添加一個 return 時,它才會執行.我還在兩個函數參數中添加了回調,并將其傳遞給每個 文檔.

                gulp.task('wire', function(callback){gulp.src('./index.html').pipe(wiredep()).pipe(gulp.dest('.'), 回調);});var filesToInject = ['./app/**/*.js', './app/**/*.css'];gulp.task('inject', 函數(回調){var target = gulp.src('./index.html');var sources = gulp.src(filesToInject, {read: false});返回target.pipe(注入(來源)).pipe(gulp.dest('.'), 回調);});

                這并沒有引發任何錯誤,但是如果我把它拿出來它不會改變任何東西.這個 return 語句做了什么神奇地使我的序列完全運行.文檔中的這些回調是什么,我只是通過不帶括號的引用來執行它們?即使它們看似什么都不做,我是否仍然需要它們?

                解決方案

                Gulp 需要知道異步任務何時完成.您有 3 種方法可以做到這一點:

                1. 返回一個事件流,這就是當你的任務函數中有 return gulp.src(...).pipe(...); 時你所做的.p>

                2. 返回一個承諾.

                3. 讓定義你任務的函數帶一個參數.Gulp 將使用回調函數調用您的函數,您應該在任務結束時調用該回調函數.

                如果您不這樣做,那么 Gulp 將不會知道該任務是異步的.因此,它會在其函數返回后立即認為任務已完成.這會帶來各種后果.Gulp 可以在任務完成之前退出.或者它可以在任務 A 完成之前啟動依賴于任務 A 的任務 B.在某些情況下,您可能立即看不到問題,但隨著您的 gulpfile 變得越來越復雜,您出現不良行為的機會也越來越多.run-sequence 并不特殊:它需要知道任務何時完成才能正確完成工作.

                請注意,您在問題中顯示的此代碼中的 callback 是無用的:

                return target.pipe(inject(sources)).pipe(gulp.dest('.'), 回調);

                callback 不會被調用.將其替換為 function () { console.log("Hello!");打回來();}.您不會在控制臺上看到 Hello!,因為未調用回調.但是,代碼確實可以正常工作,因為您返回了流.Gulp 使用您返回的流來確定任務結束,而不是回調(無論如何都不會調用).

                I was having trouble getting gulp run-sequence to execute both functions that i gave it (it would only execute one of them. I had something like this:

                gulp.task('wire', function(){
                  gulp.src('./index.html')
                    .pipe(wiredep())
                    .pipe(gulp.dest('.'));
                });
                
                var filesToInject = ['./app/**/*.js', './app/**/*.css'];
                gulp.task('inject', function (){
                  var target = gulp.src('./index.html');
                  var sources = gulp.src(filesToInject, {read: false});
                  return target.pipe(inject(sources))
                    .pipe(gulp.dest('.'));
                });
                
                gulp.task('wire-inject',  function(callback){
                    sequence('wire', 'inject', callback);
                });
                

                That would only run the inject task. Only when I added a return before gulp.src in the wire task would it execute. I also added callback in both function params and passed it to the last pipe in both tasks per the documentation.

                gulp.task('wire', function(callback){
                  gulp.src('./index.html')
                    .pipe(wiredep())
                    .pipe(gulp.dest('.'), callback);
                });
                
                var filesToInject = ['./app/**/*.js', './app/**/*.css'];
                gulp.task('inject', function (callback){
                  var target = gulp.src('./index.html');
                  var sources = gulp.src(filesToInject, {read: false});
                  return target.pipe(inject(sources))
                    .pipe(gulp.dest('.'), callback);
                });
                

                That did not throw any errors, however it doesn't change anything if I take it out. What does this return statement do that magically makes my sequence run completely. What are these callbacks in the documentation that I just pass a reference to with out parentheses to execute them? Do I still need them even though they seemingly do nothing?

                解決方案

                Gulp needs to know when an asynchronous task is done. You have 3 ways to do this:

                1. Return an event stream, which is what you do when you have return gulp.src(...).pipe(...); in your task's function.

                2. Return a promise.

                3. Have the function that defines you task take a parameter. Gulp will call your function with a callback that you should call when the task is over.

                If you do not do this, then Gulp will not know that the task is asynchronous. So it will consider the task done as soon as its function returns. This has all kinds of consequences. Gulp could exit before a task is done. Or it could start a task B that depends on task A before task A is complete. In some cases, you may not see a problem immediately but as your gulpfile gets more complex, you run more chances of getting bad behavior. run-sequence is not special: it needs to know when a task is complete to do its job correctly.

                Note that callback in this code which you show in your question is useless:

                return target.pipe(inject(sources))
                    .pipe(gulp.dest('.'), callback);
                

                callback won't be called. Replace it with function () { console.log("Hello!"); callback(); }. You won't see Hello! on the console because the callback is not called. However, the code does work overall because you return the stream. Gulp uses the stream you return to determine that the task is over, not the callback (which is never called anyway).

                這篇關于Gulp 任務中`return` 語句和`callback` 參考的用途的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運算符上的意外令牌)
                Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標志傳遞給 Gulp 以使其以不同的方式運行任務?)
                Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                How to run Gulp tasks sequentially one after the other(如何一個接一個地依次運行 Gulp 任務)
                Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                Detect FLASH plugin crashes(檢測 FLASH 插件崩潰)

                <small id='8cjwz'></small><noframes id='8cjwz'>

                1. <tfoot id='8cjwz'></tfoot>

                    <tbody id='8cjwz'></tbody>
                  <i id='8cjwz'><tr id='8cjwz'><dt id='8cjwz'><q id='8cjwz'><span id='8cjwz'><b id='8cjwz'><form id='8cjwz'><ins id='8cjwz'></ins><ul id='8cjwz'></ul><sub id='8cjwz'></sub></form><legend id='8cjwz'></legend><bdo id='8cjwz'><pre id='8cjwz'><center id='8cjwz'></center></pre></bdo></b><th id='8cjwz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8cjwz'><tfoot id='8cjwz'></tfoot><dl id='8cjwz'><fieldset id='8cjwz'></fieldset></dl></div>
                    <bdo id='8cjwz'></bdo><ul id='8cjwz'></ul>

                      1. <legend id='8cjwz'><style id='8cjwz'><dir id='8cjwz'><q id='8cjwz'></q></dir></style></legend>

                          主站蜘蛛池模板: 蜜桃在线视频 | 免费观看一级毛片视频 | 日韩精品在线播放 | 精品久久九九 | xnxx 日本免费 | 在线一区视频 | 欧美激情精品久久久久 | 久久久久国产精品一区 | 一级在线观看 | 亚洲第一福利视频 | 亚洲成人一区二区 | 免费黄色录像片 | 一级黄色片在线免费观看 | 精品一二区| 国产一区二区三区四区区 | av日韩一区 | 男人天堂网站 | 国产精品日韩欧美一区二区三区 | 一区二区在线 | 欧美日韩亚洲一区 | 日韩一区中文字幕 | 精品日韩在线 | av成人在线观看 | 欧美激情a∨在线视频播放 成人免费共享视频 | 免费视频久久久久 | 自拍偷拍第一页 | 热久久999| 国产精品99久久免费观看 | 欧美日韩视频 | 亚洲免费福利视频 | 九九精品久久久 | 中文在线a在线 | 亚洲国产欧美精品 | 福利视频一区 | 欧美综合国产精品久久丁香 | 久草免费在线视频 | 九九热在线免费观看 | av黄色免费 | 看片网站在线 | 四虎在线视频 | av乱码 |