在Elastic Beanstalk中构建React应用 [英] Build a React App in Elastic Beanstalk

查看:89
本文介绍了在Elastic Beanstalk中构建React应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了这些说明,我用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:

  1. npm init设置package.json(已完成)
  2. git init设置git存储库
  3. eb init通过其CLI设置弹性beantalk设置
  4. 提交代码
  5. 使用eb deploy
  6. 部署到eb
  1. npm init to setup package.json (which you've done)
  2. git init to setup a git repo
  3. eb init to setup elastic beanstalk settings through its CLI
  4. commit code
  5. 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屋!

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