使用react-hot-loader 3和自己的服务器

时间:2016-09-10 18:39:41

标签: node.js reactjs webpack webpack-dev-server react-hot-loader

我能够设置react-hot-loader以正确捆绑我的客户端js并将更改推送到浏览器并在那里应用([react-router] You cannot change <Router routes>; it will be ignored警告除外)。 我正在使用自己的服务器koakoa-webpack-dev-middlewarekoa-webpack-hot-middleware来处理webpack和hot。它还使用此代码处理我的应用程序的服务器呈现

export default function *renderReact() {
  const history = createMemoryHistory();
  const store   = makeStore(history);

  const [redirectLocation, renderProps] = yield match.bind(null, { routes, location: this.url, history });

  if (redirectLocation) {
    return this.redirect(redirectLocation.pathname + redirectLocation.search)
  }

  if (renderProps == null) {
    return this.throw(404, 'Not found')
  }

  const rootElement = (
    <Provider store={store} key="provider">
      <RouterContext {...renderProps} />
    </Provider>
  );

  this.body = renderApp({
    html:  yield store.renderToString(ReactDOMServer, rootElement),
    state: JSON.stringify(store.getState())
  });
}

问题在于我的服务器端代码:hot仅适用于客户端代码并动态更新更改,但我的服务器代码无法更新,因为在服务器启动时加载的脚本和页面重新加载我没有从服务器更新渲染页面,然后用新客户端代码更新。 并反应警告Warning: React attempted to reuse markup in a container but the checksum was invalid... 问题是:如何处理与服务器上的服务器呈现部分相关的代码更改,而不是在重新启动热负载时重新启动应用程序?

0 个答案:

没有答案