繁体   English   中英

如何将浏览器化的节点模块集成到早午餐构建的应用程序中?

[英]How to integrate a browserified node module into brunch-built app?

前端开发人员的新功能,我正在尝试通过早午餐构建基于主干的Webapp。 一切顺利,直到我尝试使用一个名为node-xmpp-client的节点模块。 该模块有一个浏览器版本: node-xmpp-browser.js在我的Google Chrome 浏览器中可以正常工作。

1-我试图将此node-xmpp-browser.js添加到供应商目录以使其捆绑到app.js中,但是在加载index.html页面时,在我的js控制台中发生以下错误:

Uncaught TypeError: require.register is not a function Uncaught
TypeError: require.register is not a function Uncaught TypeError:
loaderPath.indexOf is not a function

2-然后,我尝试将此脚本直接添加到我的index.html页中(node-xmpp-client浏览器示例也是如此):

<!DOCTYPE html>
<html lang="en">
<head>
  <title>My WebUI</title>
  <link rel="stylesheet" type="text/css" href="app.css">
  <meta name="viewport" content="width=device-width" initial-    scale="1.0">
</head>
<body>
  <div class='root-view'></div>
  <script src="node-xmpp-browser.js"></script>
  <script src='vendor.js'> </script>
  <script src='templates.js'> </script>
  <script src='app.js'> </script>
  <script> require('initialize');  </script>
</body>
</html>

但是控制台再次抱怨:

Uncaught TypeError: require.register is not a function
Uncaught TypeError: require.register is not a function
Uncaught Error: Cannot find module 'initialize'

似乎与如何在浏览器化脚本和早午餐构建脚本中声明模块(通过require关键字)存在冲突?

将这样的浏览器模块包含到基于早午餐的应用程序中的正确方法是什么?

非常感谢您的宝贵时间,

皮埃尔

您需要捆绑在客户端脚本中的require定义。 这是Brunch的默认设置,因此需要调整脚本标签的顺序,以便在require加载的任何脚本之前定义require ,或者您可以设置modules: definition: false在配置中为modules: definition: false

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM