principlejavascriptreactCritical
Detecting production vs. development React at runtime
Viewed 0 times
productiondevelopmentreactdetectingruntime
Problem
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
}Solution
This is best done emulating the Node way of doing things with your build tool - webpack, browserify - by exposing
So your code becomes:
For how to set it up, see envify or Passing environment-dependent variables in webpack
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
Code Snippets
if (!process.env.NODE_ENV || process.env.NODE_ENV === 'development') {
// dev code
} else {
// production code
}Context
Stack Overflow Q#35469836, score: 339
Revisions (0)
No revisions yet.