3

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?

Toby
  • 12,743
  • 8
  • 43
  • 75

1 Answers1

6

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.

Toby
  • 12,743
  • 8
  • 43
  • 75