1 | // @remove-on-eject-begin
|
2 | /**
|
3 | * Copyright (c) 2015-present, Facebook, Inc.
|
4 | * All rights reserved.
|
5 | *
|
6 | * This source code is licensed under the BSD-style license found in the
|
7 | * LICENSE file in the root directory of this source tree. An additional grant
|
8 | * of patent rights can be found in the PATENTS file in the same directory.
|
9 | */
|
10 | // @remove-on-eject-end
|
11 |
|
12 | // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
13 | // injected into the application via DefinePlugin in Webpack configuration.
|
14 |
|
15 | var REACT_APP = /^REACT_APP_/i;
|
16 |
|
17 | function getClientEnvironment(publicUrl) {
|
18 | var raw = Object
|
19 | .keys(process.env)
|
20 | .filter(key => REACT_APP.test(key))
|
21 | .reduce((env, key) => {
|
22 | env[key] = process.env[key];
|
23 | return env;
|
24 | }, {
|
25 | // Useful for determining whether we’re running in production mode.
|
26 | // Most importantly, it switches React into the correct mode.
|
27 | 'NODE_ENV': process.env.NODE_ENV || 'development',
|
28 | // Useful for resolving the correct path to static assets in `public`.
|
29 | // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
30 | // This should only be used as an escape hatch. Normally you would put
|
31 | // images into the `src` and `import` them in code to get their paths.
|
32 | 'PUBLIC_URL': publicUrl
|
33 | });
|
34 | // Stringify all values so we can feed into Webpack DefinePlugin
|
35 | var stringified = {
|
36 | 'process.env': Object
|
37 | .keys(raw)
|
38 | .reduce((env, key) => {
|
39 | env[key] = JSON.stringify(raw[key]);
|
40 | return env;
|
41 | }, {})
|
42 | };
|
43 |
|
44 | return { raw, stringified };
|
45 | }
|
46 |
|
47 | module.exports = getClientEnvironment;
|