There is a problem in the react source code that is not a problem, but it is very confusing

Why is there a judgment statement like the following in the react source code? (if ("development"! = "production") {.}

clipboard.png

I can"t figure it out even though I"ve been going through it for most of the day. Is there any point in this? And the source code is full of this judgment.
react version 15.6

Jan.16,2022

these are compiled and generated, and only code that has not been confused is like this, and the code after UglifyJS processing will remove these. The real source code should be something like this:

if (process.env.NODE_ENV !== 'production'){}

this version of React defaults to development mode, and you need to specify NODE_ENV if you publish. In addition, you can dispose of the code through UglifyJS. Or you can directly refer to the confused code:

const React = require('react/dist/react.min.js');
For more information, please see https://github.com/facebook/r.

.

has two uses

  1. during official development, more debugging information is available for debugging. In production environment, it has generally been deleted
  2. .
  3. when we develop it, it is used as debugging and has more debugging information, but it is not recommended in production environment and has more consumption

We can also use this when we do our own development, output debugging information in the development environment, but no longer output some information in the production environment.

Menu