Browserify-与外部模块创建捆绑包 [英] Browserify - create bundle with external module
问题描述
我真的是浏览器世界的新手。
我想使用此模块 peer-file ,以便允许两个浏览器之间的文件传输。将用法部分读入自述文件后,我注意到我必须在网页中包含脚本bundle.js。要构建捆绑包,我需要输入 browserify -r ./index.js> build.js
,其中 -r
选项表示外部需求,因此我可以在主脚本中使用关键字 require( )
,像这样:
I'm really new to browserify world.
I want to use this module peer-file, in order to allow the file transfer between two browsers. Reading the Usage section into readme, I note I have to include the script bundle.js in my web page. To build the bundle I need to type browserify -r ./index.js > build.js
, where -r
option means external require, so I can use in my main script the keyword require()
, like this:
var send = require('peer-file/send')
var receive = require('peer-file/receive')
但是,当我加载时在网页上,我在控制台中收到此错误。
未捕获的错误:找不到模块对等文件/发送
However, when I load the web page, I receive this error into the console.
Uncaught Error: Cannot find module 'peer-file/send'
有任何建议吗? p>
Any suggestion?
推荐答案
如果您查看索引文件- https://github.com/michaelrhodes/peer-file/blob/master/index.js
If you look at the index file - https://github.com/michaelrhodes/peer-file/blob/master/index.js
它将发送
和接收
添加到出口中。因此,您首先可以解决此问题,然后可以使用点符号来访问导出。
It adds send
and receive
to the exports. So you first get a handle to that, then you can access the exports with dot notation.
var send = require('peer-file').send;
var receive = require('peer-file').receive;
或者只获取一次:
var peerFile = require('peer-file');
// Later
peerFile.send..
peerFile.receive..
这篇关于Browserify-与外部模块创建捆绑包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!