From 5372ebabde92b080dd8399431489bb350817eaa3 Mon Sep 17 00:00:00 2001 From: Tuomas-Matti Soikkeli Date: Thu, 1 Dec 2016 19:28:25 +0200 Subject: [PATCH] Make PUBLIC_URL environment variable available at build time. Previously PUBLIC_URL was read from package.json homapage entry. Webpack DefinePlugin then processed the PUBLIC_URL to be available at run time. However setting environment variable should have precedence over configuration. Fixed by looking into process.env.PUBLIC_URL before assiging value from package.json. --- packages/react-scripts/config/webpack.config.prod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 60016896892..4a6af67e6ac 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -36,7 +36,7 @@ function ensureSlash(path, needsSlash) { // single-page apps that may serve index.html for nested URLs like /todos/42. // We can't use a relative path in HTML because we don't want to load something // like /todos/42/static/js/bundle.7289d.js. We have to know the root. -var homepagePath = require(paths.appPackageJson).homepage; +var homepagePath = process.env.PUBLIC_URL || require(paths.appPackageJson).homepage; var homepagePathname = homepagePath ? url.parse(homepagePath).pathname : '/'; // Webpack uses `publicPath` to determine where the app is being served from. // It requires a trailing slash, or the file assets will get an incorrect path.