我正在使用Redux和Rematch,因为它提供了Redux Saga和Redux Thunk开箱即用的功能,但是我无法将其与Redux Devtools断开连接。顾名思义,devtools应该仅在开发过程中才可见或可访问,而不是在生产中。我不希望我的最终用户与州和调度员打交道,也不希望看到幕后发生的事情。
是否可以在生产版本中隐藏Redux Devtools或断开其连接?
为了从devtools中隐藏Redux,请注意以下代码:
import { createStore, applyMiddleware, compose } from 'redux';
import createSagaMiddleware from 'redux-saga';
import reducer from '~/redux/reducers';
import mySaga from '~/redux/sagas';
import { nodeEnv } from '~/utils/config';
const composeEnhancers =
(nodeEnv !== 'production' &&
typeof window !== 'undefined' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
compose;
const sagaMiddleware = createSagaMiddleware();
export default createStore(
reducer,
composeEnhancers(applyMiddleware(sagaMiddleware))
);
sagaMiddleware.run(mySaga);
这是Redux和Redux-Saga之间的集成,不重要的是:
const composeEnhancers =
(nodeEnv !== 'production' &&
typeof window !== 'undefined' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
compose;
composeEnhancers
只需在客户端和完全开发模式下使用__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
进行调整,否则代码仅使用compose
,这意味着它将被浏览器devtools隐藏。