我想在Web应用程序中启用“热模块替换”,这样可以加快开发时间。
我关注了这篇文章:https://duske.me/setting-up-hot-module-replacement-with-create-react-app-and-redux/
然后我重新编写了index.js
import React from 'react';
import ReactDOM from 'react-dom';
import {render} from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import {Provider,connect} from 'react-redux';
import FirebaseConfig from './FirebaseConfig';
import firebase from 'firebase';
import configureStore from './configureStore';
firebase.initializeApp(FirebaseConfig);
const store = configureStore();
render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
serviceWorker.unregister();
并且我创建了 configureStore.js :
import {createStore,applyMiddleware} from 'redux';
import reducer from './reducers';
import thunk from 'redux-thunk';
import {composeWithDevTools} from 'redux-devtools-extension' // REDUX DEVTOOLS
const configureStore = ()=> {
const store = createStore(reducer,composeWithDevTools(applyMiddleware(thunk)));
if (module.hot) {
module.hot.accept('./reducers/index', () => {
const nextRootReducer = require('./reducers/index').default;
store.replaceReducer(nextRootReducer);
});
}
return store
}
export default configureStore;
PS。 “ reducers / index.js”是我的rootreducer的默认导出文件(通过将所有reducer与CombineReducers()结合使用)
但是似乎没有任何效果。 我错过了什么 ?