Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude / disable Redux devtools in production build or disconnect?

As its name suggests devtools should be visible or accessible only during development and not in production. I don't want my end users playing with the state and dispatcher or seeing what's going on under the hood.

Is there a way to hide Redux Devtools or disconnect it in the production build?

I'm looking answers for Vanilla Redux. Not Redux Saga, Redux Thunk or Rematch.

like image 624
Pushkin Avatar asked Mar 29 '20 02:03

Pushkin


People also ask

How do I disable Redux dev tools in production?

If you don't want to allow the extension in production, just use 'redux-devtools-extension/developmentOnly' instead of 'redux-devtools-extension'.

How do I keep Redux DevTools open?

Hit Ctrl+Shift+I, or F12. You will then open up the Developer Tools.

What is diff in Redux DevTools?

Diff. The right side of the console has multiple options to see the state of the application and the relation of each action to the state. When an action is selected in the left hand side of the console, the Diff option will show only what that individual action changed in the state tree.


1 Answers

For hiding the Redux from devtools pay attention to the following code:

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);

It is an integration between Redux and Redux-Saga that is not important the point is the:

const composeEnhancers =
  (nodeEnv !== 'production' &&
    typeof window !== 'undefined' &&
    window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__) ||
  compose;

The composeEnhancers is tuned just use __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ in the client and exactly development mode, otherwise the code just use compose and it means it will be hidden from browsers devtools.

like image 130
AmerllicA Avatar answered Sep 20 '22 12:09

AmerllicA