
What is the best way to deploy react app on production? - thapakazi
As a newbie, hereby wanted to learn from best people out there... how to publish my react app in production.<p>Right now what I am doing is:<p>1. build  =&gt; yarn build<p>2. copy   =&gt; yarn deploy (actually rsync fresh stuffs to a ec2 slice)<p>3. serve  =&gt; serve using nginx (as static web contents)<p>Also tried with s3{no SSL :( endpoint} and cloudfront{ doesn&#x27;t work with index.html and also couldn&#x27;t make its weird lamdaEdge work }<p>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 &quot;Unexpected Error Occurred&quot; as they need to refresh to get the latest assets.<p>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.<p>But I think there is a much better way of doing things in react and js world :)<p>staying positive :D
Thanks
======
zachguo
It'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
Thanks, 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-
di...](https://aws.amazon.com/blogs/compute/implementing-default-directory-
indexes-in-amazon-s3-backed-amazon-cloudfront-origins-using-lambdaedge/)

