Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create-React-App absolute paths to JS and CSS in prod build

I'm using create-react-app and in prod I'd like to serve the JS and CSS and other static assets on s3, but serve the index.html file from another location. However, the URLs in the built files are all relative paths.

Is there a way (without ejecting) to use absolute URLs in the production build?

like image 299
Toby Avatar asked Nov 18 '25 04:11

Toby


1 Answers

Apparently this is achievable with the PUBLIC_URL environment variable. I was under the impression this variable was intended to be used if the React app would be living in a sub-directory, in order to fix client side routing. However, by adding:

PUBLIC_URL=https://<my-s3-bucket_url>

The URLs in all files become absolute URLs instead of relative URLs.

like image 155
Toby Avatar answered Nov 19 '25 19:11

Toby