MCPcopy
hub / github.com/react/create-react-app / getClientEnvironment

Function getClientEnvironment

packages/react-scripts/config/env.js:71–110  ·  view source on GitHub ↗
(publicUrl)

Source from the content-addressed store, hash-verified

69const REACT_APP = /^REACT_APP_/i;
70
71function getClientEnvironment(publicUrl) {
72 const raw = Object.keys(process.env)
73 .filter(key => REACT_APP.test(key))
74 .reduce(
75 (env, key) => {
76 env[key] = process.env[key];
77 return env;
78 },
79 {
80 // Useful for determining whether we’re running in production mode.
81 // Most importantly, it switches React into the correct mode.
82 NODE_ENV: process.env.NODE_ENV || 'development',
83 // Useful for resolving the correct path to static assets in `public`.
84 // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
85 // This should only be used as an escape hatch. Normally you would put
86 // images into the `src` and `import` them in code to get their paths.
87 PUBLIC_URL: publicUrl,
88 // We support configuring the sockjs pathname during development.
89 // These settings let a developer run multiple simultaneous projects.
90 // They are used as the connection `hostname`, `pathname` and `port`
91 // in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
92 // and `sockPort` options in webpack-dev-server.
93 WDS_SOCKET_HOST: process.env.WDS_SOCKET_HOST,
94 WDS_SOCKET_PATH: process.env.WDS_SOCKET_PATH,
95 WDS_SOCKET_PORT: process.env.WDS_SOCKET_PORT,
96 // Whether or not react-refresh is enabled.
97 // It is defined here so it is available in the webpackHotDevClient.
98 FAST_REFRESH: process.env.FAST_REFRESH !== 'false',
99 }
100 );
101 // Stringify all values so we can feed into webpack DefinePlugin
102 const stringified = {
103 'process.env': Object.keys(raw).reduce((env, key) => {
104 env[key] = JSON.stringify(raw[key]);
105 return env;
106 }, {}),
107 };
108
109 return { raw, stringified };
110}
111
112module.exports = getClientEnvironment;

Callers 2

start.jsFile · 0.85
webpack.config.jsFile · 0.85

Calls 1

testMethod · 0.80

Tested by

no test coverage detected