Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  80] [ 7]  / answers: 1 / hits: 115434  / 8 Years ago, wed, february 17, 2016, 12:00:00

Is it possible to detect whether the current version of React is development or production at runtime? I'd like to do something like this:



if (React.isDevelopment) {
// Development thing
} else {
// Real thing
}

More From » reactjs

 Answers
44

This is best done emulating the Node way of doing things with your build tool - webpack, browserify - by exposing process.env.NODE_ENV. Typically, you'll have it set to production in prod and development (or undefined) in dev.



So your code becomes:



if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
// dev code
} else {
// production code
}


For how to set it up, see envify or Passing environment-dependent variables in webpack


[#63276] Tuesday, February 16, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dayana

Total Points: 302
Total Questions: 102
Total Answers: 100

Location: Cayman Islands
Member since Fri, Mar 4, 2022
2 Years ago
;