How to change PublicPath for Create React App in Dev Environment

Simranjit Singh picture Simranjit Singh · Feb 8, 2018 · Viewed 11.8k times · Source

I am using Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-rc1-final which internally uses Create-react-app and AspnetCore.ReactDevelopmentServer

My Dev. Environment is using IIS for hosting multiple api's say api1 as http://localhost/api1 and api2 as http://localhost/api2

Problem is if I host my React app from Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-rc1-final template to http://localhost/myApp - it expects the files are always served with PublicPath "/" and hence does not work.

I know Create-react-app's Prod setup uses PublicPath from PUBLIC_URL or Homepage from package.json.

Is it possible to modify create-react-app setup to use a custom publicpath in Dev. environment?

Answer

Simranjit Singh picture Simranjit Singh · Feb 8, 2018

After doing some more googling and searching old issues on github, I have realized that this feature is due for release in react-scripts 2.0 which should include https://github.com/facebook/create-react-app/pull/1887. This will allow subpaths to be included in url from where the files are being served in create-react-app