S3带有React的Amazon静态网站? [英] S3 Amazon Static Website with React?

查看:80
本文介绍了S3带有React的Amazon静态网站?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ReactJs建立了一个网站,要查看该网站,我通常执行npm start并通过浏览器转到localhost:3000.

I built a website using ReactJs, and to see the website, I generally do npm start and go to localhost:3000 via a browser.

我现在想在S3上托管此网站,但没有EC2实例.我的理解是npm是一个过程,因此它是服务器端的,因此,我需要购买计算才能实际部署我的网站.

I now want to host this website on S3, but without an EC2 instance. My understanding is that npm is a process, so it is server-side, and therefore, I would need to purchase compute to actually deploy my website.

我发现本教程没有提到为EC2实例计算时间付费: https://www.fullstackreact.com/articles/deploying-a-react-app-to-s3/

I found this tutorial that does not mention paying for EC2 instance compute time: https://www.fullstackreact.com/articles/deploying-a-react-app-to-s3/

但是,他们仍然使用NPM,这让我感到困惑.

However, they still use NPM which makes me confused.

我的问题是:如果我仅使用静态S3网站而不进行计算,是否可以使用React?

My question is: is it possible to use React if I were to only use Static S3 Website, without compute, and if so - how do I bypass NPM process?

反应-单独脚本中的组件不起作用

在上面的文章中,用户试图做出一个hello-world应用程序以响应,但是所有答案都将它们指向使服务器提供内容的方向.我认为react是前端的东西,可以在没有服务器端进程的情况下运行.这是真的?有人可以解释为什么需要node.js或与之配对的否,以及是否可以在没有ec2运算的情况下在s3上使用react?

In the above post, user tried to make a hello-world app in react, but all of the answers point them in the direction of making a server serve the content. I thought react is a front-end thing and can run without server-side processes. Is this true? Can someone explain why node.js is necessary or is paired with react, and whether is is possible to use react on s3 without ec2 compute?

推荐答案

有可能完全在s3上托管静态反应站点.在这种情况下,您只能将 node / npm 用作构建工具并运行开发服务器( localhost:3000 ).

It's possible to host a static react site entirely on s3. In this case, you would use node/npm only as build tools and to run your development server (localhost:3000).

npm 将下载您的依赖项,并且您将使用node或gulp或webpack将资产构建为静态文件.

npm would download your dependencies and you'd use node or gulp or webpack to build the assets into static files.

然后,您将文件上传到s3,在该处将为静态文件提供服务.

Then you would upload the files to s3 where it would serve the static files.

如果您有一些后端节点代码,则需要使用ec2或其他类型的主机.但是,如果它是完全静态的javascript,则无需节点服务器.

If you have some backend node code, then you would need to use ec2 or some other type of host. But if it's entirely static javascript, then there's no need for a node server.

以下一些链接可能有助于详细说明:

Here are some links that might help explain in more detail:

这篇关于S3带有React的Amazon静态网站?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆