【发布时间】:2015-10-09 08:22:28
【问题描述】:
前端开发的新手,我正在尝试使用早午餐构建基于主干的 web 应用程序。 一切都很顺利,直到我尝试使用名为node-xmpp-client 的节点模块。 这个模块有一个浏览器版本:node-xmpp-browser.js,它在我的谷歌浏览器中运行良好。
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 关键字)有冲突?
将这种浏览器化模块包含到基于早午餐的应用程序中的正确方法是什么?
非常感谢您的宝贵时间,
皮埃尔
【问题讨论】:
-
似乎brunch有自己的封装机制。剩下的问题是“如何将节点模块集成到在浏览器中运行的 Web 应用程序中?”
-
jspm.io 可能是解决方案...挖掘它...
-
我看到了许多用于早午餐应用程序的浏览器模块。工作很酷。所以,应该是绝对可以的。
标签: javascript backbone.js browserify brunch