text: import { createStore, compose, applyMiddleware } from 'redux';
  import reduxImmutableStateInvariant from 'redux-immutable-state-invariant';
  import thunk from 'redux-thunk';
  import createHistory from 'history/createBrowserHistory';
  import { actionsMiddleware } from '../utils/Middlewares';
  
  // 'routerMiddleware': the new way of storing route changes with redux middleware since rrV4.
  import { connectRouter, routerMiddleware } from 'connected-react-router';
  import rootReducer from '../reducers';
  
  export const history = createHistory();
  const connectRouterHistory = connectRouter(history);
  
  function configureStoreProd(initialState) {
    const reactRouterMiddleware = routerMiddleware(history);
    const middlewares = [
      // Add other middleware on this line...
  
      // thunk middleware can also accept an extra argument to be passed to each thunk action
      // https://github.com/reduxjs/redux-thunk#injecting-a-custom-argument
      thunk,
      reactRouterMiddleware,
      actionsMiddleware,
    ];
  
    return createStore(rootReducer(history), initialState, compose(applyMiddleware(...middlewares)));
  }
  
  function configureStoreDev(initialState) {
    const reactRouterMiddleware = routerMiddleware(history);
    const middlewares = [
      // Add other middleware on this line...
  
      // Redux middleware that spits an error on you when you try to mutate your state either inside a dispatch or between dispatches.
      reduxImmutableStateInvariant(),
  
      // thunk middleware can also accept an extra argument to be passed to each thunk action
      // https://github.com/reduxjs/redux-thunk#injecting-a-custom-argument
      thunk,
      reactRouterMiddleware,
      actionsMiddleware,
    ];
  
    const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; // add support for Redux dev tools
    const store = createStore(
      rootReducer(history),
      initialState,
      composeEnhancers(applyMiddleware(...middlewares))
    );
  
    if (module.hot) {
      // Enable Webpack hot module replacement for reducers
      module.hot.accept('../reducers', () => {
        const nextRootReducer = require('../reducers').default; // eslint-disable-line global-require
        store.replaceReducer(connectRouterHistory(nextRootReducer));
      });
    }
  
    return store;
  }
  
  const configureStore =
    process.env.NODE_ENV === 'production' ? configureStoreProd : configureStoreDev;
  
  export default configureStore;
  