From 7add7aef3b9ab106e20c4bf088a91fc3e4131db5 Mon Sep 17 00:00:00 2001 From: Enoah Netzach Date: Thu, 20 Oct 2016 17:28:14 +0200 Subject: [PATCH 1/5] Add support for `PUBLIC_URL` env variable --- packages/react-scripts/config/paths.js | 10 +++++--- .../config/webpack.config.prod.js | 12 ++++++---- packages/react-scripts/scripts/build.js | 24 ++++++++++--------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index 2f10ea2fb8a..f32bd1cba50 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -41,7 +41,7 @@ var nodePaths = (process.env.NODE_PATH || '') .map(resolveApp); // config after eject: we're in ./config/ -module.exports = { +var configs = { appBuild: resolveApp('build'), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), @@ -61,7 +61,7 @@ function resolveOwn(relativePath) { } // config before eject: we're in ./node_modules/react-scripts/config/ -module.exports = { +configs = { appBuild: resolveApp('build'), appPublic: resolveApp('public'), appHtml: resolveApp('public/index.html'), @@ -78,7 +78,7 @@ module.exports = { // config before publish: we're in ./packages/react-scripts/config/ if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) { - module.exports = { + configs = { appBuild: resolveOwn('../../../build'), appPublic: resolveOwn('../template/public'), appHtml: resolveOwn('../template/public/index.html'), @@ -93,3 +93,7 @@ if (__dirname.indexOf(path.join('packages', 'react-scripts', 'config')) !== -1) }; } // @remove-on-eject-end + +configs.publicUrl = process.env.PUBLIC_URL ? process.env.PUBLIC_URL : require(configs.appPackageJson).homepage; + +module.exports = configs; diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 058db0d7921..a6154c8decc 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -35,20 +35,22 @@ function ensureSlash(path, needsSlash) { } } -// We use "homepage" field to infer "public path" at which the app is served. +// We use `PUBLIC_URL` environment variable or "homepage" field to infer +// "public path" at which the app is served. // Webpack needs to know it to put the right