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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Saved me huge effort and time, almost ejected from cra, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.