4 ms·
What is the best way to deploy react app on production?
As a newbie, hereby wanted to learn from best people out there... how to publish my react app in production.
Right now what I am doing is:
1. build => yarn build
2. copy => yarn deploy (actually rsync fresh stuffs to a ec2 slice)
3. serve => serve using nginx (as static web contents)
Also tried with s3{no SSL :( endpoint} and cloudfront{ doesn't work with index.html and also couldn't make its weird lamdaEdge work }
Problems I am having are:
After each yarn builds, as new assets are generated and copied with rsync; I am deleting other old builds with --delete option.
The result of which, the clients{browsers} are getting 404 for old assets and they see this weird msg "Unexpected Error Occurred" as they need to refresh to get the latest assets.
What is the best practice to make it continuous and avoid such 404 weirdness? I am thinking of writing nginx redirects for such old assets request.
But I think there is a much better way of doing things in react and js world :)
staying positive :D
Thanks
- zachguo 9y agoIt's pretty easy to deploy to S3, host your build as a static website and point both your index and 404 pages to your index.html. SSL can be configured in CloudFront.
- thapakazi 9y agoThanks, that was quick. Can you elaborate more on that "both your index and 404 pages to your index.html". Where do I do that on s3 ? cloudfront ? I had one on cloudfront to redirect 404 to index.html but that redirected all my sign_up/index.html to login/index.html page too :( But is it the best way of doing it? And about s3 and CloudFront with ssl, I was weaving via this guide, and couldn't make lamda work with CloudFront. I was stucked with lamda IAM permission weirdness, and couldnot make it work: https://aws.amazon.com/blogs/compute/implementing-default-directory-indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/ https://aws.amazon.com/blogs/compute/implementing-default-di...