From e163df35674ad572224f541e79f8b2f61692285f Mon Sep 17 00:00:00 2001 From: Dave Sibiski Date: Mon, 10 Aug 2015 19:31:05 -0700 Subject: [PATCH] Adds `process.env.NODE_ENV` polyfill Summary: There are many libraries that use `NODE_ENV` to check whether the code is running in "production" mode or not. This allows those library authors to not have to add conditionals for React Native. One such library is Redux: https://github.com/gaearon/react-redux/pull/40 Thanks to @brentvatne for providing the solution via this tweet (via his phone in the airport :wink:): https://twitter.com/notbrent/status/630440250951749632 /cc @vjeux @gaearon @zpao @amasad Closes https://github.com/facebook/react-native/pull/2279 Github Author: Dave Sibiski --- .../Initialization/InitializeJavaScriptAppEngine.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js index 5f421f8190cde0..6a1dfa3cd7bee4 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js +++ b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js @@ -129,6 +129,10 @@ function setupProfile() { require('BridgeProfiling').swizzleReactPerf(); } +function setUpProcessEnv() { + GLOBAL.process = {env: {NODE_ENV: __DEV__ ? 'development' : 'production'}}; +} + setUpRedBoxErrorHandler(); setUpTimers(); setUpAlert(); @@ -138,3 +142,4 @@ setUpRedBoxConsoleErrorHandler(); setUpGeolocation(); setUpWebSockets(); setupProfile(); +setUpProcessEnv();