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

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

  • <tfoot id='tVGQP'></tfoot>
    1. <legend id='tVGQP'><style id='tVGQP'><dir id='tVGQP'><q id='tVGQP'></q></dir></style></legend>

        <i id='tVGQP'><tr id='tVGQP'><dt id='tVGQP'><q id='tVGQP'><span id='tVGQP'><b id='tVGQP'><form id='tVGQP'><ins id='tVGQP'></ins><ul id='tVGQP'></ul><sub id='tVGQP'></sub></form><legend id='tVGQP'></legend><bdo id='tVGQP'><pre id='tVGQP'><center id='tVGQP'></center></pre></bdo></b><th id='tVGQP'></th></span></q></dt></tr></i><div class="lr9nfvp" id='tVGQP'><tfoot id='tVGQP'></tfoot><dl id='tVGQP'><fieldset id='tVGQP'></fieldset></dl></div>
        • <bdo id='tVGQP'></bdo><ul id='tVGQP'></ul>

        在“管道"之間傳遞變量在吞咽

        Passing variables between quot;pipesquot; in Gulp(在“管道之間傳遞變量在吞咽)
        <i id='hwvWs'><tr id='hwvWs'><dt id='hwvWs'><q id='hwvWs'><span id='hwvWs'><b id='hwvWs'><form id='hwvWs'><ins id='hwvWs'></ins><ul id='hwvWs'></ul><sub id='hwvWs'></sub></form><legend id='hwvWs'></legend><bdo id='hwvWs'><pre id='hwvWs'><center id='hwvWs'></center></pre></bdo></b><th id='hwvWs'></th></span></q></dt></tr></i><div class="ddfhtll" id='hwvWs'><tfoot id='hwvWs'></tfoot><dl id='hwvWs'><fieldset id='hwvWs'></fieldset></dl></div>

          • <bdo id='hwvWs'></bdo><ul id='hwvWs'></ul>
              <tbody id='hwvWs'></tbody>

            <legend id='hwvWs'><style id='hwvWs'><dir id='hwvWs'><q id='hwvWs'></q></dir></style></legend>

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

              <tfoot id='hwvWs'></tfoot>
                  本文介紹了在“管道"之間傳遞變量在吞咽的處理方法,對大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

                  我正在嘗試編寫一個(gè) gulp 任務(wù),該任務(wù)通過 gulp-prompt 插件獲取一些用戶輸入.但我無法將該輸入傳遞給其他例如:

                  I'm trying to write a gulp tasks that takes some user input via the gulp-prompt plugin. But I'm having trouble passing that input along to other eg:

                  gulp.task('userinput', function(){
                  
                      var myVar = 'MONKEY';
                  
                      gulp.src('./templates/_component.*')
                      .pipe(prompt.prompt([
                          {
                              type: 'input',
                              name: 'userInput',
                              message: 'Say something'
                          }
                      ], function(res){
                          myVar = res.userInput;
                      }))
                      .pipe(prompt.confirm('You said ' + myVar));
                  });
                  

                  假設(shè)我在提示符處輸入 hello,我希望確認(rèn)會說 You said Hello,但它說的是 You said MONKEY.

                  Assuming I enter hello at the prompt, I was expecting the confirmation to say You said Hello, but it says You said MONKEY.

                  Gulp 可以做到這一點(diǎn)嗎?

                  Is this possible with Gulp?

                  推薦答案

                  這里的問題是你正在創(chuàng)建第二個(gè)提示 ('You said ' + myVar) before 第一個(gè)提示已執(zhí)行:

                  The issue here is that you are creating the second prompt ('You said ' + myVar) before the first prompt has been executed:

                  1. myVar 設(shè)置為 'MONKEY'
                  2. 創(chuàng)建信息流
                  1. Set myVar to 'MONKEY'
                  2. Create streams
                  1. 創(chuàng)建 src 流,這是異步的
                  2. 創(chuàng)建第一個(gè)提示,并將其添加到 src 流中
                  3. 使用 myVar 的當(dāng)前值創(chuàng)建第二個(gè)提示,并將其添加到第一個(gè)提示流中
                  1. Create src stream, which is asynchronous
                  2. Create first prompt, and add it to the src stream
                  3. Create second prompt using current value of myVar, and add it to the first prompt stream

                • 現(xiàn)在才處理執(zhí)行的流

                • Only now are the streams executed processed

                  1. 加載源
                  2. 運(yùn)行第一個(gè)提示,設(shè)置myVar
                  3. 使用之前生成的消息運(yùn)行第二個(gè)提示

                • <小時(shí)>

                  如果您想將其全部保留為單個(gè)流,唯一的解決方案是在允許閉包(函數(shù))的東西中使用變量.一些插件已經(jīng)接受閉包作為參數(shù),但大多數(shù)不接受.


                  The only solution if you want to keep it all as a single stream is to use the variable within something that allows for a closure (function). Some plugins already accept a closure as an argument, but most don't.

                  將流包裝在閉包中的一種解決方案是 gulp-tap,它不是專門為這種情況設(shè)計(jì)的,但應(yīng)該可以工作.它看起來像這樣:

                  One solution to wrap a stream in a closure that would work here is gulp-tap, which isn't designed for this scenario specifically, but should work. it looks like this:

                  var tap = require('gulp-tap');
                  
                  //...
                  
                  gulp.task('userinput', function(){
                  
                      var myVar = 'MONKEY';
                  
                      gulp.src('./templates/_component.*')
                      .pipe(prompt.prompt([
                          {
                              type: 'input',
                              name: 'userInput',
                              message: 'Say something'
                          }
                      ], function(res){
                          myVar = res.userInput;
                      }))
                      .pipe(tap(function(file, t) {
                          // format is t.through(stream-function, [arguments...])
                          return t.through(prompt.confirm, ['You said ' + myVar]);
                      });
                  });
                  

                  因?yàn)樗话b在一個(gè)閉包中,并且針對每個(gè)文件進(jìn)行評估,所以它將獲取變量的 current 值.但是,因?yàn)樗m用于每個(gè)文件,所以您會看到處理 每個(gè) 文件的提示一次.

                  Because this is wrapped in a closure, and evaluated for each file, it will pick up the current value for the variable. However, because it works on each file, you'll see the prompt once for each file processed.

                  更好的解決方案是將您的任務(wù)分成多個(gè)相互依賴的任務(wù).看起來像這樣:

                  An better solution would be to separate your task into multiple, dependent tasks. That would look something like this:

                  var myVar = 'MONKEY';
                  
                  gulp.task('userinput1', function(){
                  
                      return gulp.src('./templates/_component.*', {read: false})
                          .pipe(prompt.prompt([
                              {
                                  type: 'input',
                                  name: 'userInput',
                                  message: 'Say something'
                              }
                          ], function(res){
                              myVar = res.userInput;
                          }));
                  });
                  
                  gulp.task('userinput', ['userinput1'], function() {
                      return gulp.src('./templates/_component.*')
                          .pipe(prompt.confirm('You said ' + myVar));
                  });
                  

                  現(xiàn)在第一個(gè)任務(wù) (userinput1) 將運(yùn)行并完成第二個(gè)任務(wù)被處理 (userinput2),所以變量將是設(shè)置正確.

                  Now the first task (userinput1) will run and complete before the second one is processed (userinput2), so the variable will be set correctly.

                  注意:確保從您的任務(wù)中return流,否則它們會被同步處理,并且您的變量不會被設(shè)置.

                  NOTE: Make sure you return the stream from your tasks, otherwise they are processed synchronously, and your variable won't get set.

                  <小時(shí)>

                  最后,完全放棄 gulp-prompt 任務(wù)可能更有意義,因?yàn)樗c流沒有太大關(guān)系.您最好在任務(wù)中直接使用 Node JavaScript 來收集用戶的輸入(最好以同步方式),然后在 gulp-stream 中處理您的文件.


                  Finally, it might make more sense to forgo the gulp-prompt task altogether, because it doesn't really have much to do with the stream. You'd probably be better off using straight Node JavaScript within your task to gather the user's input (preferably in a synchronous manner), then processing your files in a gulp-stream after that.

                  這篇關(guān)于在“管道"之間傳遞變量在吞咽的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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ù))
                  Stylesheet not loaded because of MIME-type(由于 MIME 類型而未加載樣式表)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時(shí) Visual Studio 2015 崩潰)
                    <tbody id='5A7OI'></tbody>

                  <small id='5A7OI'></small><noframes id='5A7OI'>

                        <bdo id='5A7OI'></bdo><ul id='5A7OI'></ul>
                        <legend id='5A7OI'><style id='5A7OI'><dir id='5A7OI'><q id='5A7OI'></q></dir></style></legend>

                          • <i id='5A7OI'><tr id='5A7OI'><dt id='5A7OI'><q id='5A7OI'><span id='5A7OI'><b id='5A7OI'><form id='5A7OI'><ins id='5A7OI'></ins><ul id='5A7OI'></ul><sub id='5A7OI'></sub></form><legend id='5A7OI'></legend><bdo id='5A7OI'><pre id='5A7OI'><center id='5A7OI'></center></pre></bdo></b><th id='5A7OI'></th></span></q></dt></tr></i><div class="lb77vhp" id='5A7OI'><tfoot id='5A7OI'></tfoot><dl id='5A7OI'><fieldset id='5A7OI'></fieldset></dl></div>
                            <tfoot id='5A7OI'></tfoot>

                          • 主站蜘蛛池模板: 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 防水套管-柔性防水套管-刚性防水套管-上海执品管件有限公司 | 小小作文网_中小学优秀作文范文大全 | 天津热油泵_管道泵_天津高温热油泵-天津市金丰泰机械泵业有限公司【官方网站】 | 深圳诚暄fpc首页-柔性线路板,fpc柔性线路板打样生产厂家 | uv固化机-丝印uv机-工业烤箱-五金蚀刻机-分拣输送机 - 保定市丰辉机械设备制造有限公司 | 杭州代理记账多少钱-注册公司代办-公司注销流程及费用-杭州福道财务管理咨询有限公司 | 直流大电流电源,燃料电池检漏设备-上海政飞 | 压缩空气冷冻式干燥机_吸附式干燥机_吸干机_沪盛冷干机 | 304不锈钢无缝管_不锈钢管厂家 - 隆达钢业集团有限公司 | 深圳公司注册-工商注册公司-千百顺代理记账公司 | 国资灵活用工平台_全国灵活用工平台前十名-灵活用工结算小帮手 | 汽液过滤网厂家_安平县银锐丝网有限公司 | 中矗模型-深圳中矗模型设计有限公司 | 上海璟文空运首页_一级航空货运代理公司_机场快递当日达 | 微量水分测定仪_厂家_卡尔费休微量水分测定仪-淄博库仑 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 带压开孔_带压堵漏_带压封堵-菏泽金升管道工程有限公司 | 压力变送器-上海武锐自动化设备有限公司 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 列管冷凝器,刮板蒸发器,外盘管反应釜厂家-无锡曼旺化工设备有限公司 | 工业雾炮机_超细雾炮_远程抑尘射雾器-世纪润德环保设备 | 水冷散热器_水冷电子散热器_大功率散热器_水冷板散热器厂家-河源市恒光辉散热器有限公司 | 杭州用友|用友软件|用友财务软件|用友ERP系统--杭州协友软件官网 | 水篦子|雨篦子|镀锌格栅雨水篦子|不锈钢排水篦子|地下车库水箅子—安平县云航丝网制品厂 | 自动化生产线-自动化装配线-直流电机自动化生产线-东莞市慧百自动化有限公司 | 合肥仿石砖_合肥pc砖厂家_合肥PC仿石砖_安徽旭坤建材有限公司 | 私人别墅家庭影院系统_家庭影院音响_家庭影院装修设计公司-邦牛影音 | 生鲜配送系统-蔬菜食材配送管理系统-连锁餐饮订货配送软件-挪挪生鲜供应链管理软件 | 不锈钢列管式冷凝器,换热器厂家-无锡飞尔诺环境工程有限公司 | 天空彩票天下彩,天空彩天空彩票免费资料,天空彩票与你同行开奖,天下彩正版资料大全 | 电动高尔夫球车|电动观光车|电动巡逻车|电动越野车厂家-绿友机械集团股份有限公司 | 招商帮-一站式网络营销服务|互联网整合营销|网络推广代运营|信息流推广|招商帮企业招商好帮手|搜索营销推广|短视视频营销推广 | 鼓风干燥箱_真空烘箱_高温干燥箱_恒温培养箱-上海笃特科学仪器 | 120kv/2mA直流高压发生器-60kv/2mA-30kva/50kv工频耐压试验装置-旭明电工 | 液压油缸-液压缸厂家价格,液压站系统-山东国立液压制造有限公司 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 台式低速离心机-脱泡离心机-菌种摇床-常州市万丰仪器制造有限公司 | 吊篮式|移动式冷热冲击试验箱-二槽冷热冲击试验箱-广东科宝 | 电气控制系统集成商-PLC控制柜变频控制柜-非标自动化定制-电气控制柜成套-NIDEC CT变频器-威肯自动化控制 | 合肥花魁情感婚姻咨询中心_挽回爱情_修复婚姻_恋爱指南 | 烽火安全网_加密软件、神盾软件官网 |