简体   繁体   English

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

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

New with front end dev, i'm trying to build a backbone based webapp with brunch. 前端开发人员的新功能,我正在尝试通过早午餐构建基于主干的Webapp。 Everything's went fine until i tried to used a node module called node-xmpp-client . 一切顺利,直到我尝试使用一个名为node-xmpp-client的节点模块。 There's a browserified version of this module: node-xmpp-browser.js which works fine in my Google Chrome. 该模块有一个浏览器版本: node-xmpp-browser.js在我的Google Chrome 浏览器中可以正常工作。

1- I tried to add this node-xmpp-browser.js to vendor dir to have it bundled into app.js but the following error occurs in my js console when loading the index.html page: 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- Then, i tried to add this script into my index.html page directly (as does the node-xmpp-client browser example): 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>

But the console complains again: 但是控制台再次抱怨:

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

Seems that there's a conflict with how to declare a module (through require keyword) in a browserified script and a brunch built script? 似乎与如何在浏览器化脚本和早午餐构建脚本中声明模块(通过require关键字)存在冲突?

What is the correct way to include such a browserified module into a brunch based app ? 将这样的浏览器模块包含到基于早午餐的应用程序中的正确方法是什么?

Thanks a lot for your time, 非常感谢您的宝贵时间,

Pierre 皮埃尔

You need a require definition bundled into your client-side scripts. 您需要捆绑在客户端脚本中的require定义。 This comes by default in Brunch, so either the order of your script tags needs to be adjusted so that require is defined before any script that is expecting gets loaded, or you might be setting modules: definition: false in your config. 这是Brunch的默认设置,因此需要调整脚本标签的顺序,以便在require加载的任何脚本之前定义require ,或者您可以设置modules: definition: false在配置中为modules: definition: false

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

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