title: Pass environment variable from package.json to React app
body: <p>I'm building a React / Node / Express / Webpack (2.2.1) application and would like to know how to approach the following:</p>
  
  <p>I would like an environment variable to be visible in the React client - the purpose being for certain api requests to use either the localhost or otherwise the IP address of the production server.</p>
  
  <p>Is it possible to get an environment variable from running a script in package.json, to the webpack build, and then compiled and visible in the bundled javascript.</p>
  
  <p>So in terminal run:</p>
  
  <pre><code>npm run build-dev // pass to Webpack something like APP_ENV="development"
  </code></pre>
  
  <p>or</p>
  
  <pre><code>npm run build-prod // pass to Webpack something like APP_ENV="production"
  </code></pre>
  
  <p>and the script definition being something like:</p>
  
  <pre><code>"scripts": {
      "build-dev": "webpack --define APP_ENV='development'"
  }
  </code></pre>
  
  <p>...help greatly appreciated</p>