Skip to content

Commit

Permalink
Separate results from getClientEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
Archie Lee committed Feb 9, 2017
1 parent f87873e commit 5763d44
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
15 changes: 9 additions & 6 deletions packages/react-scripts/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
var REACT_APP = /^REACT_APP_/i;

function getClientEnvironment(publicUrl) {
var processEnv = Object
var vars = Object
.keys(process.env)
.filter(key => REACT_APP.test(key))
.reduce((env, key) => {
Expand All @@ -31,15 +31,18 @@ function getClientEnvironment(publicUrl) {
// images into the `src` and `import` them in code to get their paths.
'PUBLIC_URL': publicUrl
});

processEnv['process.env'] = Object
.keys(processEnv)
// Stringify all values so we can feed into Webpack DefinePlugin
var string = Object
.keys(vars)
.reduce((env, key) => {
env[key] = JSON.stringify(processEnv[key]);
env[key] = JSON.stringify(vars[key]);
return env;
}, {});

return processEnv;
return {
vars: vars,
string: string,
};
}

module.exports = getClientEnvironment;
7 changes: 4 additions & 3 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,18 +202,19 @@ module.exports = {
];
},
plugins: [
// Makes the public URL available as %PUBLIC_URL% in index.html, e.g.:
// Makes some environment variables available in index.html.
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
// In development, this will be an empty string.
new InterpolateHtmlPlugin(env),
new InterpolateHtmlPlugin(env.vars),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
template: paths.appHtml,
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env),
new webpack.DefinePlugin(env.string),
// This is necessary to emit hot updates (currently CSS only):
new webpack.HotModuleReplacementPlugin(),
// Watcher doesn't work well if you mistype casing in a path so we use
Expand Down
7 changes: 4 additions & 3 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ module.exports = {
];
},
plugins: [
// Makes the public URL available as %PUBLIC_URL% in index.html, e.g.:
// Makes some environment variables available in index.html.
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
// In production, it will be an empty string unless you specify "homepage"
// in `package.json`, in which case it will be the pathname of that URL.
new InterpolateHtmlPlugin(env),
new InterpolateHtmlPlugin(env.vars),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
Expand All @@ -240,7 +241,7 @@ module.exports = {
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
// It is absolutely essential that NODE_ENV was set to production here.
// Otherwise React will be compiled in the very slow development mode.
new webpack.DefinePlugin(env),
new webpack.DefinePlugin(env.string),
// This helps ensure the builds are consistent if source hasn't changed:
new webpack.optimize.OccurrenceOrderPlugin(),
// Try to dedupe duplicated modules, if any:
Expand Down

0 comments on commit 5763d44

Please sign in to comment.