pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="lrxx7d7" id='jjAAT'><tfoot id='jjAAT'></tfoot><dl id='jjAAT'><fieldset id='jjAAT'></fieldset></dl></div>

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

      Purpose of `return` Statement and `callback` Reference in Gulp Task(Gulp 任務(wù)中`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="tjr7jjp" 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 任務(wù)中`return` 語句和`callback` 參考的用途的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                限時(shí)送ChatGPT賬號..

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

                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',回調(diào));});

                那只會運(yùn)行 inject 任務(wù).只有當(dāng)我在 wire 任務(wù)中的 gulp.src 之前添加一個(gè) return 時(shí),它才會執(zhí)行.我還在兩個(gè)函數(shù)參數(shù)中添加了回調(diào),并將其傳遞給每個(gè) 文檔.

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

                這并沒有引發(fā)任何錯(cuò)誤,但是如果我把它拿出來它不會改變?nèi)魏螙|西.這個(gè) return 語句做了什么神奇地使我的序列完全運(yùn)行.文檔中的這些回調(diào)是什么,我只是通過不帶括號的引用來執(zhí)行它們?即使它們看似什么都不做,我是否仍然需要它們?

                解決方案

                Gulp 需要知道異步任務(wù)何時(shí)完成.您有 3 種方法可以做到這一點(diǎn):

                1. 返回一個(gè)事件流,這就是當(dāng)你的任務(wù)函數(shù)中有 return gulp.src(...).pipe(...); 時(shí)你所做的.p>

                2. 返回一個(gè)承諾.

                3. 讓定義你任務(wù)的函數(shù)帶一個(gè)參數(shù).Gulp 將使用回調(diào)函數(shù)調(diào)用您的函數(shù),您應(yīng)該在任務(wù)結(jié)束時(shí)調(diào)用該回調(diào)函數(shù).

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

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

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

                callback 不會被調(diào)用.將其替換為 function () { console.log("Hello!");打回來();}.您不會在控制臺上看到 Hello!,因?yàn)槲凑{(diào)用回調(diào).但是,代碼確實(shí)可以正常工作,因?yàn)槟祷亓肆?Gulp 使用您返回的流來確定任務(wù)結(jié)束,而不是回調(diào)(無論如何都不會調(diào)用).

                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).

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

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

                相關(guān)文檔推薦

                Browserify, Babel 6, Gulp - Unexpected token on spread operator(Browserify,Babel 6,Gulp - 傳播運(yùn)算符上的意外令牌)
                Is it possible to pass a flag to Gulp to have it run tasks in different ways?(是否可以將標(biāo)志傳遞給 Gulp 以使其以不同的方式運(yùn)行任務(wù)?)
                Why do we need to install gulp globally and locally?(為什么我們需要在全局和本地安裝 gulp?)
                How to run Gulp tasks sequentially one after the other(如何一個(gè)接一個(gè)地依次運(yùn)行 Gulp 任務(wù))
                Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時(shí) 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="rj77bjn" 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>

                          主站蜘蛛池模板: 物和码官网,物和码,免费一物一码数字化营销SaaS平台 | ★店家乐|服装销售管理软件|服装店收银系统|内衣店鞋店进销存软件|连锁店管理软件|收银软件手机版|会员管理系统-手机版,云版,App | 在线钠离子分析仪-硅酸根离子浓度测定仪-油液水分测定仪价格-北京时代新维测控设备有限公司 | 雷蒙磨,雷蒙磨粉机,雷蒙磨机 - 巩义市大峪沟高峰机械厂 | 三防漆–水性三防漆–水性浸渍漆–贝塔三防漆厂家 | 退火炉,燃气退火炉,燃气热处理炉生产厂家-丹阳市丰泰工业炉有限公司 | 沥青车辙成型机-车托式混凝土取芯机-混凝土塑料试模|鑫高仪器 | NM-02立式吸污机_ZHCS-02软轴刷_二合一吸刷软轴刷-厦门地坤科技有限公司 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | ph计,实验室ph计,台式ph计,实验室酸度计,台式酸度计 | 青岛侦探调查_青岛侦探事务所_青岛调查事务所_青岛婚外情取证-青岛狄仁杰国际侦探公司 | 镀锌钢格栅_热镀锌格栅板_钢格栅板_热镀锌钢格板-安平县昊泽丝网制品有限公司 | 正压送风机-多叶送风口-板式排烟口-德州志诺通风设备 | 青州搬家公司电话_青州搬家公司哪家好「鸿喜」青州搬家 | 电子海图系统-电梯检验系统-智慧供热系统开发-商品房预售资金监管系统 | elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | 艾乐贝拉细胞研究中心 | 国家组织工程种子细胞库华南分库 | 【直乐】河北石家庄脊柱侧弯医院_治疗椎间盘突出哪家医院好_骨科脊柱外科专业医院_治疗抽动症/关节病骨伤权威医院|排行-直乐矫形中医医院 | led全彩屏-室内|学校|展厅|p3|户外|会议室|圆柱|p2.5LED显示屏-LED显示屏价格-LED互动地砖屏_蕙宇屏科技 | 雨水收集系统厂家-雨水收集利用-模块雨水收集池-徐州博智环保科技有限公司 | 沙盘模型公司_沙盘模型制作公司_建筑模型公司_工业机械模型制作厂家 | 高压管道冲洗清洗机_液压剪叉式升降机平台厂家-林君机电 | 包塑软管|金属软管|包塑金属软管-闵彬管业 | 慈溪麦田广告公司,提供慈溪广告设计。| 冷却塔减速机器_冷却塔皮带箱维修厂家_凉水塔风机电机更换-广东康明冷却塔厂家 | 运动木地板_体育木地板_篮球馆木地板_舞台木地板-实木运动地板厂家 | 药品仓库用除湿机-变电站用防爆空调-油漆房用防爆空调-杭州特奥环保科技有限公司 | 济南货架定做_仓储货架生产厂_重型货架厂_仓库货架批发_济南启力仓储设备有限公司 | 广西绿桂涂料--承接隔热涂料、隔音涂料、真石漆、多彩仿石漆等涂料工程双包施工 | 2025福建平潭岛旅游攻略|蓝眼泪,景点,住宿攻略-趣平潭网 | 合肥活动房_安徽活动板房_集成打包箱房厂家-安徽玉强钢结构集成房屋有限公司 | 斗式提升机_链式斗提机_带式斗提机厂家无锡市鸿诚输送机械有限公司 | 变位机,焊接变位机,焊接变位器,小型变位机,小型焊接变位机-济南上弘机电设备有限公司 | 威客电竞(vk·game)·电子竞技赛事官网| 贵州科比特-防雷公司厂家提供贵州防雷工程,防雷检测,防雷接地,防雷设备价格,防雷产品报价服务-贵州防雷检测公司 | 蜜蜂职场文库_职场求职面试实用的范文资料大全 | 深圳彩钢板_彩钢瓦_岩棉板_夹芯板_防火复合彩钢板_长鑫 | 气密性检测仪_气密性检测设备_防水测试仪_密封测试仪-岳信仪器 | 没斑啦-专业的祛斑美白嫩肤知识网站-去斑经验分享 | 游戏版号转让_游戏资质出售_游戏公司转让-【八九买卖网】 | 福建珂朗雅装饰材料有限公司「官方网站」 |