| 12 | } |
| 13 | |
| 14 | export function configureStore(initialState = {}) { |
| 15 | // Middleware and store enhancers |
| 16 | const enhancers = [ |
| 17 | applyMiddleware(thunk), |
| 18 | ]; |
| 19 | |
| 20 | if (process.env.CLIENT && process.env.NODE_ENV === 'development') { |
| 21 | // Enable DevTools only when rendering on client and during development. |
| 22 | enhancers.push(window.devToolsExtension ? window.devToolsExtension() : DevTools.instrument()); |
| 23 | } |
| 24 | |
| 25 | const store = createStore(rootReducer, initialState, compose(...enhancers)); |
| 26 | |
| 27 | // For hot reloading reducers |
| 28 | if (module.hot) { |
| 29 | // Enable Webpack hot module replacement for reducers |
| 30 | module.hot.accept('./reducers', () => { |
| 31 | const nextReducer = require('./reducers').default; // eslint-disable-line global-require |
| 32 | store.replaceReducer(nextReducer); |
| 33 | }); |
| 34 | } |
| 35 | |
| 36 | return store; |
| 37 | } |