The meaning of life is to explore the world

PUBLIC_URL in React is not dynamic

Posted on By Jason Liu

Symptom
PUBLIC_URL is a system variable defined in file .env and used by Create React App.
Once we run npm run build, this is the base URL as a static string.
It cannot be dynamically set in a configuration file at run time.
As a result, if two builds are using different PUBLIC_URL then they have to be built separately, which is bad for containerization.

solution
So far I have found no solution