From 6e378d4813fd88ccafed2057e1327098f9c190d2 Mon Sep 17 00:00:00 2001 From: Archie Lee Date: Tue, 24 Jan 2017 23:19:23 +0800 Subject: [PATCH 1/7] Make all vars accessiable in index.html --- packages/react-scripts/config/env.js | 18 ++++++++++++------ .../react-scripts/config/webpack.config.dev.js | 6 ++---- .../config/webpack.config.prod.js | 6 ++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index 66ba341b358..3f417304833 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -19,21 +19,27 @@ function getClientEnvironment(publicUrl) { .keys(process.env) .filter(key => REACT_APP.test(key)) .reduce((env, key) => { - env[key] = JSON.stringify(process.env[key]); + env[key] = process.env[key]; return env; }, { // Useful for determining whether we’re running in production mode. // Most importantly, it switches React into the correct mode. - 'NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), + 'NODE_ENV': process.env.NODE_ENV || 'development', // Useful for resolving the correct path to static assets in `public`. // For example, . // This should only be used as an escape hatch. Normally you would put // images into the `src` and `import` them in code to get their paths. - 'PUBLIC_URL': JSON.stringify(publicUrl) + 'PUBLIC_URL': publicUrl }); - return {'process.env': processEnv}; + + processEnv['process.env'] = Object + .keys(processEnv) + .reduce((env, key) => { + env[key] = JSON.stringify(processEnv[key]); + return env; + }, {}); + + return processEnv; } module.exports = getClientEnvironment; diff --git a/packages/react-scripts/config/webpack.config.dev.js b/packages/react-scripts/config/webpack.config.dev.js index 96fd632b795..b890677cdc7 100644 --- a/packages/react-scripts/config/webpack.config.dev.js +++ b/packages/react-scripts/config/webpack.config.dev.js @@ -205,9 +205,7 @@ module.exports = { // Makes the public URL available as %PUBLIC_URL% in index.html, e.g.: // // In development, this will be an empty string. - new InterpolateHtmlPlugin({ - PUBLIC_URL: publicUrl - }), + new InterpolateHtmlPlugin(env), // Generates an `index.html` file with the