在Elastic Beanstalk中构建React应用 [英] Build a React App in Elastic Beanstalk
问题描述
我遵循了这些说明,我用React制作了一个hello world应用程序.我将开发文件上传到我的EBS中,并且可以正常工作.
I followed these instructions and I made a hello world app with React. I uploaded the development files in my EBS and it worked.
在我使用命令 npm run build 之后,按照说明进行操作,安装了 push-state ,并使用localhost进行了测试.一切正常.
After that I used the command npm run build, I followed the instructions, I installed the push-state and I tested using localhost. Everything worked fine.
但是我将构建文件上传到我的EBS,它抱怨该应用程序没有 package.json 文件,并且该应用程序无法正常工作.
But I uploaded the build files to my EBS and it complains that the app does not have the package.json file and the app does not work.
我需要做什么来放入package.json才能使用Elastic Beanstalk部署我的react应用程序?如何在EBS中部署由 npm run build 生成的生成文件?
What do I have to do to put in package.json to deploy my react app using Elastic Beanstalk? How to deploy the build files generated by npm run build in EBS?
推荐答案
我最近使用EB CLI部署了基于react node的应用程序.我必须在项目目录中运行eb init
,它会引导您完成eb config的设置.步骤如下:
I recently deployed my react node based app using the EB CLI. I had to run eb init
in my project directory which walks you through setting up the eb config. Here's the steps:
-
npm init
设置package.json(已完成) -
git init
设置git存储库 -
eb init
通过其CLI设置弹性beantalk设置 - 提交代码
- 使用
eb deploy
部署到eb
npm init
to setup package.json (which you've done)git init
to setup a git repoeb init
to setup elastic beanstalk settings through its CLI- commit code
- deploy to eb with
eb deploy
AWS会指导您完成这些步骤,前提是您重新为您的应用程序提供节点服务(您没有说,但有可能).
AWS walks you through these steps assuming you're serving your app with node (which you didn't say, but it's likely).
作为奖励,您可能需要设置CI,以便在测试通过代码推送时AWS可以构建您的应用程序.请参阅我用来执行此操作的 travis yaml 文件.
As a bonus, you might want to setup CI so that AWS builds your app when your tests pass on code push. See the travis yaml file I use to do this.
这篇关于在Elastic Beanstalk中构建React应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!