Disable chrome react DevTools for production

前端 未结 5 661
[愿得一人]
[愿得一人] 2020-12-09 10:06

I\'m trying to browserify my react app for production using gulp and envify to setup NODE_ENV. So I can remove react warning, error reporting in the console, and even my cod

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 10:55

    According to an issue on Github, you can add run a single javascript line before react is loaded to prevent it.

    From #191 of react-devtools

    
    

    Then, you may consider wrapping this with your environment condition, like that you could do sth like below in your server side rendering. Let's say Pug (formerly known as Jade):

    #{process.env.NODE_ENV == 'production' ? "window.__REACT_DEVTOOLS_GLOBAL_HOOK__.inject = function(){}" : ""}
    

    However, it would be still a good practice to put the business logic and the sensitive data back to your server.

提交回复
热议问题