[英]How can I 'swap' react for react/addons in my application?
I want to use the Perf stuff. 我想使用Perf的东西。 It seems that if I do:
看来,如果我这样做:
var React = require('react/addons');
in my own modules then libraries (react-bootstrap, react-router etc.) end up using another copy of plain react and things break. 在我自己的模块中,然后库(react-bootstrap,react-router等)最终会使用另一份普通的react副本,并且事情中断了。 I am using browserify.
我正在使用browserify。
Is there a fix or another way to do this? 是否有解决方法或其他方法?
Requiring react
and react/addons
will give you the same object. 需要
react
和react/addons
将给您相同的对象。 react/addons
requires the same module that react
does ( lib/React
), and react/addons
even mutates that object so that anyone requiring react
will get the addons as well. react/addons
需要与react
相同的模块( lib/React
),而且react/addons
甚至会变异该对象,以便任何需要react
也能获得该addons。
If you end up with multiple versions of React in your bundle, it's because the libraries you use have react
as a dependency instead of a peer dependency. 如果你最终组合中的阵营的多个版本,那是因为你用有库
react
的依赖,而不是对依赖。 You should use npm dedupe
to avoid that. 您应该使用
npm dedupe
来避免这种情况。 But react-router
has react
as a peer dependency, so react-router
will get the same react
module instance as your module (with the addons). 但是
react-router
具有react
等依赖关系,因此react-router
将获得与您的模块相同的react
模块实例(带有插件)。 Don't know about the other packages you use that depend on React though. 虽然不知道您使用的其他依赖React的软件包。
It turns out the problem was with my gulpfile. 原来问题出在我的gulpfile。 Tx for the comments about looking for a browserify shim that lead me to the solution:
Tx提供有关寻找浏览器填充程序的评论,这些评论将我引向了解决方案:
My browserify task (from React JS workflow, part 2 ) builds separate vendors.js (libs) and main.js (my app) bundles during development using browserify.external(..) to exclude the libs from main.js. 我的browserify任务(来自React JS工作流,第2部分 )在开发过程中使用browserify.external(..)来构建单独的vendor.js(库)和main.js(我的应用)包,以将这些库从main.js中排除。 I just had to add "react/addons" as an external lib along with "react".
我只需要将“ react / addons”与“ react”一起添加为外部库。
The issue is explained here: 该问题在这里说明:
https://github.com/substack/node-browserify/issues/1161 https://github.com/substack/node-browserify/issues/1161
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.