使用browserify运行ReactJS.NET [英] Running ReactJS.NET with browserify

查看:89
本文介绍了使用browserify运行ReactJS.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力从演示页面<上使Browserify与ReactJS .NET MVC设置一起使用。 / a>。

I'm struggling to get Browserify working with the ReactJS .NET MVC setup from the demo page.

在服务器上使用 .jsx 文件进行渲染时,一切正常(不使用require() ),但是当我使用Browserify捆绑包时,出现以下错误:

Everything works when rendering on the server with a .jsx file (not using require()), but when I use my Browserify bundle I get an error of:


类型为'React.Exceptions.ReactInvalidComponentException'的异常发生在React.dll,但未在用户代码中处理。
其他信息:找不到名为 CommentBox的组件。您是否忘了将其添加到App_Start\ReactConfig.cs中?

An exception of type 'React.Exceptions.ReactInvalidComponentException' occurred in React.dll but was not handled in user code. Additional information: Could not find a component named 'CommentBox'. Did you forget to add it to App_Start\ReactConfig.cs?

这是我的视图:

@Html.React("CommentBox", new
{
    initialData = Model
})
<script src="http://fb.me/react-0.12.2.js"></script>
<script src="src/to/bundle.js"></script>
@Html.ReactInitJavaScript()

ReactInitJavascript()编译为:

<script>React.render(React.createElement(CommentBox, {"initialData":[{"Author":"Daniel Lo Nigro","Text":"Hello ReactJS.NET World!"},{"Author":"Pete Hunt","Text":"This is one comment"}]}), document.getElementById("react1"));

我认为未定义 CommentBox 是因为它无法从Browserify捆绑包中访问,是否有一种简单的方法公开组件?

I assume that CommentBox is not defined because it is not accessible from the Browserify bundle, is there a simple way to expose a component?

我正在命令行上运行browserify任务,因此有任何建议

I'm running my browserify task on the command-line so any suggestions for that would be helpful.

推荐答案

您需要全局公开该组件,以便可以从服务器端代码对其进行访问。 。我没有用Browserify尝试过,但是ReactJS.NET文档确实涵盖了如何使用Webpack做到这一点: http ://reactjs.net/guides/webpack.html

You need to expose the component globally, so that it can be accessed from the server-side code. I haven't tried it with Browserify, but the ReactJS.NET documentation does cover how to do this with Webpack: http://reactjs.net/guides/webpack.html

这篇关于使用browserify运行ReactJS.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆