Skip to content

Commit

Permalink
Changed variables naming to raw and stringified
Browse files Browse the repository at this point in the history
  • Loading branch information
Archie Lee committed Feb 10, 2017
1 parent 0e5fcdc commit 096f3c6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 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 vars = Object
var raw = Object
.keys(process.env)
.filter(key => REACT_APP.test(key))
.reduce((env, key) => {
Expand All @@ -32,18 +32,18 @@ function getClientEnvironment(publicUrl) {
'PUBLIC_URL': publicUrl
});
// Stringify all values so we can feed into Webpack DefinePlugin
var string = {
var stringified = {
'process.env': Object
.keys(vars)
.keys(raw)
.reduce((env, key) => {
env[key] = JSON.stringify(vars[key]);
env[key] = JSON.stringify(raw[key]);
return env;
}, {}),
};

return {
vars: vars,
string: string,
raw: raw,
stringified: stringified,
};
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-scripts/config/webpack.config.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@ module.exports = {
// 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.vars),
new InterpolateHtmlPlugin(env.raw),
// 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.string),
new webpack.DefinePlugin(env.stringified),
// 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
6 changes: 3 additions & 3 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ var env = getClientEnvironment(publicUrl);

// Assert this just to be safe.
// Development builds of React are slow and not intended for production.
if (env.string['process.env'].NODE_ENV !== '"production"') {
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
throw new Error('Production builds must have NODE_ENV=production.');
}

Expand Down Expand Up @@ -219,7 +219,7 @@ module.exports = {
// <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.vars),
new InterpolateHtmlPlugin(env.raw),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
inject: true,
Expand All @@ -241,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.string),
new webpack.DefinePlugin(env.stringified),
// 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 096f3c6

Please sign in to comment.