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

  • <small id='gWKXA'></small><noframes id='gWKXA'>

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

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

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

        <tfoot id='gWKXA'></tfoot>
      1. 從 gulp 中使用 browserify 時如何向瀏覽器公開“要

        How to expose #39;require#39; to the browser when using browserify from within gulp?(從 gulp 中使用 browserify 時如何向瀏覽器公開“要求?)
        <tfoot id='syPx8'></tfoot><legend id='syPx8'><style id='syPx8'><dir id='syPx8'><q id='syPx8'></q></dir></style></legend>

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

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

            <i id='syPx8'><tr id='syPx8'><dt id='syPx8'><q id='syPx8'><span id='syPx8'><b id='syPx8'><form id='syPx8'><ins id='syPx8'></ins><ul id='syPx8'></ul><sub id='syPx8'></sub></form><legend id='syPx8'></legend><bdo id='syPx8'><pre id='syPx8'><center id='syPx8'></center></pre></bdo></b><th id='syPx8'></th></span></q></dt></tr></i><div class="myym2sk" id='syPx8'><tfoot id='syPx8'></tfoot><dl id='syPx8'><fieldset id='syPx8'></fieldset></dl></div>
                <tbody id='syPx8'></tbody>
                • 本文介紹了從 gulp 中使用 browserify 時如何向瀏覽器公開“要求"?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  限時送ChatGPT賬號..

                  當我有一個看起來像這樣的文件 x.js 時:

                  When I have a file x.js that looks like this:

                  x.js

                  module.exports = function (n) { return n * 111 }
                  

                  然后我像這樣從命令行運行 browserify:

                  and I run browserify from the command line like so:

                  browserify -r ./x.js > bundle.js
                  

                  我得到一個看起來像這樣的輸出文件(大致):

                  I get an output file that looks like this (roughly):

                  require=(function e(t,n,r){function ......
                  ./App.jsx":[function(require,module,exports){
                  module.exports=require('0+DPR/');
                  },{}]},{},[])
                  

                  然后在我的瀏覽器代碼中我可以這樣做:

                  Then in my browser code I can do this:

                  <html>
                    <head>
                      <title>React server rendering example</title>
                      <script src="static/bundle.js"></script>
                    </head>
                    <body>
                      Welcome to the React server rendering example. Here is a server-rendered React component:
                      <div id="53a442ff8b39d"></div><script>
                      var x = require('./x.js');
                      console.log(x(3))
                  </script>  </body>
                  </html>
                  

                  我其實有兩個問題:

                  1) 這在瀏覽器中不太有效我收到錯誤:未捕獲的錯誤:找不到模塊'./x.js'".為什么會這樣?

                  1) This doesn't quite work in the browser I get the error: "Uncaught Error: Cannot find module './x.js'". Why is that happening?

                  2) 我實際上想使用乙烯基源流在 gulp 中運行它.我試過在我的 gulpfile 中做這樣的事情,但它不起作用.有任何想法嗎?我收到錯誤未定義要求"

                  2) I actually want to run this in gulp using vinyl-source-stream. I've tried doing something like this in my gulpfile but it doesn't work. Any ideas? I get the error 'require is not defined'

                  var   gulp = require('gulp'),
                    browserify = require('browserify'),
                    source = require('vinyl-source-stream');
                  
                  var b = browserify({
                      entries: ['./x.js'],
                    });
                     b.bundle({debug: false})
                     .pipe(source('bundle.js'))
                     .pipe(gulp.dest('./build'));
                  

                  推薦答案

                  更新:您可以在 -r 開關中引用別名

                  Update: You can reference an alias in your -r switch

                  試試:browserify -r ./x.js:my-module >bundle.js

                  在你的頁面中:var x = require('my-module');

                  注意:如果您在 fsthrough 等節(jié)點模塊上使用 -r 開關,則不需要為這些模塊設置別名,因為它們通常有名稱在他們的 package.json 文件中.

                  NOTE: if you used an -r switch on a node module like fs or through, you don't need an alias for these because they usually have a name in their package.json file.

                  參見node-browserify -- 外部要求 了解更多信息.

                  See node-browserify -- external requires for more info.

                  如果你打算像這樣(使用 -r 開關)捆綁你的 x.js,有幾個選項

                  If you are going to bundle your x.js like that (with -r switch) there are a couple of options

                  1) 將腳本放入您的 html 頁面并單獨捆綁.

                  1) Take the script in your html page and bundle it separately.

                        創(chuàng)建一個 ma??in.js 文件并將你的 JS 放入其中.

                        Create a main.js file and put your JS in it.

                        使用browserify -x ./x.js >main.js

                        Use browserify -x ./x.js > main.js

                        通過使用 -x 開關,Browserify 會將您的 bundle.js 作為依賴項鏈接.

                        By using the -x switch, Browserify will link your bundle.js in as a dependancy.

                        然后在你的頁面中引用這兩個JS文件.

                        Then reference both JS files in your page.

                  2) 使用 Browserify 生成的名稱.

                  2) Use name generated by Browserify.

                        var x = require('0+DPR/');

                        var x = require('0+DPR/');

                        請參閱上面的更新以創(chuàng)建別名.

                        See Update above to create an alias.

                  下面是很好的資源,因為您希望通過 Gulp 走得更遠

                  Good resource below since you are looking to go further with Gulp

                  • Browserify - 將 Nodejs 模塊帶到瀏覽器

                  更多 Gulp + Browserify(使用 Watchify 以及 livereload)查看 Viget 上的博客文章

                  For more Gulp + Browserify (uses Watchify as well for livereload) Check out blog post on Viget

                  • Gulp + Browserify:所有帖子

                  這篇關于從 gulp 中使用 browserify 時如何向瀏覽器公開“要求"?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 任務)
                  Stylesheet not loaded because of MIME-type(由于 MIME 類型而未加載樣式表)
                  Visual Studio 2015 crashes when opening Javascript files(打開 Javascript 文件時 Visual Studio 2015 崩潰)
                • <tfoot id='9RdAq'></tfoot>

                    <tbody id='9RdAq'></tbody>
                  <legend id='9RdAq'><style id='9RdAq'><dir id='9RdAq'><q id='9RdAq'></q></dir></style></legend>

                      <small id='9RdAq'></small><noframes id='9RdAq'>

                      <i id='9RdAq'><tr id='9RdAq'><dt id='9RdAq'><q id='9RdAq'><span id='9RdAq'><b id='9RdAq'><form id='9RdAq'><ins id='9RdAq'></ins><ul id='9RdAq'></ul><sub id='9RdAq'></sub></form><legend id='9RdAq'></legend><bdo id='9RdAq'><pre id='9RdAq'><center id='9RdAq'></center></pre></bdo></b><th id='9RdAq'></th></span></q></dt></tr></i><div class="022c0qw" id='9RdAq'><tfoot id='9RdAq'></tfoot><dl id='9RdAq'><fieldset id='9RdAq'></fieldset></dl></div>
                        <bdo id='9RdAq'></bdo><ul id='9RdAq'></ul>
                          • 主站蜘蛛池模板: 密集架|电动密集架|移动密集架|黑龙江档案密集架-大量现货厂家销售 | 伟秀电气有限公司-10kv高低压开关柜-高低压配电柜-中置柜-充气柜-欧式箱变-高压真空断路器厂家 | 手板_手板模型制作_cnc手板加工厂-东莞天泓 | 广州活动策划公司-15+年专业大型公关活动策划执行管理经验-睿阳广告 | LED太阳能中国结|发光红灯笼|灯杆造型灯|节日灯|太阳能灯笼|LED路灯杆装饰造型灯-北京中海轩光电 | 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 软膜天花_软膜灯箱_首选乐创品牌_一站式天花软膜材料供应商! | 广州二手电缆线回收,旧电缆回收,广州铜线回收-广东益福电缆线回收公司 | 掺铥光纤放大器-C/L波段光纤放大器-小信号光纤放大器-合肥脉锐光电技术有限公司 | 砂石生产线_石料生产线设备_制砂生产线设备价格_生产厂家-河南中誉鼎力智能装备有限公司 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 驾驶式洗地机/扫地机_全自动洗地机_工业洗地机_荣事达工厂官网 | 重庆网站建设,重庆网站设计,重庆网站制作,重庆seo,重庆做网站,重庆seo,重庆公众号运营,重庆小程序开发 | 双能x射线骨密度检测仪_dxa骨密度仪_双能x线骨密度仪_品牌厂家【品源医疗】 | 测试治具|过炉治具|过锡炉治具|工装夹具|测试夹具|允睿自动化设备 | 不锈钢反应釜,不锈钢反应釜厂家-价格-威海鑫泰化工机械有限公司 不干胶标签-不干胶贴纸-不干胶标签定制-不干胶标签印刷厂-弗雷曼纸业(苏州)有限公司 | 河南道路标志牌_交通路标牌_交通标志牌厂家-郑州路畅交通 | 济南菜鸟驿站广告|青岛快递车车体|社区媒体-抖音|墙体广告-山东揽胜广告传媒有限公司 | 不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰]-不锈钢法兰-碳钢法兰-法兰盘生产加工厂家-[鼎捷峰] | 专注氟塑料泵_衬氟泵_磁力泵_卧龙泵阀_化工泵专业品牌 - 梭川泵阀 | 郑州水质检测中心_井水检测_河南废气检测_河南中环嘉创检测 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | 江苏齐宝进出口贸易有限公司 | 诗词大全-古诗名句 - 古诗词赏析| 撕碎机,撕破机,双轴破碎机-大件垃圾破碎机厂家 | 安全,主动,被动,柔性,山体滑坡,sns,钢丝绳,边坡,防护网,护栏网,围栏,栏杆,栅栏,厂家 - 护栏网防护网生产厂家 | 运动木地板价格,篮球馆体育运动木地板生产厂家_欧氏地板 | 对照品_中药对照品_标准品_对照药材_「格利普」高纯中药标准品厂家-成都格利普生物科技有限公司 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库 | Eiafans.com_环评爱好者 环评网|环评论坛|环评报告公示网|竣工环保验收公示网|环保验收报告公示网|环保自主验收公示|环评公示网|环保公示网|注册环评工程师|环境影响评价|环评师|规划环评|环评报告|环评考试网|环评论坛 - Powered by Discuz! | 国资灵活用工平台_全国灵活用工平台前十名-灵活用工结算小帮手 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 杰福伦_磁致伸缩位移传感器_线性位移传感器-意大利GEFRAN杰福伦-河南赉威液压科技有限公司 | 外观设计_设备外观设计_外观设计公司_产品外观设计_机械设备外观设计_东莞工业设计公司-意品深蓝 | 气动隔膜泵-电动隔膜泵-循环热水泵-液下排污/螺杆/管道/化工泵「厂家」浙江绿邦 | 吉祥新世纪铝塑板_生产铝塑板厂家_铝塑板生产厂家_临沂市兴达铝塑装饰材料有限公司 | 登车桥动力单元-非标液压泵站-非标液压系统-深圳市三好科技有限公司 | 苏州西装定制-西服定制厂家-职业装定制厂家-尺品服饰西装定做公司 | 考试试题_试卷及答案_诗词单词成语 - 优易学 | 安徽净化板_合肥岩棉板厂家_玻镁板厂家_安徽科艺美洁净科技有限公司 | 北京包装设计_标志设计公司_包装设计公司-北京思逸品牌设计 | 中央空调温控器_风机盘管温控器_智能_液晶_三速开关面板-中央空调温控器厂家 |