Skip to content

Commit 5763d44

Browse files
author
Archie Lee
committed
Separate results from getClientEnvironment
1 parent f87873e commit 5763d44

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

packages/react-scripts/config/env.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
var REACT_APP = /^REACT_APP_/i;
1616

1717
function getClientEnvironment(publicUrl) {
18-
var processEnv = Object
18+
var vars = Object
1919
.keys(process.env)
2020
.filter(key => REACT_APP.test(key))
2121
.reduce((env, key) => {
@@ -31,15 +31,18 @@ function getClientEnvironment(publicUrl) {
3131
// images into the `src` and `import` them in code to get their paths.
3232
'PUBLIC_URL': publicUrl
3333
});
34-
35-
processEnv['process.env'] = Object
36-
.keys(processEnv)
34+
// Stringify all values so we can feed into Webpack DefinePlugin
35+
var string = Object
36+
.keys(vars)
3737
.reduce((env, key) => {
38-
env[key] = JSON.stringify(processEnv[key]);
38+
env[key] = JSON.stringify(vars[key]);
3939
return env;
4040
}, {});
4141

42-
return processEnv;
42+
return {
43+
vars: vars,
44+
string: string,
45+
};
4346
}
4447

4548
module.exports = getClientEnvironment;

packages/react-scripts/config/webpack.config.dev.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,19 @@ module.exports = {
202202
];
203203
},
204204
plugins: [
205-
// Makes the public URL available as %PUBLIC_URL% in index.html, e.g.:
205+
// Makes some environment variables available in index.html.
206+
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
206207
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
207208
// In development, this will be an empty string.
208-
new InterpolateHtmlPlugin(env),
209+
new InterpolateHtmlPlugin(env.vars),
209210
// Generates an `index.html` file with the <script> injected.
210211
new HtmlWebpackPlugin({
211212
inject: true,
212213
template: paths.appHtml,
213214
}),
214215
// Makes some environment variables available to the JS code, for example:
215216
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
216-
new webpack.DefinePlugin(env),
217+
new webpack.DefinePlugin(env.string),
217218
// This is necessary to emit hot updates (currently CSS only):
218219
new webpack.HotModuleReplacementPlugin(),
219220
// Watcher doesn't work well if you mistype casing in a path so we use

packages/react-scripts/config/webpack.config.prod.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,12 @@ module.exports = {
214214
];
215215
},
216216
plugins: [
217-
// Makes the public URL available as %PUBLIC_URL% in index.html, e.g.:
217+
// Makes some environment variables available in index.html.
218+
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
218219
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
219220
// In production, it will be an empty string unless you specify "homepage"
220221
// in `package.json`, in which case it will be the pathname of that URL.
221-
new InterpolateHtmlPlugin(env),
222+
new InterpolateHtmlPlugin(env.vars),
222223
// Generates an `index.html` file with the <script> injected.
223224
new HtmlWebpackPlugin({
224225
inject: true,
@@ -240,7 +241,7 @@ module.exports = {
240241
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
241242
// It is absolutely essential that NODE_ENV was set to production here.
242243
// Otherwise React will be compiled in the very slow development mode.
243-
new webpack.DefinePlugin(env),
244+
new webpack.DefinePlugin(env.string),
244245
// This helps ensure the builds are consistent if source hasn't changed:
245246
new webpack.optimize.OccurrenceOrderPlugin(),
246247
// Try to dedupe duplicated modules, if any:

0 commit comments

Comments
 (0)