From 8c366defaff6f933a727b05dc296f0e2a62d4eda Mon Sep 17 00:00:00 2001 From: Gavin Date: Sat, 27 Jan 2018 00:09:49 +0800 Subject: [PATCH] fix(store): product env cannot find module 'redux-devtools-extension'. (#3618) Problem description: - Cannot find module 'redux-devtools-extension' --- examples/with-redux-saga/store.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/examples/with-redux-saga/store.js b/examples/with-redux-saga/store.js index 2215a8ec..e8c7f7bc 100644 --- a/examples/with-redux-saga/store.js +++ b/examples/with-redux-saga/store.js @@ -1,5 +1,4 @@ import {createStore, applyMiddleware} from 'redux' -import {composeWithDevTools} from 'redux-devtools-extension' import withRedux from 'next-redux-wrapper' import nextReduxSaga from 'next-redux-saga' import createSagaMiddleware from 'redux-saga' @@ -9,11 +8,19 @@ import rootSaga from './saga' const sagaMiddleware = createSagaMiddleware() +const bindMiddleware = (middleware) => { + if (process.env.NODE_ENV !== 'production') { + const { composeWithDevTools } = require('redux-devtools-extension') + return composeWithDevTools(applyMiddleware(...middleware)) + } + return applyMiddleware(...middleware) +} + export function configureStore (initialState = exampleInitialState) { const store = createStore( rootReducer, initialState, - composeWithDevTools(applyMiddleware(sagaMiddleware)) + bindMiddleware([sagaMiddleware]) ) store.sagaTask = sagaMiddleware.run(rootSaga)