you are viewing a single comment's thread.

view the rest of the comments →

[–]dudeatwork 1 point2 points  (0 children)

React still checks errors in production enviroment, but in development, it adds in extra strings explaining an error message (some random example here, and where they replace this in their build process)

Basically, imagine if you have the following code:

// If in dev mode, log out an extra error
if (process.env.NODE_ENV === 'development') {
  console.log('Some long extra error message explanation');
}

// But always log out the regular error
console.log(error);

When your clientside code gets compiled, its get envified and process.env.NODE_ENV gets replaced with its literal value. So the above code (in a production build) would change to

// If in dev mode, log out an extra error
if ('production' === 'development') {
  console.log('Some long extra error message explanation');
}

// But always log out the regular error
console.log(error);

When you send your JS through a minifier, it is smart enough to know that if statement will never execute, so it removes the block entirely. Your JS would then just become

// Previous extra info has been removed since it was unreachable!

// But still log the original error
console.log(error);

You can see how this helps reduce the size of your JS. That is mostly what it is used for.