2016-08-29 16 views
4

我工作的通用項目做出反應,我的客戶端入口點是:wepback 2熱重裝不是重新解析

import React from 'react' 
 
import {render} from 'react-dom' 
 
import {Provider} from 'react-redux' 
 
import {AppContainer} from 'react-hot-loader' 
 
import {Router, browserHistory} from 'react-router' 
 
import {syncHistoryWithStore} from 'react-router-redux' 
 
import {addLocaleData} from 'react-intl' 
 
import it from 'react-intl/locale-data/it' 
 
import en from 'react-intl/locale-data/en' 
 
import IntlProvider from 'shared/containers/IntlProvider' 
 
import configureStore from 'shared/configureStore' 
 
import routes from 'shared/routes' 
 
import {isDev, isLive} from 'shared/config' 
 

 
[en, it].forEach(addLocaleData) 
 

 
const hook = document.getElementById('app') 
 
const initialState = JSON.parse(hook.getAttribute('data-initial-state')) 
 
const store = configureStore(initialState) 
 
const history = syncHistoryWithStore(browserHistory, store) 
 
let content = (
 
    <Provider store={store}> 
 
    <IntlProvider key="intl"> 
 
     <Router history={history}> 
 
     {routes} 
 
     </Router> 
 
    </IntlProvider> 
 
    </Provider> 
 
) 
 

 
if (isLive) { 
 
    content = <AppContainer>{content}</AppContainer> 
 
} 
 

 
function renderApp() { 
 
    render(content, hook) 
 
} 
 

 
if (isLive) { 
 
    module.hot.accept('./index.js') 
 
    module.hot.accept('../shared/routes', renderApp) 
 
} 
 

 
renderApp()

在成分的變化,重裝似乎工作,但沒有渲染應用.. 也許它發生在熱重載技巧發生之前?

console output

注意我的路由配置是現在經典的非dymanic路線。

回答

0

我有同樣的問題,因爲我只是忘了爲模塊代替

if (module.hot) { 
module.hot.accept(
    "./App", 
    () => { 
     const NextApp = require("./App").App; // THIS LINE 
     render(NextApp); 
    }, 
); 

}

添加代碼