Tag: expressjs

错误在找不到模块'babel-core'。 使用react.js,webpack和express服务器

每当我在terminal上运行webpack时,我会得到: Hash: efea76b1048c3a97b963 Version: webpack 1.12.13 Time: 33ms + 1 hidden modules ERROR in Cannot find module 'babel-core' 这是我的webpack.config.js文件 module.exports = { entry: './app-client.js', output: { filename: 'public/bundle.js' }, module: { loaders: [ { exclude: /(node_modules|app-server.js)/, loader: 'babel' } ] } } 的package.json { "name": "react", "version": "1.0.0", "description": "React polling app", "main": "app-client.js", "dependencies": […]

React + Flux和服务器端渲染? (同构反应+通量)

用同构应用程序设置应用程序初始状态的一般做法是什么? 没有通量我会简单地使用像这样的东西: var props = { }; // initial state var html = React.renderToString(MyComponent(props); 然后通过快速 {{{reactMarkup}}呈现该标记,并通过{{{reactMarkup}} 。 在客户端设置初始状态,我会做这样的事情: if (typeof window !== 'undefined') { var props = JSON.parse(document.getElementById('props').innerHTML); React.render(MyComponent(props), document.getElementById('reactMarkup')); } 所以,基本上你是在服务器和客户端设置了两次状态,不过React会比较差异,在大多数情况下,不会因为重新渲染而影响性能。 如果您在Flux架构中采取行动和存储,这个原则将如何工作? 在我的组件内我可以这样做: getInitialState: function() { return AppStore.getAppState(); } 但是现在我怎么从服务器设置AppStore的初始状态呢? 如果我使用React.renderToString没有传递的属性,它会调用AppStore.getAppState() ,它不会有任何东西,因为我仍然不明白我将如何设置我的商店在服务器上的状态? 2015年2月5日更新 我仍然在寻找一个干净的解决scheme,不涉及使用Fluxible,Fluxxor,Reflux等第三方Flux实现。 2016年8月19日更新 使用Redux 。